Debian Codegraph @

Source/Reasoner/Generator/CConcreteOntologyBasementBuilder.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 "CConcreteOntologyBasementBuilder.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Generator {
29
30 CConcreteOntologyBasementBuilder::CConcreteOntologyBasementBuilder(CConcreteOntology* basementBuildConcreteOntology) {
31 LOG(NOTICE,"::Konclude::Reasoner::Generator::ConcreteOntologyBasementBuilder",logTr("ConcreteOntologyBasementBuilder initialized."),this);
32 mOnto = basementBuildConcreteOntology;
33 }
34
35 CConcreteOntologyBasementBuilder::~CConcreteOntologyBasementBuilder() {
36 }
37
38
39
40
41
42 bool CConcreteOntologyBasementBuilder::initializeBuilding() {
43 mOntoStrings = mOnto->getStringMapping();
44 mOntoStrings = mOnto->getStringMapping();
45 mOntoData = mOnto->getDataBoxes();
46 mOntoBuild = mOnto->getBuildData();
47
48 tBox = mOntoData->getTBox();
49 rBox = mOntoData->getRBox();
50 aBox = mOntoData->getABox();
51
52 mOntoData->setBasicBuild(true);
53
54 mMemManager = CContext::getMemoryAllocationManager(mOnto->getOntologyContext());
55
56 mTellAxiomSet = mOntoBuild->getTellAxiomSet();
57 mRetractAxiomSet = mOntoBuild->getRetractAxiomSet();
58
59 mTellUpdatedAxiomSet = mOntoBuild->getUpdatedTellAxiomSet();
60 mRetractUpdatedAxiomSet = mOntoBuild->getUpdatedRetractAxiomSet();
61
62 mUpdateClassAxiomHash = mOntoData->getExpressionDataBoxMapping()->getUpdatedClassAxiomTellOrRetractHash();
63 mUpdateObjectPropertyAxiomHash = mOntoData->getExpressionDataBoxMapping()->getUpdateObjectPropertyAxiomHash();
64
65 mClassTermClassAxiomSet = mOntoData->getExpressionDataBoxMapping()->getClassTermExpressionClassAxiomExpressionSet();
66 mClassTermClassAxiomHash = mOntoData->getExpressionDataBoxMapping()->getClassTermExpressionClassAxiomExpressionHash();
67
68 mObjPropTermObjPropAxiomSet = mOntoData->getExpressionDataBoxMapping()->getObjectPropertyTermObjectPropertyAxiomSet();
69 mObjPropTermObjPropAxiomHash = mOntoData->getExpressionDataBoxMapping()->getObjectPropertyTermObjectPropertyAxiomHash();
70
71 mTopRebuildClassTermExpressionsSet = mOntoData->getExpressionDataBoxMapping()->getTopRebuildClassTermExpressionsSet();
72 mTopRebuildObjectPropertyTermExpressionsSet = mOntoData->getExpressionDataBoxMapping()->getTopRebuildObjectPropertyTermExpressionsSet();
73
74
75 mActiveEntityCountVector = mOntoData->getExpressionDataBoxMapping()->getActiveEntityVector();
76
77
78 mTopClassExpression = mOntoBuild->getTopClassExpression();
79 mBottomClassExpression = mOntoBuild->getBottomClassExpression();
80 mTopObjPropExpression = mOntoBuild->getTopObjectPropertyExpression();
81 mBottomObjPropExpression = mOntoBuild->getBottomObjectPropertyExpression();
82
83 mTopDataPropExpression = mOntoBuild->getTopDataPropertyExpression();
84 mBottomDataPropExpression = mOntoBuild->getBottomDataPropertyExpression();
85
86 mClassTermConceptHash = mOntoData->getExpressionDataBoxMapping()->getClassTermConceptMappingHash();
87 mConceptClassTermHash = mOntoData->getExpressionDataBoxMapping()->getConceptClassTermMappingHash();
88
89
90 mDataRangeTermConceptHash = mOntoData->getExpressionDataBoxMapping()->getDataRangeTermConceptMappingHash();
91 mConceptDataRangeTermHash = mOntoData->getExpressionDataBoxMapping()->getConceptDataRangeTermMappingHash();
92
93
94
95 mObjPropTermRoleHash = mOntoData->getExpressionDataBoxMapping()->getObjectPropertyTermRoleMappingHash();
96 mRoleObjPropTermHash = mOntoData->getExpressionDataBoxMapping()->getRoleObjectPropertyTermMappingHash();
97
98 mDataPropTermRoleHash = mOntoData->getExpressionDataBoxMapping()->getDataPropertyTermRoleMappingHash();
99 mRoleDataPropTermHash = mOntoData->getExpressionDataBoxMapping()->getRoleDataPropertyTermMappingHash();
100
101 mDataPropTermRoleHash = mOntoData->getExpressionDataBoxMapping()->getDataPropertyTermRoleMappingHash();
102 mRoleDataPropTermHash = mOntoData->getExpressionDataBoxMapping()->getRoleDataPropertyTermMappingHash();
103
104 mIndividulTermIndiHash = mOntoData->getExpressionDataBoxMapping()->getIndividulTermIndiMappingHash();
105 mIndiIndividulTermHash = mOntoData->getExpressionDataBoxMapping()->getIndiIndividulTermMappingHash();
106
107 mExpressionBuildContainerList = mOntoBuild->getExpressionBuildListContainer();
108 mInverseObjectPropertyHash = mOntoBuild->getInverseObjectPropertyHash();
109
110
111 mExpressionBuildHash = mOntoBuild->getStructuralExpressionBuildHash();
112
113 mClassBuildHash = mOntoBuild->getClassEntityBuildHash();
114 mObjectPropertyBuildHash = mOntoBuild->getObjectPropertyEntityBuildHash();
115 mIndividualBuildHash = mOntoBuild->getIndividualEntityBuildHash();
116 mDataPropertyBuildHash = mOntoBuild->getDataPropertyEntityBuildHash();
117
118 mAbbreviatedNamePrefixMapHash = mOntoStrings->getAbbreviatedNamePrefixHash();
119 mNamePrefixMapHash = mOntoStrings->getNamePrefixHash();
120
121 mDatatypeExpDatatypeHash = mOntoData->getExpressionDataBoxMapping()->getDatatypeExpressionDatatypeHash();
122 mDatatypeDatatypeExpHash = mOntoData->getExpressionDataBoxMapping()->getDatatypeDatatypeExpessionHash();
123
124 mDatatypeBuildHash = mOntoBuild->getDatatypeIRIBuildHash();
125
126 return true;
127 }
128
129
130
131 bool CConcreteOntologyBasementBuilder::updateName(CNamedItem* item, const QString& name) {
132 bool nameAdded = false;
133 if (!CIRIName::hasIRIName(item->getNameLinker(),name)) {
134 cint64 lastNameID = CName::getLastNameVersionID(item->getNameLinker());
135 if (lastNameID < 0) {
136 lastNameID = 0;
137 }
138 FOREACHHASHIT (QString prefix, CNamePrefix* namePrefix, *mNamePrefixMapHash) {
139 if (name.startsWith(prefix)) {
140 CAbbreviatedIRIName* newName = CObjectAllocator<CAbbreviatedIRIName>::allocateAndConstruct(mMemManager);
141 QString abbString = name.mid(prefix.length());
142 newName->init(namePrefix,abbString);
143 newName->setNameVersionID(lastNameID);
144 CLinker<CName*>* newNameLinker = CObjectAllocator< CLinker<CName*> >::allocateAndConstruct(mMemManager);
145 newNameLinker->init(newName);
146 item->addNameLinker(newNameLinker);
147 nameAdded = true;
148 }
149 }
150 if (!nameAdded) {
151 CIRIName* newName = CObjectAllocator<CIRIName>::allocateAndConstruct(mMemManager);
152 newName->init(name);
153 newName->setNameVersionID(lastNameID);
154 CLinker<CName*>* newNameLinker = CObjectAllocator< CLinker<CName*> >::allocateAndConstruct(mMemManager);
155 newNameLinker->init(newName);
156 item->addNameLinker(newNameLinker);
157 }
158 }
159 return nameAdded;
160 }
161
162
163
164 bool CConcreteOntologyBasementBuilder::createDatatype(const QString& datatypeIRI) {
165 if (!mDatatypeBuildHash->contains(datatypeIRI)) {
166 CDatatypeExpression* datatypeExpression = new CDatatypeExpression(datatypeIRI);
167 datatypeExpression->setEntityID(mOntoBuild->getNextEntityNumber(true));
168 mDatatypeBuildHash->insert(datatypeIRI,datatypeExpression);
169 CDatatype* datatype = new CDatatype();
170 datatype->initDatatype(datatypeIRI);
171 mDatatypeExpDatatypeHash->insert(datatypeExpression,datatype);
172 mDatatypeDatatypeExpHash->insert(datatype,datatypeExpression);
173 CDatatypeVector* datatypeVector = tBox->getDatatypeVector(true);
174 datatype->setDatatypeTag(datatypeVector->getItemCount());
175 datatypeVector->setData(datatype->getDatatypeTag(),datatype);
176 }
177 return true;
178 }
179
180
181 bool CConcreteOntologyBasementBuilder::buildOntologyBasement() {
182 // generate top and bottom class and concept
183 addNameAbbreviation(PREFIX_OWL,"owl");
184 addNameAbbreviation(PREFIX_RDF,"rdf");
185 addNameAbbreviation(PREFIX_XML,"xml");
186 addNameAbbreviation(PREFIX_XSD,"xsd");
187 addNameAbbreviation(PREFIX_RDFS,"rdfs");
188
189 QString topConceptString = PREFIX_OWL_THING;
190 QString bottomConceptString = PREFIX_OWL_NOTHING;
191
192 QString topObjectRoleString = PREFIX_OWL_TOPOBJECTPROPERTY;
193 QString bottomObjectRoleString = PREFIX_OWL_BOTTOMOBJECTPROPERTY;
194
195 QString topDataRoleString = PREFIX_OWL_TOPDATAPROPERTY;
196 QString bottomDataRoleString = PREFIX_OWL_BOTTOMDATAPROPERTY;
197
198 mActiveEntityCountVector->increaseVectorSize(mOntoBuild->getNextEntityNumber(false)+6+35);
199 if (!mTopClassExpression) {
200 CClassExpression* topClassExpression = new CClassExpression(topConceptString);
201 topClassExpression->setEntityID(mOntoBuild->getNextEntityNumber(true));
202 mActiveEntityCountVector->incActiveEntityCount(topClassExpression);
203 mExpressionBuildContainerList->append(topClassExpression);
204 mClassBuildHash->insert(topConceptString,topClassExpression);
205 mTopClassExpression = topClassExpression;
206 mOntoBuild->setTopClassExpression(mTopClassExpression);
207 }
208 if (!mBottomClassExpression) {
209 CClassExpression* bottomClassExpression = new CClassExpression(bottomConceptString);
210 bottomClassExpression->setEntityID(mOntoBuild->getNextEntityNumber(true));
211 mActiveEntityCountVector->incActiveEntityCount(bottomClassExpression);
212 mExpressionBuildContainerList->append(bottomClassExpression);
213 mClassBuildHash->insert(bottomConceptString,bottomClassExpression);
214 mBottomClassExpression = bottomClassExpression;
215 mOntoBuild->setBottomClassExpression(mBottomClassExpression);
216 }
217 if (!mTopObjPropExpression) {
218 CObjectPropertyExpression* topObjPropExpression = new CObjectPropertyExpression(topObjectRoleString);
219 topObjPropExpression->setEntityID(mOntoBuild->getNextEntityNumber(true));
220 mActiveEntityCountVector->incActiveEntityCount(topObjPropExpression);
221 mExpressionBuildContainerList->append(topObjPropExpression);
222 mObjectPropertyBuildHash->insert(topObjectRoleString,topObjPropExpression);
223 mTopObjPropExpression = topObjPropExpression;
224 mOntoBuild->setTopObjectPropertyExpression(mTopObjPropExpression);
225 }
226 if (!mBottomObjPropExpression) {
227 CObjectPropertyExpression* bottomObjPropExpression = new CObjectPropertyExpression(bottomObjectRoleString);
228 bottomObjPropExpression->setEntityID(mOntoBuild->getNextEntityNumber(true));
229 mActiveEntityCountVector->incActiveEntityCount(bottomObjPropExpression);
230 mExpressionBuildContainerList->append(bottomObjPropExpression);
231 mObjectPropertyBuildHash->insert(bottomObjectRoleString,bottomObjPropExpression);
232 mBottomObjPropExpression = bottomObjPropExpression;
233 mOntoBuild->setBottomObjectPropertyExpression(mBottomObjPropExpression);
234 }
235
236 if (!mTopDataPropExpression) {
237 CDataPropertyExpression* topDataPropExpression = new CDataPropertyExpression(topDataRoleString);
238 topDataPropExpression->setEntityID(mOntoBuild->getNextEntityNumber(true));
239 mActiveEntityCountVector->incActiveEntityCount(topDataPropExpression);
240 mExpressionBuildContainerList->append(topDataPropExpression);
241 mDataPropertyBuildHash->insert(topDataRoleString,topDataPropExpression);
242 mTopDataPropExpression = topDataPropExpression;
243 mOntoBuild->setTopDataPropertyExpression(mTopDataPropExpression);
244 }
245 if (!mBottomDataPropExpression) {
246 CDataPropertyExpression* bottomDataPropExpression = new CDataPropertyExpression(bottomDataRoleString);
247 bottomDataPropExpression->setEntityID(mOntoBuild->getNextEntityNumber(true));
248 mActiveEntityCountVector->incActiveEntityCount(bottomDataPropExpression);
249 mExpressionBuildContainerList->append(bottomDataPropExpression);
250 mDataPropertyBuildHash->insert(bottomDataRoleString,bottomDataPropExpression);
251 mBottomDataPropExpression = bottomDataPropExpression;
252 mOntoBuild->setBottomDataPropertyExpression(mBottomDataPropExpression);
253 }
254
255 CMemoryAllocationManager* tBoxMemMan = CContext::getMemoryAllocationManager(tBox->getBoxContext());
256 CConcept* topConcept = tBox->getTopConcept();
257 if (!topConcept) {
258 topConcept = CObjectAllocator<CConcept>::allocateAndConstruct(tBoxMemMan);
259 topConcept->initConcept();
260 topConcept->setConceptTag(tBox->getTopConceptIndex());
261 topConcept->setOperatorCode(CCTOP);
262 updateName(topConcept,topConceptString);
263 mClassTermConceptHash->insert(mTopClassExpression,topConcept);
264 mConceptClassTermHash->insert(topConcept,mTopClassExpression);
265 tBox->setTopConcept(topConcept);
266 }
267 CConcept* bottomConcept = tBox->getBottomConcept();
268 if (!bottomConcept) {
269 bottomConcept = CObjectAllocator<CConcept>::allocateAndConstruct(tBoxMemMan);
270 bottomConcept->initConcept();
271 bottomConcept->setConceptTag(tBox->getBottomConceptIndex());
272 bottomConcept->setOperatorCode(CCBOTTOM);
273 updateName(bottomConcept,bottomConceptString);
274 mClassTermConceptHash->insert(mBottomClassExpression,bottomConcept);
275 mConceptClassTermHash->insert(bottomConcept,mBottomClassExpression);
276 tBox->setBottomConcept(bottomConcept);
277 }
278 CConcept* indiTriggerConcept = tBox->getIndividualTriggerConcept();
279 if (!indiTriggerConcept) {
280 indiTriggerConcept = CObjectAllocator<CConcept>::allocateAndConstruct(tBoxMemMan);
281 indiTriggerConcept->initConcept();
282 indiTriggerConcept->setConceptTag(tBox->getIndividualTriggerConceptIndex());
283 indiTriggerConcept->setOperatorCode(CCIMPLTRIG);
284 tBox->setIndividualTriggerConcept(indiTriggerConcept);
285 }
286
287 CMemoryAllocationManager* rBoxMemMan = CContext::getMemoryAllocationManager(rBox->getBoxContext());
288 CRole* topObjectRole = rBox->getTopObjectRole();
289 if (!topObjectRole) {
290 topObjectRole = CObjectAllocator<CRole>::allocateAndConstruct(tBoxMemMan);
291 topObjectRole->initRole();
292 topObjectRole->setInverseRole(topObjectRole);
293 topObjectRole->setRoleTag(rBox->getTopObjectRoleIndex());
294 updateName(topObjectRole,topObjectRoleString);
295 mObjPropTermRoleHash->insert(mTopObjPropExpression,topObjectRole);
296 mRoleObjPropTermHash->insert(topObjectRole,mTopObjPropExpression);
297 rBox->setTopObjectRole(topObjectRole);
298 }
299 CRole* bottomObjectRole = rBox->getBottomObjectRole();
300 if (!bottomObjectRole) {
301 bottomObjectRole = CObjectAllocator<CRole>::allocateAndConstruct(tBoxMemMan);
302 bottomObjectRole->initRole();
303 bottomObjectRole->setInverseRole(bottomObjectRole);
304 bottomObjectRole->setRoleTag(rBox->getBottomObjectRoleIndex());
305 updateName(bottomObjectRole,bottomObjectRoleString);
306 mObjPropTermRoleHash->insert(mBottomObjPropExpression,bottomObjectRole);
307 mRoleObjPropTermHash->insert(bottomObjectRole,mBottomObjPropExpression);
308 rBox->setBottomObjectRole(bottomObjectRole);
309 }
310 CRole* topDataRole = rBox->getTopDataRole();
311 if (!topDataRole) {
312 topDataRole = CObjectAllocator<CRole>::allocateAndConstruct(tBoxMemMan);
313 topDataRole->initRole();
314 topDataRole->setDataRole(true);
315 topDataRole->setRoleTag(rBox->getTopDataRoleIndex());
316 updateName(topDataRole,topDataRoleString);
317 mDataPropTermRoleHash->insert(mTopDataPropExpression,topDataRole);
318 mRoleDataPropTermHash->insert(topDataRole,mTopDataPropExpression);
319 rBox->setTopDataRole(topDataRole);
320 }
321 CRole* bottomDataRole = rBox->getBottomDataRole();
322 if (!bottomDataRole) {
323 bottomDataRole = CObjectAllocator<CRole>::allocateAndConstruct(tBoxMemMan);
324 bottomDataRole->initRole();
325 bottomDataRole->setDataRole(true);
326 bottomDataRole->setRoleTag(rBox->getBottomDataRoleIndex());
327 updateName(bottomDataRole,bottomDataRoleString);
328 mDataPropTermRoleHash->insert(mBottomDataPropExpression,bottomDataRole);
329 mRoleDataPropTermHash->insert(bottomDataRole,mBottomDataPropExpression);
330 rBox->setBottomDataRole(bottomDataRole);
331 }
332
333
334
335 createDatatype(PREFIX_OWL_BOTTOM_DATATYPE);
336 createDatatype(PREFIX_OWL_TOP_DATATYPE);
337 createDatatype(PREFIX_OWL_REAL_DATATYPE);
338 createDatatype(PREFIX_OWL_RATIONAL_DATATYPE);
339 createDatatype(PREFIX_XML_DECIMAL_DATATYPE);
340 createDatatype(PREFIX_XML_INTEGER_DATATYPE);
341
342 createDatatype(PREFIX_XML_NONNEGATIVEINTEGER_DATATYPE);
343 createDatatype(PREFIX_XML_POSITIVEINTEGER_DATATYPE);
344 createDatatype(PREFIX_XML_NONPOSITIVEINTEGER_DATATYPE);
345 createDatatype(PREFIX_XML_NEGATIVEINTEGER_DATATYPE);
346 createDatatype(PREFIX_XML_LONG_DATATYPE);
347 createDatatype(PREFIX_XML_INT_DATATYPE);
348 createDatatype(PREFIX_XML_SHORT_DATATYPE);
349 createDatatype(PREFIX_XML_BYTE_DATATYPE);
350 createDatatype(PREFIX_XML_UNSIGNEDLONG_DATATYPE);
351 createDatatype(PREFIX_XML_UNSIGNEDINT_DATATYPE);
352 createDatatype(PREFIX_XML_UNSIGNEDSHORT_DATATYPE);
353 createDatatype(PREFIX_XML_UNSIGNEDBYTE_DATATYPE);
354
355
356 createDatatype(PREFIX_XML_PLAINLITERAL_DATATYPE);
357 createDatatype(PREFIX_XML_STRING_DATATYPE);
358 createDatatype(PREFIX_XML_NORMALIZEDSTRING_DATATYPE);
359 createDatatype(PREFIX_XML_TOKEN_DATATYPE);
360 createDatatype(PREFIX_XML_NAME_DATATYPE);
361 createDatatype(PREFIX_XML_NCNAME_DATATYPE);
362 createDatatype(PREFIX_XML_NMTOKEN_DATATYPE);
363 createDatatype(PREFIX_XML_LANGUAGE_DATATYPE);
364
365
366 createDatatype(PREFIX_XML_BOOLEAN_DATATYPE);
367
368
369 createDatatype(PREFIX_XML_DOUBLE_DATATYPE);
370 createDatatype(PREFIX_XML_FLOAT_DATATYPE);
371
372
373 createDatatype(PREFIX_XML_BINARYHEX_DATATYPE);
374 createDatatype(PREFIX_XML_BINARYBASE64_DATATYPE);
375
376
377 createDatatype(PREFIX_XML_IRI_DATATYPE);
378
379
380 createDatatype(PREFIX_XML_DATETIME_DATATYPE);
381 createDatatype(PREFIX_XML_DATETIMESTAMP_DATATYPE);
382
383
384 createDatatype(PREFIX_XML_XML_DATATYPE);
385
386
387 CDatatypeExpression* topDatatypeExpression = mDatatypeBuildHash->value(CStringRefStringHasher(PREFIX_OWL_TOP_DATATYPE));
388 mOntoBuild->setTopDataRangeExpression(topDatatypeExpression);
389
390 CDatatypeExpression* bottomDatatypeExpression = mDatatypeBuildHash->value(CStringRefStringHasher(PREFIX_OWL_BOTTOM_DATATYPE));
391 mOntoBuild->setBottomDataRangeExpression(bottomDatatypeExpression);
392
393
394 CConcept* topDataRangeConcept = tBox->getTopDataRangeConcept();
395 if (!topDataRangeConcept) {
396 topDataRangeConcept = CObjectAllocator<CConcept>::allocateAndConstruct(tBoxMemMan);
397 topDataRangeConcept->initConcept();
398 topDataRangeConcept->setConceptTag(tBox->getTopDataRangeConceptIndex());
399 topDataRangeConcept->setOperatorCode(CCIMPLTRIG);
400 mDataRangeTermConceptHash->insert(topDatatypeExpression, topDataRangeConcept);
401 mConceptDataRangeTermHash->insert(topDataRangeConcept, topDatatypeExpression);
402 tBox->setTopDataRangeConcept(topDataRangeConcept);
403 }
404
405 return true;
406 }
407
408
409 bool CConcreteOntologyBasementBuilder::completeBuilding() {
410 return true;
411 }
412
413
414
415 bool CConcreteOntologyBasementBuilder::addNameAbbreviation(const QString &name, const QString &abbreviatedName) {
416 if (!mAbbreviatedNamePrefixMapHash->contains(abbreviatedName)) {
417 CNamePrefix* namePrefix = new CNamePrefix(abbreviatedName,name);
418 mAbbreviatedNamePrefixMapHash->insert(abbreviatedName,namePrefix);
419 mNamePrefixMapHash->insert(name,namePrefix);
420 return true;
421 } else {
422 return false;
423 }
424 }
425
426
427 }; // end namespace Generator
428
429 }; // end namespace Reasoner
430
431 }; // end namespace Konclude