Debian Codegraph @

Source/Reasoner/Kernel/Process/CConceptLabelSet.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 "CConceptLabelSet.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Kernel {
29
30 namespace Process {
31
32
33
34 CConceptLabelSet::CConceptLabelSet(CProcessContext* processContext) : mProcessContext(processContext),mConceptDesDepMap(processContext) {
35 mConceptDesLinker = nullptr;
36 mPrevConceptDesLinker = nullptr;
37 mConceptCount = 0;
38 }
39
40
41 CConceptLabelSet::~CConceptLabelSet() {
42 }
43
44
45 CConceptSetSignature* CConceptLabelSet::getConceptSignature() {
46 return &mConceptSignature;
47 }
48
49
50 cint64 CConceptLabelSet::getConceptSignatureValue() {
51 return mConceptSignature.getSignatureValue();
52 }
53
54
55 CConceptLabelSet* CConceptLabelSet::initConceptLabelSet(CConceptLabelSet* prevConceptLabelSet) {
56 if (prevConceptLabelSet) {
57 mConceptDesLinker = prevConceptLabelSet->mConceptDesLinker;
58 mPrevConceptDesLinker = mConceptDesLinker;
59 mConceptCount = prevConceptLabelSet->mConceptCount;
60 mConceptDesDepMap = prevConceptLabelSet->mConceptDesDepMap;
61 } else {
62 mConceptDesDepMap.clear();
63 mConceptDesLinker = nullptr;
64 mPrevConceptDesLinker = nullptr;
65 mConceptCount = 0;
66 }
67 return this;
68 }
69
70
71
72 bool CConceptLabelSet::hasConceptDescriptor(CConceptDescriptor* conceptDescriptor) {
73 return hasConcept(conceptDescriptor->getConcept(),conceptDescriptor->getNegation());
74 }
75
76
77 bool CConceptLabelSet::containsConceptDescriptor(CConceptDescriptor* conceptDescriptor) {
78 return hasConceptDescriptor(conceptDescriptor);
79 }
80
81
82 bool CConceptLabelSet::hasConcept(CConcept* concept, bool negated) {
83 cint64 conTag = concept->getConceptTag();
84 CConceptDescriptorDependencyPair* conDesDepPair = nullptr;
85 bool isContained = mConceptDesDepMap.tryGetValuePointer(conTag,conDesDepPair);
86 return isContained && conDesDepPair->first->isNegated() == negated;
87 }
88
89 bool CConceptLabelSet::hasConcept(CConcept* concept, bool* containsNegated) {
90 cint64 conTag = concept->getConceptTag();
91 CConceptDescriptorDependencyPair* conDesDepPair = nullptr;
92 bool isContained = mConceptDesDepMap.tryGetValuePointer(conTag,conDesDepPair);
93 if (isContained && containsNegated) {
94 *containsNegated = conDesDepPair->first->isNegated();
95 }
96 return isContained;
97 }
98
99 bool CConceptLabelSet::containsConcept(CConcept* concept, bool* containsNegated) {
100 return hasConcept(concept,containsNegated);
101 }
102
103 bool CConceptLabelSet::containsConcept(CConcept* concept, bool negated) {
104 return hasConcept(concept,negated);
105 }
106
107
108 CClashedConceptDescriptor* CConceptLabelSet::insertConceptReturnClash(CConceptDescriptor* conceptDescriptor, CDependencyTrackPoint* depTrackPoint) {
109 cint64 conTag = conceptDescriptor->getConceptTag();
110 bool alreadyContained = false;
111 CPROCESSMAP<cint64,CConceptDescriptorDependencyPair>::iterator it = mConceptDesDepMap.tryInsert(conTag,CConceptDescriptorDependencyPair(conceptDescriptor,depTrackPoint),&alreadyContained);
112 if (alreadyContained) {
113 cint64 containConceptTag(it.key());
114 CConceptDescriptorDependencyPair containsDesDepPair(it.value());
115 CConceptDescriptor* containsConDes = containsDesDepPair.first;
116 if (containsConDes->isNegated() != conceptDescriptor->isNegated()) {
117 CDependencyTrackPoint* containsDepTrackPoint = containsDesDepPair.second;
118 // create clash
119 CClashedConceptDescriptor* clashDes1 = CObjectAllocator<CClashedConceptDescriptor>::allocateAndConstruct(CContext::getMemoryAllocationManager(mProcessContext));
120 clashDes1->initClashedConceptDescriptor(conceptDescriptor,depTrackPoint,0);
121 CClashedConceptDescriptor* clashDes2 = CObjectAllocator<CClashedConceptDescriptor>::allocateAndConstruct(CContext::getMemoryAllocationManager(mProcessContext));
122 clashDes2->initClashedConceptDescriptor(containsConDes,containsDesDepPair.second,0);
123 clashDes1->append(clashDes2);
124 return clashDes1;
125 }
126 } else {
127 ++mConceptCount;
128 mConceptSignature.addConceptSignature(conceptDescriptor);
129 mConceptDesLinker = conceptDescriptor->append(mConceptDesLinker);
130 }
131 return nullptr;
132 }
133
134
135 CConceptLabelSet* CConceptLabelSet::insertConceptThrowClash(CConceptDescriptor* conceptDescriptor, CDependencyTrackPoint* depTrackPoint) {
136 CClashedConceptDescriptor* clash = insertConceptReturnClash(conceptDescriptor,depTrackPoint);
137 if (clash) {
138 throw clash;
139 }
140 return this;
141 }
142
143
144 CConceptLabelSet* CConceptLabelSet::updateConceptDependencyTrackPoint(CConceptDescriptor* conceptDescriptor, CDependencyTrackPoint* updateDepTrackPoint) {
145 cint64 conTag = conceptDescriptor->getConceptTag();
146 mConceptDesDepMap.insert(conTag,CConceptDescriptorDependencyPair(conceptDescriptor,updateDepTrackPoint));
147 return this;
148 }
149
150
151
152 cint64 CConceptLabelSet::getConceptCount() {
153 return mConceptCount;
154 }
155
156 CConceptLabelSetIterator CConceptLabelSet::getConceptLabelSetIterator(bool getSorted, bool getDependencies) {
157 if (getSorted || getDependencies) {
158 return CConceptLabelSetIterator(mConceptCount,nullptr,mConceptDesDepMap.begin(),mConceptDesDepMap.end());
159 } else {
160 return CConceptLabelSetIterator(mConceptCount,mConceptDesLinker,mConceptDesDepMap.end(),mConceptDesDepMap.end());
161 }
162 }
163
164
165
166 }; // end namespace Process
167
168 }; // end namespace Kernel
169
170 }; // end namespace Reasoner
171
172 }; // end namespace Konclude