Debian Codegraph @

Source/Reasoner/Preprocess/CConceptRoleIndividualLocator.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 "CConceptRoleIndividualLocator.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Preprocess {
29
30
31 CConceptRoleIndividualLocator::CConceptRoleIndividualLocator() {
32 }
33
34
35 CConceptRoleIndividualLocator::~CConceptRoleIndividualLocator() {
36 }
37
38
39 CConcept* CConceptRoleIndividualLocator::getLocatedConcept(CConcept* concept, CConcreteOntology* ontology) {
40 CTBox* tbox = ontology->getDataBoxes()->getTBox();
41 CConceptVector* conceptVector = tbox->getConceptVector();
42 cint64 conceptTag = concept->getConceptTag();
43
44 if (!conceptVector->hasLocalData(concept->getConceptTag())) {
45 CMemoryAllocationManager* memMan = tbox->getBoxContext()->getMemoryAllocationManager();
46 CBUILDHASH<CConcept*,CClassTermExpression*>* conceptClassTermHash = ontology->getDataBoxes()->getExpressionDataBoxMapping()->getConceptClassTermMappingHash();
47
48 CConcept* prevConcept = concept;
49 concept = CObjectAllocator<CConcept>::allocateAndConstruct(memMan)->initConceptCopy(prevConcept,memMan);
50 conceptVector->setLocalData(conceptTag,concept);
51
52 CClassTermExpression* classTerm = conceptClassTermHash->value(prevConcept);
53 if (classTerm) {
54 conceptClassTermHash->insert(concept,classTerm);
55 CBUILDHASH<CClassTermExpression*,CConcept*>* classTermConceptHash = ontology->getDataBoxes()->getExpressionDataBoxMapping()->getClassTermConceptMappingHash();
56 classTermConceptHash->insert(classTerm,concept);
57 }
58 }
59 return concept;
60 }
61
62
63
64 CRole* CConceptRoleIndividualLocator::getLocatedRole(CRole* role, CConcreteOntology* ontology) {
65 CRBox* rbox = ontology->getDataBoxes()->getRBox();
66 CRoleVector* roleVector = rbox->getRoleVector();
67 cint64 roleTag = role->getRoleTag();
68
69 if (!roleVector->hasLocalData(role->getRoleTag())) {
70 CMemoryAllocationManager* memMan = rbox->getBoxContext()->getMemoryAllocationManager();
71
72 CRole *roleRef = role;
73 role = CObjectAllocator<CRole>::allocateAndConstruct(memMan)->initRoleCopy(roleRef,memMan);
74 roleVector->setData(roleTag,role);
75
76 if (!role->isDataRole()) {
77 CBUILDHASH<CRole*, CObjectPropertyTermExpression*>* roleObjectPropertyTermHash = ontology->getDataBoxes()->getExpressionDataBoxMapping()->getRoleObjectPropertyTermMappingHash();
78 CObjectPropertyTermExpression* objPropTerm = roleObjectPropertyTermHash->value(roleRef);
79 if (objPropTerm) {
80 roleObjectPropertyTermHash->insert(role, objPropTerm);
81
82 CBUILDHASH<CObjectPropertyTermExpression*, CRole*>* objectPropertyTermroleHash = ontology->getDataBoxes()->getExpressionDataBoxMapping()->getObjectPropertyTermRoleMappingHash();
83 objectPropertyTermroleHash->insert(objPropTerm, role);
84
85 }
86 } else {
87 CBUILDHASH<CRole*, CDataPropertyTermExpression*>* roleDataPropertyTermHash = ontology->getDataBoxes()->getExpressionDataBoxMapping()->getRoleDataPropertyTermMappingHash();
88 CDataPropertyTermExpression* dataPropTerm = roleDataPropertyTermHash->value(roleRef);
89 if (dataPropTerm) {
90 roleDataPropertyTermHash->insert(role, dataPropTerm);
91
92 CBUILDHASH<CDataPropertyTermExpression*, CRole*>* objectPropertyTermroleHash = ontology->getDataBoxes()->getExpressionDataBoxMapping()->getDataPropertyTermRoleMappingHash();
93 objectPropertyTermroleHash->insert(dataPropTerm, role);
94
95 }
96
97 }
98 }
99
100 return role;
101 }
102
103
104 CIndividual* CConceptRoleIndividualLocator::getLocatedIndividual(CIndividual* individual, CConcreteOntology* ontology) {
105 CABox* abox = ontology->getDataBoxes()->getABox();
106 CIndividualVector* indiVector = abox->getIndividualVector();
107 cint64 indiTag = individual->getIndividualID();
108
109 CIndividual* localIndi = indiVector->getLocalData(indiTag);
110 if (!localIndi) {
111 CMemoryAllocationManager* memMan = abox->getBoxContext()->getMemoryAllocationManager();
112 CBUILDHASH<CIndividual*,CIndividualTermExpression*>* indiIndividualTermHash = ontology->getDataBoxes()->getExpressionDataBoxMapping()->getIndiIndividulTermMappingHash();
113 CBUILDHASH<CIndividualTermExpression*,CIndividual*>* individualTermIndiHash = ontology->getDataBoxes()->getExpressionDataBoxMapping()->getIndividulTermIndiMappingHash();
114
115 localIndi = CObjectAllocator<CIndividual>::allocateAndConstruct(memMan)->initIndividualCopy(individual,memMan);
116 indiVector->setLocalData(indiTag,localIndi);
117
118 CIndividualTermExpression* indiTerm = indiIndividualTermHash->value(individual);
119 if (indiTerm) {
120 indiIndividualTermHash->insert(localIndi,indiTerm);
121 individualTermIndiHash->insert(indiTerm,localIndi);
122 }
123 }
124 return localIndi;
125 }
126
127
128
129 }; // end namespace Preprocess
130
131 }; // end namespace Reasoner
132
133 }; // end namespace Konclude