Debian Codegraph @

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

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 #include <iostream>
21
22 #include "dumpInterface.h"
23 #include "dlTBox.h"
24
25 //-------------------------------------------------------------------------------
26 // General dumping methods -- dumping relevant parts of ontology
27 //-------------------------------------------------------------------------------
28 void TBox :: dump ( dumpInterface* dump ) const
29 {
30 dump->prologue();
31
32 // dump all (relevant) roles
33 dumpAllRoles(dump);
34
35 // dump all (relevant) concepts
36 for ( c_const_iterator pc = c_begin(); pc != c_end(); ++pc )
37 if ( isRelevant(*pc) )
38 dumpConcept( dump, *pc );
39
40 for ( i_const_iterator pi = i_begin(); pi != i_end(); ++pi )
41 if ( isRelevant(*pi) )
42 dumpConcept( dump, *pi );
43
44 // dump GCIs
45 if ( getTG() != bpTOP )
46 {
47 dump->startAx (diImpliesC);
48 dump->dumpTop();
49 dump->contAx (diImpliesC);
50 dumpExpression ( dump, getTG() );
51 dump->finishAx (diImpliesC);
52 }
53
54 dump->epilogue();
55 }
56
57 void TBox :: dumpConcept ( dumpInterface* dump, const TConcept* p ) const
58 {
59 // dump defConcept
60 dump->startAx (diDefineC);
61 dump->dumpConcept(p);
62 dump->finishAx (diDefineC);
63
64 // dump "p [= def"
65 if ( p->pBody != bpTOP )
66 {
67 diAx Ax = p->isNonPrimitive() ? diEqualsC : diImpliesC;
68 dump->startAx (Ax);
69 dump->dumpConcept(p);
70 dump->contAx (Ax);
71 dumpExpression ( dump, p->pBody );
72 dump->finishAx (Ax);
73 }
74 }
75
76 void TBox :: dumpRole ( dumpInterface* dump, const TRole* p ) const
77 {
78 // dump defRole and parents
79 if ( p->getId() > 0 || !isRelevant(p->inverse()) )
80 {
81 const TRole* q = ( p->getId()>0 ? p : p->inverse() );
82
83 dump->startAx (diDefineR);
84 dump->dumpRole(q);
85 dump->finishAx (diDefineR);
86
87 // dump parents
88 for ( const auto& parent: q->told() )
89 {
90 dump->startAx (diImpliesR);
91 dump->dumpRole(q);
92 dump->contAx (diImpliesR);
93 dump->dumpRole(static_cast<const TRole*>(parent));
94 dump->finishAx (diImpliesR);
95 }
96 }
97
98 // dump transitivity
99 if ( p->isTransitive() )
100 {
101 dump->startAx (diTransitiveR);
102 dump->dumpRole(p);
103 dump->finishAx (diTransitiveR);
104 }
105
106 // dump functionality (for topmost-functional roles only)
107 if ( p->isTopFunc() )
108 {
109 dump->startAx (diFunctionalR);
110 dump->dumpRole(p);
111 dump->finishAx (diFunctionalR);
112 }
113
114 // dump "domain"
115 if ( p->getBPDomain() != bpTOP )
116 {
117 dump->startAx (diDomainR);
118 dump->dumpRole(p);
119 dump->contAx (diDomainR);
120 dumpExpression ( dump, p->getBPDomain() );
121 dump->finishAx (diDomainR);
122 }
123
124 // dump "range"
125 if ( p->getBPRange() != bpTOP )
126 {
127 dump->startAx (diRangeR);
128 dump->dumpRole(p);
129 dump->contAx (diRangeR);
130 dumpExpression ( dump, p->getBPRange() );
131 dump->finishAx (diRangeR);
132 }
133 }
134
135 void TBox :: dumpExpression ( dumpInterface* dump, BipolarPointer p ) const
136 {
137 fpp_assert ( isValid(p) );
138
139 if ( p == bpTOP )
140 return dump->dumpTop();
141 if ( p == bpBOTTOM )
142 return dump->dumpBottom();
143
144 // checks inversion
145 if ( isNegative(p) )
146 {
147 dump->startOp (diNot);
148 dumpExpression ( dump, inverse(p) );
149 return dump->finishOp (diNot);
150 }
151
152 const DLVertex& v = DLHeap[p];
153
154 switch ( v.Type() )
155 {
156 case dtTop:
157 return dump->dumpTop();
158
159 case dtName:
160 return dump->dumpConcept(static_cast<const TConcept*>(v.getConcept()));
161
162 case dtAnd:
163 dump->startOp (diAnd);
164 for ( DLVertex::const_iterator q = v.begin(); q != v.end(); ++q )
165 {
166 if ( q != v.begin() )
167 dump->contOp (diAnd);
168 dumpExpression ( dump, *q );
169 }
170 dump->finishOp (diAnd);
171 return;
172
173 case dtForall:
174 dump->startOp (diForall);
175 dump->dumpRole (v.getRole());
176 dump->contOp(diForall);
177 dumpExpression ( dump, v.getC() );
178 dump->finishOp (diForall);
179 return;
180
181 case dtLE:
182 dump->startOp ( diLE, v.getNumberLE() );
183 dump->dumpRole (v.getRole());
184 dump->contOp(diLE);
185 dumpExpression ( dump, v.getC() );
186 dump->finishOp (diLE);
187 return;
188
189 default:
190 std::cerr << "Error dumping vertex of type " << v.getTagName() << "(" << v.Type () << ")";
191 fpp_unreachable();
192 }
193 }
194
195 void TBox :: dumpAllRoles ( dumpInterface* dump ) const
196 {
197 RoleMaster::const_iterator p;
198 for ( p = ORM.begin(); p != ORM.end(); ++p )
199 if ( isRelevant(*p) )
200 {
201 fpp_assert ( !(*p)->isSynonym() );
202 dumpRole ( dump, *p );
203 }
204 for ( p = DRM.begin(); p != DRM.end(); ++p )
205 if ( isRelevant(*p) )
206 {
207 fpp_assert ( !(*p)->isSynonym() );
208 dumpRole ( dump, *p );
209 }
210 }
211
212 // dump given concept expression
213 void dumpCExpression ( dumpInterface* dump, const DLTree* C )
214 {
215 if ( C == nullptr )
216 return;
217
218 Token t = C->Element().getToken();
219 diOp tag;
220
221 switch (t)
222 {
223 case TOP:
224 return dump->dumpTop();
225 case BOTTOM:
226 return dump->dumpBottom();
227 case CNAME:
228 case INAME:
229 return dump->dumpConcept(static_cast<TConcept*>(C->Element().getNE()));
230 case NOT:
231 dump->startOp(diNot);
232 dumpCExpression ( dump, C->Left() );
233 return dump->finishOp(diNot);
234 case AND:
235 case OR:
236 tag = t == AND ? diAnd : diOr;
237 dump->startOp(tag);
238 dumpCExpression ( dump, C->Left() );
239 dump->contOp(tag);
240 dumpCExpression ( dump, C->Right() );
241 return dump->finishOp(tag);
242
243 case EXISTS:
244 case FORALL:
245 case LE:
246 case GE:
247 tag = t == EXISTS ? diExists : t == FORALL ? diForall : t == GE ? diGE : diLE;
248 if ( t == GE || t == LE )
249 dump->startOp ( tag, C->Element().getData() );
250 else
251 dump->startOp(tag);
252 dumpRExpression ( dump, C->Left() );
253 dump->contOp(tag);
254 dumpCExpression ( dump, C->Right() );
255 return dump->finishOp(tag);
256 default:
257 fpp_unreachable();
258 }
259 }
260 // dump given role expression
261 void dumpRExpression ( dumpInterface* dump, const DLTree* R )
262 {
263 if ( R == nullptr )
264 return;
265
266 switch ( R->Element().getToken() )
267 {
268 case RNAME:
269 case DNAME:
270 return dump->dumpRole(static_cast<TRole*>(R->Element().getNE()));
271 case NOT:
272 case INV:
273 dump->startOp(diInv);
274 dumpRExpression ( dump, R->Left() );
275 return dump->finishOp(diInv);
276 default:
277 fpp_unreachable();
278 }
279 }