Debian Codegraph @

FaCT++.Python/lib/Kernel/dumpInterface.h

raw symbols SCIP
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 DUMPINTERFACE_H
21 #define DUMPINTERFACE_H
22
23 #include <ostream>
24
25 #include "tNamedEntry.h"
26 #include "dltree.h"
27
28 class TConcept;
29 class TRole;
30
31 /// enumeration of dump interface concept operations
32 enum diOp
33 { // concept expressions
34 diNot,
35 diAnd,
36 diOr,
37 diExists,
38 diForall,
39 diGE,
40 diLE,
41 // role expressions
42 diInv,
43 // individual expressions
44 diOneOf,
45 // wrong operation
46 diErrorOp,
47 // end of the enum
48 diLastOp = diErrorOp
49 }; // diOp
50
51 /// enumeration of dump interface axioms
52 enum diAx
53 { // wrong axiom
54 diErrorAx = diLastOp,
55 // concept axioms
56 diDefineC,
57 diImpliesC,
58 diEqualsC,
59 diDisjointC,
60 // role axioms
61 diDefineR,
62 diTransitiveR,
63 diFunctionalR,
64 diImpliesR,
65 diEqualsR,
66 diDomainR,
67 diRangeR,
68 // individual axioms
69 diInstanceOf,
70 }; // diAx
71
72 /// general interface for dumping ontology to a proper format
73 class dumpInterface
74 {
75 protected: // members
76 /// output stream
77 std::ostream& o;
78 /// indentation level
79 unsigned int indent = 0;
80 /// print every axiom on a single line (need for sorting, for example)
81 bool oneliner = false;
82
83 protected: // methods
84 /// write necessary amount of TABs
85 void skipIndent ( void );
86 /// increase indentation level
87 void incIndent ( void );
88 /// decrease indentation level
89 void decIndent ( void );
90
91 public: // interface
92 /// the only c'tor -- empty
93 explicit dumpInterface ( std::ostream& oo ) : o(oo) {}
94 /// empty d'tor
95 virtual ~dumpInterface() = default;
96
97 /// set ONELINER flag; @return previous value
98 bool useIndentation ( bool val )
99 {
100 bool ret = oneliner;
101 oneliner = val;
102 return ret;
103 }
104
105 // global prologue/epilogue
106 virtual void prologue ( void ) {}
107 virtual void epilogue ( void ) {}
108
109 // general concept expression
110 virtual void dumpTop ( void ) {}
111 virtual void dumpBottom ( void ) {}
112 virtual void dumpNumber ( unsigned int ) {}
113
114 virtual void startOp ( diOp ) {}
115 /// start operation >=/<= with number
116 virtual void startOp ( diOp, unsigned int ) {}
117 virtual void contOp ( diOp ) {}
118 virtual void finishOp ( diOp ) {}
119
120 virtual void startAx ( diAx ) {}
121 virtual void contAx ( diAx ) {}
122 virtual void finishAx ( diAx ) {}
123
124 /// obtain name by the named entry
125 virtual void dumpName ( const TNamedEntry* p ) { o << p->getName(); }
126 /// dump concept atom (as used in expression)
127 virtual void dumpConcept ( const TConcept* ) {}
128 /// dump role atom (as used in expression)
129 virtual void dumpRole ( const TRole* ) {}
130 }; // dumpInterface
131
132 inline void dumpInterface :: skipIndent ( void )
133 {
134 if ( oneliner )
135 return;
136 o << "\n";
137 for ( unsigned int i = indent; i > 0; --i )
138 o << " ";
139 }
140
141 inline void dumpInterface :: incIndent ( void )
142 {
143 skipIndent();
144 ++indent; // operands of AND-like
145 }
146
147 inline void dumpInterface :: decIndent ( void )
148 {
149 --indent;
150 skipIndent();
151 }
152
153 // dump given concept expression
154 void dumpCExpression ( dumpInterface* dump, const DLTree* C );
155 // dump given role expression
156 void dumpRExpression ( dumpInterface* dump, const DLTree* R );
157
158 #endif