| 1 | /* This file is part of the FaCT++ DL reasoner |
| 2 | Copyright (C) 2003-2015 Dmitry Tsarkov and The University of Manchester |
| 3 | Copyright (C) 2015-2017 Dmitry Tsarkov |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | This library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with this library; if not, write to the Free Software |
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #ifndef DUMPLISP_H |
| 21 | #define DUMPLISP_H |
| 22 | |
| 23 | #include "dumpInterface.h" |
| 24 | #include "dlTBox.h" //TConcept/TRole |
| 25 | |
| 26 | /// class for dumping ontology to a lisp format |
| 27 | class dumpLisp : public dumpInterface |
| 28 | { |
| 29 | public: // interface |
| 30 | /// the only c'tor -- empty |
| 31 | explicit dumpLisp ( std::ostream& oo ) : dumpInterface(oo) {} |
| 32 | |
| 33 | // global prologue/epilogue |
| 34 | void prologue ( void ) override {} |
| 35 | void epilogue ( void ) override {} |
| 36 | |
| 37 | // general concept expression |
| 38 | void dumpTop ( void ) override { o << "*TOP*"; } |
| 39 | void dumpBottom ( void ) override { o << "*BOTTOM*"; } |
| 40 | void dumpNumber ( unsigned int n ) override { o << n << " "; } |
| 41 | |
| 42 | void startOp ( diOp Op ) override; |
| 43 | /// start operation >=/<= with number |
| 44 | void startOp ( diOp Op, unsigned int n ) override { startOp(Op); dumpNumber(n); } |
| 45 | void contOp ( diOp Op ) override |
| 46 | { |
| 47 | if ( Op == diAnd || Op == diOr ) |
| 48 | skipIndent(); |
| 49 | else |
| 50 | o << " "; |
| 51 | } |
| 52 | void finishOp ( diOp Op ) override |
| 53 | { |
| 54 | if ( Op == diAnd || Op == diOr ) |
| 55 | decIndent(); |
| 56 | o << ")"; |
| 57 | } |
| 58 | |
| 59 | void startAx ( diAx Ax ) override; |
| 60 | void contAx ( diAx ) override { o << " "; } |
| 61 | void finishAx ( diAx ) override { o << ")\n"; } |
| 62 | |
| 63 | /// obtain name by the named entry |
| 64 | void dumpName ( const TNamedEntry* p ) override { o << "|" << p->getName() << "|"; } |
| 65 | /// dump concept atom (as used in expression) |
| 66 | void dumpConcept ( const TConcept* p ) override { dumpName(p); } |
| 67 | /// dump role atom (as used in expression) |
| 68 | void dumpRole ( const TRole* p ) override |
| 69 | { |
| 70 | if ( p->getId() < 0 ) // inverse |
| 71 | { |
| 72 | o << "(inv "; |
| 73 | dumpName(p->inverse()); |
| 74 | o << ")"; |
| 75 | } |
| 76 | else |
| 77 | dumpName(p); |
| 78 | } |
| 79 | }; // dumpLisp |
| 80 | |
| 81 | #endif |