File: dumpInterface.cpp

package info (click to toggle)
fact%2B%2B 1.6.5~dfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 4,496 kB
  • sloc: cpp: 28,000; java: 22,674; xml: 3,268; makefile: 102; ansic: 61; sh: 3
file content (278 lines) | stat: -rw-r--r-- 6,640 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/* This file is part of the FaCT++ DL reasoner
Copyright (C) 2003-2015 Dmitry Tsarkov and The University of Manchester
Copyright (C) 2015-2016 Dmitry Tsarkov

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include "dumpInterface.h"
#include "dlTBox.h"

//-------------------------------------------------------------------------------
// General dumping methods -- dumping relevant parts of ontology
//-------------------------------------------------------------------------------
void TBox :: dump ( dumpInterface* dump ) const
{
	dump->prologue();

	// dump all (relevant) roles
	dumpAllRoles(dump);

	// dump all (relevant) concepts
	for ( c_const_iterator pc = c_begin(); pc != c_end(); ++pc )
		if ( isRelevant(*pc) )
			dumpConcept( dump, *pc );

	for ( i_const_iterator pi = i_begin(); pi != i_end(); ++pi )
		if ( isRelevant(*pi) )
			dumpConcept( dump, *pi );

	// dump GCIs
	if ( getTG() != bpTOP )
	{
		dump->startAx (diImpliesC);
		dump->dumpTop();
		dump->contAx (diImpliesC);
		dumpExpression ( dump, getTG() );
		dump->finishAx (diImpliesC);
	}

	dump->epilogue();
}

void TBox :: dumpConcept ( dumpInterface* dump, const TConcept* p ) const
{
	// dump defConcept
	dump->startAx (diDefineC);
	dump->dumpConcept(p);
	dump->finishAx (diDefineC);

	// dump "p [= def"
	if ( p->pBody != bpTOP )
	{
		diAx Ax = p->isNonPrimitive() ? diEqualsC : diImpliesC;
		dump->startAx (Ax);
		dump->dumpConcept(p);
		dump->contAx (Ax);
		dumpExpression ( dump, p->pBody );
		dump->finishAx (Ax);
	}
}

void TBox :: dumpRole ( dumpInterface* dump, const TRole* p ) const
{
	// dump defRole and parents
	if ( p->getId() > 0 || !isRelevant(p->inverse()) )
	{
		const TRole* q = ( p->getId()>0 ? p : p->inverse() );

		dump->startAx (diDefineR);
		dump->dumpRole(q);
		dump->finishAx (diDefineR);

		// dump parents
		for ( ClassifiableEntry::const_iterator i = q->told_begin(); i != q->told_end(); ++i )
		{
			dump->startAx (diImpliesR);
			dump->dumpRole(q);
			dump->contAx (diImpliesR);
			dump->dumpRole(static_cast<const TRole*>(*i));
			dump->finishAx (diImpliesR);
		}
	}

	// dump transitility
	if ( p->isTransitive() )
	{
		dump->startAx (diTransitiveR);
		dump->dumpRole(p);
		dump->finishAx (diTransitiveR);
	}

	// dump functionality (for topmost-functional roles only)
	if ( p->isTopFunc() )
	{
		dump->startAx (diFunctionalR);
		dump->dumpRole(p);
		dump->finishAx (diFunctionalR);
	}

	// dump "domain"
	if ( p->getBPDomain() != bpTOP )
	{
		dump->startAx (diDomainR);
		dump->dumpRole(p);
		dump->contAx (diDomainR);
		dumpExpression ( dump, p->getBPDomain() );
		dump->finishAx (diDomainR);
	}

	// dump "range"
	if ( p->getBPRange() != bpTOP )
	{
		dump->startAx (diRangeR);
		dump->dumpRole(p);
		dump->contAx (diRangeR);
		dumpExpression ( dump, p->getBPRange() );
		dump->finishAx (diRangeR);
	}
}

void TBox :: dumpExpression ( dumpInterface* dump, BipolarPointer p ) const
{
	fpp_assert ( isValid(p) );

	if ( p == bpTOP )
		return dump->dumpTop();
	if ( p == bpBOTTOM )
		return dump->dumpBottom();

	// checks inversion
	if ( isNegative(p) )
	{
		dump->startOp (diNot);
		dumpExpression ( dump, inverse(p) );
		return dump->finishOp (diNot);
	}

	const DLVertex& v = DLHeap[p];

	switch ( v.Type() )
	{
	case dtTop:
		return dump->dumpTop();

	case dtName:
		return dump->dumpConcept(static_cast<const TConcept*>(v.getConcept()));

	case dtAnd:
		dump->startOp (diAnd);
		for ( DLVertex::const_iterator q = v.begin(); q != v.end(); ++q )
		{
			if ( q != v.begin() )
				dump->contOp (diAnd);
			dumpExpression ( dump, *q );
		}
		dump->finishOp (diAnd);
		return;

	case dtForall:
		dump->startOp (diForall);
		dump->dumpRole (v.getRole());
		dump->contOp(diForall);
		dumpExpression ( dump, v.getC() );
		dump->finishOp (diForall);
		return;

	case dtLE:
		dump->startOp ( diLE, v.getNumberLE() );
		dump->dumpRole (v.getRole());
		dump->contOp(diLE);
		dumpExpression ( dump, v.getC() );
		dump->finishOp (diLE);
		return;

	default:
		std::cerr << "Error dumping vertex of type " << v.getTagName() << "(" << v.Type () << ")";
		fpp_unreachable();
		return;	// invalid value
	}
}

void TBox :: dumpAllRoles ( dumpInterface* dump ) const
{
	RoleMaster::const_iterator p;
	for ( p = ORM.begin(); p != ORM.end(); ++p )
		if ( isRelevant(*p) )
		{
			fpp_assert ( !(*p)->isSynonym() );
			dumpRole ( dump, *p );
		}
	for ( p = DRM.begin(); p != DRM.end(); ++p )
		if ( isRelevant(*p) )
		{
			fpp_assert ( !(*p)->isSynonym() );
			dumpRole ( dump, *p );
		}
}

	// dump given concept expression
void dumpCExpression ( dumpInterface* dump, const DLTree* C )
{
	if ( C == NULL )
		return;

	Token t = C->Element().getToken();
	diOp tag;

	switch (t)
	{
	case TOP:
		return dump->dumpTop();
	case BOTTOM:
		return dump->dumpBottom();
	case CNAME:
	case INAME:
		return dump->dumpConcept(static_cast<TConcept*>(C->Element().getNE()));
	case NOT:
		dump->startOp(diNot);
		dumpCExpression ( dump, C->Left() );
		return dump->finishOp(diNot);
	case AND:
	case OR:
		tag = t == AND ? diAnd : diOr;
		dump->startOp(tag);
		dumpCExpression ( dump, C->Left() );
		dump->contOp(tag);
		dumpCExpression ( dump, C->Right() );
		return dump->finishOp(tag);

	case EXISTS:
	case FORALL:
	case LE:
	case GE:
		tag = t == EXISTS ? diExists : t == FORALL ? diForall : t == GE ? diGE : diLE;
		if ( t == GE || t == LE )
			dump->startOp ( tag, C->Element().getData() );
		else
			dump->startOp(tag);
		dumpRExpression ( dump, C->Left() );
		dump->contOp(tag);
		dumpCExpression ( dump, C->Right() );
		return dump->finishOp(tag);
	default:
		fpp_unreachable();
	}
}
	// dump given role expression
void dumpRExpression ( dumpInterface* dump, const DLTree* R )
{
	if ( R == NULL )
		return;

	switch ( R->Element().getToken() )
	{
	case RNAME:
	case DNAME:
		return dump->dumpRole(static_cast<TRole*>(R->Element().getNE()));
	case NOT:
	case INV:
		dump->startOp(diInv);
		dumpRExpression ( dump, R->Left() );
		return dump->finishOp(diInv);
	default:
		fpp_unreachable();
	}
}