Debian Codegraph @

Source/Reasoner/Ontology/CConceptTextFormater.cpp

raw
1 /*
2 * Copyright (C) 2013-2015, 2019 by the Konclude Developer Team.
3 *
4 * This file is part of the reasoning system Konclude.
5 * For details and support, see <http://konclude.com/>.
6 *
7 * Konclude is free software: you can redistribute it and/or modify
8 * it under the terms of version 3 of the GNU Lesser General Public
9 * License (LGPLv3) as published by the Free Software Foundation.
10 *
11 * Konclude is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU (Lesser) General Public License for more details.
15 *
16 * You should have received a copy of the GNU (Lesser) General Public
17 * License along with Konclude. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include "CConceptTextFormater.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Ontology {
29
30
31 CConceptTextFormater::CConceptTextFormater() {
32 }
33
34
35 CConceptTextFormater::~CConceptTextFormater() {
36 }
37
38
39
40
41 QString CConceptTextFormater::getConceptString(CConcept *concept, bool negated, bool useTag, qint64 defSkipCount) {
42
43 CConcept *con = concept;
44 QString className;
45
46 if (concept->hasClassName()) {
47 defSkipCount--;
48 }
49
50 if (negated) {
51 className += QChar(0x00AC);
52 }
53 if (defSkipCount <= 0 || useTag || concept->getDefinitionOperatorTag() == CCNONE) {
54 className += QString::number(con->getConceptTag());
55 QString iriClassNameString = CIRIName::getRecentIRIName(con->getClassNameLinker());
56 if (!iriClassNameString.isEmpty()) {
57 className += "~";
58 if (iriClassNameString == "http://www.w3.org/2002/07/owl#Thing") {
59 className += QChar(0x22A4);
60 } else {
61 className += iriClassNameString;
62 }
63 }
64 }
65
66
67 if (!concept->hasClassName() || defSkipCount > 0) {
68 if (!className.isEmpty()) {
69 className += " := ";
70 }
71
72 QString conText;
73 qint64 opCode = con->getProcessingOperatorTag();
74 CConceptOperator* conOperator = con->getConceptOperator();
75 if (negated) {
76 conText += QChar(0x00AC);
77 }
78 conText += " (";
79 if (opCode == CCATOM) {
80 conText += QString::number(con->getConceptTag())+QString("~ATOM");
81 }
82 if (opCode == CCNOMINAL) {
83 conText += QString::number(con->getConceptTag())+QString("~{%1~%2}").arg(con->getNominalIndividual()->getIndividualID()).arg(CIRIName::getRecentIRIName(con->getNominalIndividual()->getIndividualNameLinker()));
84 }
85 if (opCode == CCVALUE) {
86 conText += QString(" VALUE ");
87 if (con->getRole()->hasPropertyName()) {
88 conText += QString(" %1. ").arg(CIRIName::getRecentIRIName(con->getRole()->getPropertyNameLinker()));
89 } else {
90 conText += QString(" %1. ").arg(con->getRole()->getRoleTag());
91 }
92 conText += QString::number(con->getConceptTag())+QString("~{%1~%2}").arg(con->getNominalIndividual()->getIndividualID()).arg(CIRIName::getRecentIRIName(con->getNominalIndividual()->getIndividualNameLinker()));
93 }
94 if (opCode == CCEQCAND) {
95 conText += QString::number(con->getConceptTag())+QString("~EQCONCAND");
96 }
97 if (opCode == CCDATATYPE) {
98 conText += QString::number(con->getConceptTag())+QString("~DATATYPE");
99 CDatatype* datatype = con->getDatatype();
100 if (datatype) {
101 conText += QString("-%1").arg(datatype->getDatatypeIRI());
102 }
103 }
104 if (opCode == CCDATARESTRICTION) {
105 conText += QString::number(con->getConceptTag())+QString("~DATARESTRICTION");
106 cint64 restrictionCode = con->getParameter();
107 QString restrictionString;
108 if (restrictionCode == CDFC_RATIONAL) {
109 restrictionString = "rationals-only";
110 } else if (restrictionCode == CDFC_DECIMAL) {
111 restrictionString = "decimals-only";
112 } else if (restrictionCode == CDFC_INTEGER) {
113 restrictionString = "integers-only";
114 } else if (restrictionCode == CDFC_MIN_EXCLUSIVE) {
115 restrictionString = "min-exclusive";
116 } else if (restrictionCode == CDFC_MIN_INCLUSIVE) {
117 restrictionString = "min-inclusive";
118 } else if (restrictionCode == CDFC_MAX_INCLUSIVE) {
119 restrictionString = "max-inclusive";
120 } else if (restrictionCode == CDFC_MAX_EXCLUSIVE) {
121 restrictionString = "max-exclusive";
122 }
123 conText += QString("-%1").arg(restrictionString);
124 CDataLiteral* dataLiteral = con->getDataLiteral();
125 if (dataLiteral) {
126 conText += QString(":-{%1}").arg(dataLiteral->getLexicalDataLiteralValueString());
127 }
128 }
129 if (opCode == CCDATALITERAL) {
130 conText += QString::number(con->getConceptTag())+QString("~DATALITERAL");
131 CDataLiteral* dataLit = con->getDataLiteral();
132 if (dataLit) {
133 conText += QString("-{%1}").arg(dataLit->getLexicalDataLiteralValueString());
134 }
135 }
136 if (opCode == CCIMPLTRIG) {
137 conText += QString::number(con->getConceptTag())+QString("~IMPLTRIG");
138 }
139 if (opCode == CCBRANCHTRIG) {
140 conText += QString::number(con->getConceptTag())+QString("~BRANCHTRIGGER");
141 }
142 if (conOperator->hasPartialOperatorCodeFlag(CConceptOperator::CCFS_AND_AQAND_TYPE)) {
143 bool opInserted = false;
144 CSortedNegLinker<CConcept *> *opLinker = con->getOperandList();
145 while (opLinker) {
146 if (opInserted) {
147 conText += QString(" AND ");
148 }
149 if (opLinker->isNegated()) {
150 conText += QChar(0x00AC);
151 }
152 opInserted = true;
153 //conText += QString::number(opLinker->getData()->getConceptTag());
154 conText += getConceptString(opLinker->getData(),false,false,defSkipCount);
155 opLinker = opLinker->getNext();
156 }
157 }
158
159 if (opCode == CCPBINDTRIG) {
160 conText += QString::number(con->getConceptTag())+QString("~PBINDTRIG");
161 }
162 if (opCode == CCVARBINDTRIG) {
163 conText += QString::number(con->getConceptTag())+QString("~VARBINDTRIG");
164 }
165 if (opCode == CCVARPBACKTRIG) {
166 conText += QString::number(con->getConceptTag())+QString("~VARPBACKTRIG");
167 }
168 if (opCode == CCBACKACTIVTRIG) {
169 conText += QString::number(con->getConceptTag())+QString("~BACKACTIVTRIG");
170 }
171 if (opCode == CCAQCHOOCE) {
172 bool opInserted = false;
173 CSortedNegLinker<CConcept *> *opLinker = con->getOperandList();
174 while (opLinker) {
175 if (!opLinker->isNegated()) {
176 conText += getConceptString(opLinker->getData(),false,false,defSkipCount);
177 }
178 opLinker = opLinker->getNext();
179 }
180 }
181 if (conOperator->hasPartialOperatorCodeFlag(CConceptOperator::CCFS_IMPL_TYPE)) {
182 bool opInserted = false;
183 CSortedNegLinker<CConcept *> *opLinker = con->getOperandList();
184
185 QString impConText = getConceptString(opLinker->getData(),false,false,defSkipCount);
186
187 opLinker = opLinker->getNext();
188 while (opLinker) {
189 if (opInserted) {
190 conText += QString(", ");
191 }
192 if (opLinker->isNegated()) {
193 conText += QChar(0x00AC);
194 }
195 opInserted = true;
196 //conText += QString::number(opLinker->getData()->getConceptTag());
197 conText += getConceptString(opLinker->getData(),false,false,defSkipCount);
198 opLinker = opLinker->getNext();
199 }
200 conText += QString(" ---->>> ")+impConText;
201 }
202 if (opCode == CCPBINDCYCLE) {
203 bool opInserted = false;
204 CSortedNegLinker<CConcept *> *opLinker = con->getOperandList();
205
206 QString impConText = getConceptString(opLinker->getData(),false,false,defSkipCount);
207
208 opLinker = opLinker->getNext();
209 while (opLinker) {
210 if (opInserted) {
211 conText += QString(", ");
212 }
213 if (opLinker->isNegated()) {
214 conText += QChar(0x00AC);
215 }
216 opInserted = true;
217 //conText += QString::number(opLinker->getData()->getConceptTag());
218 conText += getConceptString(opLinker->getData(),false,false,defSkipCount);
219 opLinker = opLinker->getNext();
220 }
221 conText += QString(" @---->>> ")+impConText;
222 }
223 if (opCode == CCVARBINDJOIN) {
224 bool opInserted = false;
225 CSortedNegLinker<CConcept *> *opLinker = con->getOperandList();
226
227 QString impConText = getConceptString(opLinker->getData(),false,false,defSkipCount);
228
229 opLinker = opLinker->getNext();
230 while (opLinker) {
231 if (opInserted) {
232 conText += QString(", ");
233 }
234 if (opLinker->isNegated()) {
235 conText += QChar(0x00AC);
236 }
237 opInserted = true;
238 //conText += QString::number(opLinker->getData()->getConceptTag());
239 conText += getConceptString(opLinker->getData(),false,false,defSkipCount);
240 opLinker = opLinker->getNext();
241 }
242 conText += QString(" |><|---->>> ")+impConText;
243 }
244 if (opCode == CCOR) {
245 bool opInserted = false;
246 CSortedNegLinker<CConcept *> *opLinker = con->getOperandList();
247 while (opLinker) {
248 if (opInserted) {
249 conText += QString(" OR ");
250 }
251 if (opLinker->isNegated()) {
252 conText += QChar(0x00AC);
253 }
254 opInserted = true;
255 //conText += QString::number(opLinker->getData()->getConceptTag());
256 conText += getConceptString(opLinker->getData(),false,false,defSkipCount);
257 opLinker = opLinker->getNext();
258 }
259 }
260 if (opCode == CCSOME || opCode == CCAQSOME) {
261 bool opInserted = false;
262 CSortedNegLinker<CConcept *> *opLinker = con->getOperandList();
263 conText += QString(" SOME ");
264 if (con->getRole()->hasPropertyName()) {
265 conText += QString(" %1. ").arg(CIRIName::getRecentIRIName(con->getRole()->getPropertyNameLinker()));
266 } else {
267 conText += QString(" %1. ").arg(con->getRole()->getRoleTag());
268 }
269 while (opLinker) {
270 if (opInserted) {
271 conText += ", ";
272 }
273 if (opLinker->isNegated()) {
274 conText += QChar(0x00AC);
275 }
276 opInserted = true;
277 //conText += QString::number(opLinker->getData()->getConceptTag());
278 conText += getConceptString(opLinker->getData(),false,false,defSkipCount);
279 opLinker = opLinker->getNext();
280 }
281 }
282 if (opCode == CCPBINDVARIABLE) {
283 bool opInserted = false;
284 CSortedNegLinker<CConcept *> *opLinker = con->getOperandList();
285 conText += QString(" PBINDVARIABLE ");
286 while (opLinker) {
287 if (opInserted) {
288 conText += ", ";
289 }
290 if (opLinker->isNegated()) {
291 conText += QChar(0x00AC);
292 }
293 opInserted = true;
294 conText += getConceptString(opLinker->getData(),false,false,defSkipCount);
295 opLinker = opLinker->getNext();
296 }
297 }
298 if (opCode == CCVARBINDVARIABLE) {
299 bool opInserted = false;
300 CSortedNegLinker<CConcept *> *opLinker = con->getOperandList();
301 conText += QString(" VARBINDVARIABLE ");
302 while (opLinker) {
303 if (opInserted) {
304 conText += ", ";
305 }
306 if (opLinker->isNegated()) {
307 conText += QChar(0x00AC);
308 }
309 opInserted = true;
310 conText += getConceptString(opLinker->getData(),false,false,defSkipCount);
311 opLinker = opLinker->getNext();
312 }
313 }
314 if (conOperator->hasPartialOperatorCodeFlag(CConceptOperator::CCFS_AQALL_TYPE)) {
315 conText += QString(" All ");
316 if (con->getRole()->hasPropertyName()) {
317 conText += QString(" %1. ").arg(CIRIName::getRecentIRIName(con->getRole()->getPropertyNameLinker()));
318 } else {
319 conText += QString(" %1. ").arg(con->getRole()->getRoleTag());
320 }
321 if (con->getVariableLinker()) {
322 cint64 varId = con->getVariable()->getPathVariableID();
323 QString varIdString = QString("%1").arg(varId);
324 #ifndef KONCLUDE_FORCE_ALL_DEBUG_DEACTIVATED
325 QString debugVariableName = con->getVariable()->mDebugVariableName;
326 varIdString += QString("~%1").arg(debugVariableName);
327 #endif
328 conText += QString(" >>{%1} ").arg(varId);
329 }
330 conText += QString::number(con->getOperandList()->getData()->getConceptTag());
331 }
332
333 if (conOperator->hasPartialOperatorCodeFlag(CConceptOperator::CCFS_ALL_TYPE)) {
334 bool opInserted = false;
335 CSortedNegLinker<CConcept *> *opLinker = con->getOperandList();
336 conText += QString(" ALL ");
337 if (con->getRole()->hasPropertyName()) {
338 conText += QString(" %1. ").arg(CIRIName::getRecentIRIName(con->getRole()->getPropertyNameLinker()));
339 } else {
340 conText += QString(" %1. ").arg(con->getRole()->getRoleTag());
341 }
342 while (opLinker) {
343 if (opInserted) {
344 conText += ", ";
345 }
346 if (opLinker->isNegated()) {
347 conText += QChar(0x00AC);
348 }
349 opInserted = true;
350 //conText += QString::number(opLinker->getData()->getConceptTag());
351 conText += getConceptString(opLinker->getData(),false,false,defSkipCount);
352 opLinker = opLinker->getNext();
353 }
354 }
355 if (opCode == CCATLEAST) {
356 bool opInserted = false;
357 CSortedNegLinker<CConcept *> *opLinker = con->getOperandList();
358 conText += QString(" ATLEAST ");
359 conText += QString(" [%1]").arg(con->getParameter());
360 if (con->getRole()->hasPropertyName()) {
361 conText += QString(" %1. ").arg(CIRIName::getRecentIRIName(con->getRole()->getPropertyNameLinker()));
362 } else {
363 conText += QString(" %1. ").arg(con->getRole()->getRoleTag());
364 }
365 while (opLinker) {
366 if (opInserted) {
367 conText += ", ";
368 }
369 if (opLinker->isNegated()) {
370 conText += QChar(0x00AC);
371 }
372 opInserted = true;
373 //conText += QString::number(opLinker->getData()->getConceptTag());
374 conText += getConceptString(opLinker->getData(),false,false,defSkipCount);
375 opLinker = opLinker->getNext();
376 }
377 }
378 if (opCode == CCPBINDGROUND || opCode == CCVARBINDGROUND) {
379 conText += QString(" GROUND ");
380 conText += QString(" [%1]").arg(con->getParameter());
381 }
382 if (opCode == CCATMOST) {
383 bool opInserted = false;
384 CSortedNegLinker<CConcept *> *opLinker = con->getOperandList();
385 conText += QString(" ATMOST ");
386 conText += QString(" [%1]").arg(con->getParameter());
387 if (con->getRole()->hasPropertyName()) {
388 conText += QString(" %1. ").arg(CIRIName::getRecentIRIName(con->getRole()->getPropertyNameLinker()));
389 } else {
390 conText += QString(" %1. ").arg(con->getRole()->getRoleTag());
391 }
392 while (opLinker) {
393 if (opInserted) {
394 conText += ", ";
395 }
396 if (opLinker->isNegated()) {
397 conText += QChar(0x00AC);
398 }
399 opInserted = true;
400 //conText += QString::number(opLinker->getData()->getConceptTag());
401 conText += getConceptString(opLinker->getData(),false,false,defSkipCount);
402 opLinker = opLinker->getNext();
403 }
404 }
405
406 conText += ") ";
407 className += conText;
408 }
409 return className;
410 }
411
412
413
414
415
416
417
418 }; // end namespace Ontology
419
420 }; // end namespace Reasoner
421
422 }; // end namespace Konclude