Debian Codegraph @

Source/Reasoner/Generator/CConcreteOntologyUpdateCollectorBuilder.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 "CConcreteOntologyUpdateCollectorBuilder.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Generator {
29
30 CConcreteOntologyUpdateCollectorBuilder::CConcreteOntologyUpdateCollectorBuilder(CConcreteOntology* updateConcreteOntology) : CConcreteOntologyBuildDataUpdater(updateConcreteOntology) {
31 LOG(NOTICE,"::Konclude::Reasoner::Generator::ConcretOntologyUpdateBuilder",logTr("ConcretOntologyUpdateBuilder initialized."),this);
32 }
33
34 CConcreteOntologyUpdateCollectorBuilder::~CConcreteOntologyUpdateCollectorBuilder() {
35 }
36
37
38
39
40
41 bool CConcreteOntologyUpdateCollectorBuilder::initializeBuilding() {
42 CConcreteOntologyBuildDataUpdater::initializeBuilding();
43
44 mTellAxiomSet = mOntoBuild->getTellAxiomSet();
45 mRetractAxiomSet = mOntoBuild->getRetractAxiomSet();
46
47 mTellUpdatedAxiomSet = mOntoBuild->getUpdatedTellAxiomSet();
48 mRetractUpdatedAxiomSet = mOntoBuild->getUpdatedRetractAxiomSet();
49
50 mChangeAxiomList = mOntoBuild->getChangeAxiomList();
51 mChangeUpdatedAxiomList = mOntoBuild->getUpdatedChangeAxiomList();
52
53 mLocTellUpdatedAxiomSet.clear();
54 mLocRetractUpdatedAxiomSet.clear();
55 mLocAddedImportOntologies.clear();
56
57 return true;
58 }
59
60
61 QSet<CAxiomExpression*>* CConcreteOntologyUpdateCollectorBuilder::getAddedAxiomSet() {
62 return &mLocTellUpdatedAxiomSet;
63 }
64
65 bool CConcreteOntologyUpdateCollectorBuilder::resetAxiomUpdates() {
66
67 mLocTellUpdatedAxiomSet.clear();
68 mLocRetractUpdatedAxiomSet.clear();
69 mLocAddedImportOntologies.clear();
70
71 return true;
72 }
73
74
75
76 bool CConcreteOntologyUpdateCollectorBuilder::completeBuilding() {
77
78 mOntoBuild->setNextAxiomNumber(mNextAxiomNumber+mNextMaxAxiomNumberOffset);
79 mOntoBuild->setNextEntityNumber(mNextEntityNumber);
80
81 FOREACHIT (CAxiomExpression* axiomExp, mLocRetractUpdatedAxiomSet) {
82 mChangeUpdatedAxiomList->append( QPair<CAxiomExpression*,bool>(axiomExp,false) );
83 mChangeAxiomList->append( QPair<CAxiomExpression*,bool>(axiomExp,false) );
84 }
85 FOREACHIT (CAxiomExpression* axiomExp, mLocTellUpdatedAxiomSet) {
86 mChangeUpdatedAxiomList->append( QPair<CAxiomExpression*,bool>(axiomExp,true) );
87 mChangeAxiomList->append( QPair<CAxiomExpression*,bool>(axiomExp,true) );
88 }
89
90
91 return true;
92 }
93
94
95
96 bool CConcreteOntologyUpdateCollectorBuilder::tellOntologyAxiom(CAxiomExpression* axiom) {
97 if (!mTellAxiomSet->contains(axiom)) {
98 mRetractAxiomSet->remove(axiom);
99 mTellAxiomSet->insert(axiom);
100 if (mLocRetractUpdatedAxiomSet.contains(axiom)) {
101 mRetractUpdatedAxiomSet->remove(axiom);
102 mLocRetractUpdatedAxiomSet.remove(axiom);
103 } else {
104 mTellUpdatedAxiomSet->insert(axiom);
105 mLocTellUpdatedAxiomSet.insert(axiom);
106 }
107 }
108 return true;
109 }
110
111 bool CConcreteOntologyUpdateCollectorBuilder::retractOntologyAxiom(CAxiomExpression* axiom) {
112 if (mTellAxiomSet->contains(axiom)) {
113 mTellAxiomSet->remove(axiom);
114 mRetractAxiomSet->insert(axiom);
115 if (mLocTellUpdatedAxiomSet.contains(axiom)) {
116 mTellUpdatedAxiomSet->remove(axiom);
117 mLocTellUpdatedAxiomSet.remove(axiom);
118 } else {
119 mRetractUpdatedAxiomSet->insert(axiom);
120 mLocRetractUpdatedAxiomSet.insert(axiom);
121 }
122 }
123 return true;
124 }
125
126
127
128 bool CConcreteOntologyUpdateCollectorBuilder::addOntologyImport(const QStringRef& name) {
129 if (CConcreteOntologyBuildDataUpdater::addOntologyImport(name)) {
130 mLocAddedImportOntologies.append(name.toString());
131 return true;
132 }
133 return false;
134 }
135
136 bool CConcreteOntologyUpdateCollectorBuilder::addOntologyImport(const QString& name) {
137 if (CConcreteOntologyBuildDataUpdater::addOntologyImport(name)) {
138 mLocAddedImportOntologies.append(name);
139 return true;
140 }
141 return false;
142 }
143
144
145 QList<QString> CConcreteOntologyUpdateCollectorBuilder::takeAddedImportOntologyList() {
146 QList<QString> tmpList(mLocAddedImportOntologies);
147 mLocAddedImportOntologies.clear();
148 return tmpList;
149 }
150
151
152 }; // end namespace Generator
153
154 }; // end namespace Reasoner
155
156 }; // end namespace Konclude