Debian Codegraph @

Source/Reasoner/Ontology/CConcept.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 "CConcept.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Ontology {
29
30
31 CConcept::CConcept() {
32 initConcept();
33 }
34
35
36
37 CConcept* CConcept::initConcept() {
38 mTag = 0;
39 mOperatorCode = CConceptOperator::getConceptOperator(CCNONE);
40 operandCount = 0;
41 operands = 0;
42 opParameter = 0;
43 operatorRole = 0;
44 tax = 0;
45 mNameLinker = 0;
46 mNominalIndiviual = nullptr;
47 mConceptData = nullptr;
48 mVariableLinker = nullptr;
49 mMappingNegated = false;
50 mDataLiteral = nullptr;
51 mDatatype = nullptr;
52 return this;
53 }
54
55
56
57 CConcept *CConcept::init(CConcept *concept) {
58 mNameLinker = concept->getClassNameLinker();
59 mTag = concept->mTag;
60 mOperatorCode = concept->mOperatorCode;
61 operandCount = concept->operandCount;
62 operands = 0;
63 opParameter = concept->opParameter;
64 operatorRole = concept->operatorRole;
65 tax = 0;
66 mNominalIndiviual = concept->mNominalIndiviual;
67 mVariableLinker = concept->mVariableLinker;
68 mMappingNegated = concept->mMappingNegated;
69 mConceptData = nullptr;
70 mDataLiteral = concept->mDataLiteral;
71 mDatatype = concept->mDatatype;
72 return this;
73 }
74
75
76
77 CConcept *CConcept::init(qint64 conTag) {
78 initTag(conTag);
79 mTag = conTag;
80 mOperatorCode = CConceptOperator::getConceptOperator(CCNONE);
81 operandCount = 0;
82 operands = 0;
83 opParameter = 0;
84 operatorRole = 0;
85 tax = 0;
86 mNominalIndiviual = nullptr;
87 mConceptData = nullptr;
88 mVariableLinker = nullptr;
89 mMappingNegated = false;
90 mDataLiteral = nullptr;
91 mDatatype = nullptr;
92 return this;
93 }
94
95 CConcept *CConcept::initConceptCopy(CConcept *concept, CMemoryAllocationManager* memMan) {
96 mNameLinker = concept->getClassNameLinker();
97 mTag = concept->mTag;
98 mOperatorCode = concept->mOperatorCode;
99 operandCount = concept->operandCount;
100 opParameter = concept->opParameter;
101 operatorRole = concept->operatorRole;
102 tax = 0;
103 operands = 0;
104 mNominalIndiviual = concept->mNominalIndiviual;
105 mMappingNegated = concept->mMappingNegated;
106 mDataLiteral = concept->mDataLiteral;
107 mDatatype = concept->mDatatype;
108 mVariableLinker = nullptr;
109 mConceptData = nullptr;
110
111
112 CSortedNegLinker<CConcept *> *opIt = concept->operands;
113 while (memMan && opIt) {
114 CConcept *con = opIt->getData();
115 bool negated = opIt->isNegated();
116 CSortedNegLinker<CConcept *> *opLinker = CObjectAllocator< CSortedNegLinker<CConcept*> >::allocateAndConstruct(memMan);
117 opLinker->init(con,negated);
118 addOperandLinker(opLinker);
119 opIt = (CSortedNegLinker<CConcept *> *)opIt->getNext();
120 }
121
122 CSortedLinker<CVariable*>* varIt = concept->mVariableLinker;
123 while (memMan && varIt) {
124 CVariable* var = varIt->getData();
125 CSortedLinker<CVariable*>* varLinker = CObjectAllocator< CSortedLinker<CVariable*> >::allocateAndConstruct(memMan);
126 varLinker->init(var);
127 addVariableLinker(varLinker);
128 varIt = (CSortedLinker<CVariable *> *)varIt->getNext();
129 }
130
131 return this;
132 }
133
134
135 CVariable* CConcept::getVariable() {
136 if (mVariableLinker) {
137 return mVariableLinker->getData();
138 }
139 return nullptr;
140 }
141
142 CSortedLinker<CVariable*>* CConcept::getVariableLinker() {
143 return mVariableLinker;
144 }
145
146 CConcept* CConcept::setVariableLinker(CSortedLinker<CVariable*>* variableLinker) {
147 mVariableLinker = variableLinker;
148 return this;
149 }
150
151
152 CConcept* CConcept::addVariableLinker(CSortedLinker<CVariable*>* variableLinker) {
153 mVariableLinker = variableLinker->insertSortedNextSorted(mVariableLinker);
154 return this;
155 }
156
157
158 CConcept *CConcept::setConceptTag(qint64 conTag) {
159 mTag = conTag;
160 return this;
161 }
162
163 qint64 CConcept::getConceptTag() const {
164 return mTag;
165 }
166
167
168 CConcept *CConcept::setOperatorCode(qint64 opCode) {
169 mOperatorCode = CConceptOperator::getConceptOperator(opCode);
170 return this;
171 }
172
173 qint64 CConcept::getOperatorCode() {
174 return mOperatorCode->getOperatorCode();
175 }
176
177 CConceptOperator* CConcept::getConceptOperator() {
178 return mOperatorCode;
179 }
180
181 CConcept *CConcept::setOperatorTag(qint64 opTag) {
182 mOperatorCode = CConceptOperator::getConceptOperator(opTag);
183 return this;
184 }
185
186 qint64 CConcept::getDefinitionOperatorTag() {
187 return getOperatorCode();
188 }
189
190
191 qint64 CConcept::getProcessingOperatorTag() {
192 qint64 tag = getOperatorCode();
193 if (tag == CCEQ || tag == CCSUB) {
194 tag = CCAND;
195 }
196 return tag;
197 }
198
199
200
201 CConcept *CConcept::setTerminology(CTerminology *terminology) {
202 tax = terminology;
203 return this;
204 }
205
206 CTerminology *CConcept::getTerminology() {
207 return tax;
208 }
209
210 qint64 CConcept::getTerminologyTag() const {
211 qint64 taxTag = 0;
212 if (tax) {
213 taxTag = tax->getTerminologyID();
214 }
215 return taxTag;
216 }
217
218 QPair<qint64,qint64> CConcept::getTerminologyConceptTagPair() {
219 return QPair<qint64,qint64>(getTerminologyTag(),mTag);
220 }
221
222
223
224 CConcept *CConcept::setParameter(qint64 parameter) {
225 opParameter = parameter;
226 return this;
227 }
228
229 qint64 CConcept::getParameter() {
230 return opParameter;
231 }
232
233
234 CConcept *CConcept::setOperandCount(qint64 count) {
235 operandCount = count;
236 return this;
237 }
238
239 CConcept* CConcept::incOperandCount(cint64 incCount) {
240 operandCount += incCount;
241 return this;
242 }
243
244
245 qint64 CConcept::getOperandCount() {
246 return operandCount;
247 }
248
249
250 CConcept *CConcept::setOperandList(CSortedNegLinker<CConcept *> *operandList) {
251 operands = operandList;
252 return this;
253 }
254
255
256 CConcept *CConcept::addOperandLinker(CSortedNegLinker<CConcept *> *operandLinker) {
257 if (operands) {
258 operands = operands->insertSortedNextSorted(operandLinker);
259 } else {
260 operands = operandLinker;
261 }
262 return this;
263 }
264
265
266 CSortedNegLinker<CConcept *> *CConcept::getOperandList() {
267 return operands;
268 }
269
270 bool CConcept::operator<=(const CConcept &concept) {
271 if (mTag < concept.mTag) {
272 return true;
273 } else if (mTag > concept.mTag) {
274 return false;
275 } else {
276 return getTerminologyTag() <= concept.getTerminologyTag();
277 }
278 }
279
280 bool CConcept::operator==(const CConcept &concept) {
281 return mTag == concept.mTag && tax == concept.tax;
282 }
283
284 CConcept *CConcept::setRole(CRole *role) {
285 operatorRole = role;
286 return this;
287 }
288
289 CRole *CConcept::getRole() {
290 return operatorRole;
291 }
292
293 CIndividual* CConcept::getNominalIndividual() {
294 return mNominalIndiviual;
295 }
296
297
298 bool CConcept::hasNominalIndividual() {
299 return mNominalIndiviual != nullptr;
300 }
301
302
303
304 CConcept* CConcept::setNominalIndividual(CIndividual* nominalIndividual) {
305 mNominalIndiviual = nominalIndividual;
306 return this;
307 }
308
309
310 bool CConcept::isGeneratingOperator(bool negated) {
311 cint64 operatorTag = mOperatorCode->getOperatorCode();
312 if (!negated) {
313 return (operatorTag == CCSOME || operatorTag == CCATLEAST);
314 } else {
315 return (operatorTag == CCALL || operatorTag == CCATMOST);
316 }
317 }
318
319 bool CConcept::isNegatedGeneratingOperator() {
320 return isGeneratingOperator(true);
321 }
322
323
324 bool CConcept::isNonGeneratingOperator() {
325 return !isGeneratingOperator();
326 }
327
328
329 bool CConcept::hasClassName() {
330 return hasName();
331 }
332
333
334 CConcept *CConcept::setClassNameLinker(CLinker<CName *> *conceptNameLinker) {
335 setNameLinker(conceptNameLinker);
336 return this;
337 }
338
339 CConcept *CConcept::addClassNameLinker(CLinker<CName *> *conceptNameLinker) {
340 addNameLinker(conceptNameLinker);
341 return this;
342 }
343
344 CLinker<CName *> *CConcept::getClassNameLinker() {
345 return getNameLinker();
346 }
347
348
349
350 bool CConcept::isEqualsToBOTTOM(bool negated) {
351 cint64 operatorTag = mOperatorCode->getOperatorCode();
352 return (!negated && operatorTag == CCBOTTOM || negated && operatorTag == CCTOP);
353 }
354
355 bool CConcept::isEqualsToTOP(bool negated) {
356 cint64 operatorTag = mOperatorCode->getOperatorCode();
357 return (negated && operatorTag == CCBOTTOM || !negated && operatorTag == CCTOP);
358 }
359
360
361 bool CConcept::hasOperandConceptTag(CConcept *concept) {
362 return hasOperandConceptTag(concept->getConceptTag());
363 }
364
365
366 bool CConcept::hasOperandConceptTag(qint64 conTag) {
367 CSortedNegLinker<CConcept *> *opIt = operands;
368 while (opIt) {
369 qint64 opConTag = opIt->getData()->getConceptTag();
370 if (opConTag == conTag) {
371 return true;
372 } else if (opConTag > conTag) {
373 return false;
374 }
375 opIt = (CSortedNegLinker<CConcept *> *)opIt->getNext();
376 }
377 return false;
378 }
379
380
381 bool CConcept::hasOperandConceptTag(CConcept *concept, bool negation) {
382 return hasOperandConceptTag(concept->getConceptTag(),negation);
383 }
384
385
386 bool CConcept::hasOperandConceptTag(qint64 conTag, bool negation) {
387 CSortedNegLinker<CConcept *> *opIt = operands;
388 while (opIt) {
389 qint64 opConTag = opIt->getData()->getConceptTag();
390 bool opNeg = opIt->isNegated();
391 if (opConTag == conTag && negation == opNeg) {
392 return true;
393 } else if (opConTag > conTag) {
394 return false;
395 }
396 opIt = (CSortedNegLinker<CConcept *> *)opIt->getNext();
397 }
398 return false;
399 }
400
401 bool CConcept::hasOperandConcept(CConcept *concept) {
402 CSortedNegLinker<CConcept *> *opIt = operands;
403 while (opIt) {
404 CConcept* opConcept = opIt->getData();
405 if (opConcept == concept) {
406 return true;
407 }
408 opIt = (CSortedNegLinker<CConcept *> *)opIt->getNext();
409 }
410 return false;
411 }
412
413 bool CConcept::hasOperandConcept(CConcept *concept, bool negation) {
414 CSortedNegLinker<CConcept *> *opIt = operands;
415 while (opIt) {
416 CConcept* opConcept = opIt->getData();
417 bool opNeg = opIt->isNegated();
418 if (opConcept == concept && negation == opNeg) {
419 return true;
420 }
421 opIt = (CSortedNegLinker<CConcept *> *)opIt->getNext();
422 }
423 return false;
424 }
425
426
427 CConceptData* CConcept::getConceptData() {
428 return mConceptData;
429 }
430
431 CConcept* CConcept::setConceptData(CConceptData* conceptData) {
432 mConceptData = conceptData;
433 return this;
434 }
435
436 bool CConcept::hasConceptData() {
437 return mConceptData != nullptr;
438 }
439
440 bool CConcept::hasMappingNegation() {
441 return mMappingNegated;
442 }
443
444 CConcept* CConcept::setMappingNegation(bool negation) {
445 mMappingNegated = negation;
446 return this;
447 }
448
449 CDataLiteral* CConcept::getDataLiteral() {
450 return mDataLiteral;
451 }
452
453 CConcept* CConcept::setDataLiteral(CDataLiteral* dataLiteral) {
454 mDataLiteral = dataLiteral;
455 return this;
456 }
457
458 CDatatype* CConcept::getDatatype() {
459 return mDatatype;
460 }
461
462 CConcept* CConcept::setDatatype(CDatatype* datatype) {
463 mDatatype = datatype;
464 return this;
465 }
466
467 }; // end namespace Ontology
468
469 }; // end namespace Reasoner
470
471 }; // end namespace Konclude