| 1 | /* This file is part of the FaCT++ DL reasoner |
| 2 | Copyright (C) 2003-2015 Dmitry Tsarkov and The University of Manchester |
| 3 | Copyright (C) 2015-2017 Dmitry Tsarkov |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU General Public License |
| 7 | as published by the Free Software Foundation; either version 2 |
| 8 | of the License, or (at your option) any later version. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with this program; if not, write to the Free Software |
| 17 | Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | |
| 20 | #include "ReasonerNom.h"cxx . . $ `<file>/Kernel/ReasonerNom.h`/ |
| 21 | |
| 22 | //----------------------------------------------------------------------------- |
| 23 | //-- internal nominal reasoning interface |
| 24 | //----------------------------------------------------------------------------- |
| 25 | |
| 26 | // register all nominals defined in TBox |
| 27 | void |
| 28 | NominalReasonercxx . . $ NominalReasoner# :: initNominalVectorcxx . . $ NominalReasoner#initNominalVector(49f6e7a06ebc5aa8). ( void ) |
| 29 | { |
| 30 | Nominalscxx . . $ NominalReasoner#Nominals..clearcxx . . $ std/vector#clear(49f6e7a06ebc5aa8).(); |
| 31 | |
| 32 | for ( TBoxcxx . . $ TBox#::i_iteratorcxx . . $ TBox#i_iterator# pi = tBoxcxx . . $ DlSatTester#tBox..i_begincxx . . $ TBox#i_begin(78b5d4d1a9fb506d).(); pi !=cxx . . $ __gnu_cxx/`operator!=`(ef3c5749062e825c). tBoxcxx . . $ DlSatTester#tBox..i_endcxx . . $ TBox#i_end(78b5d4d1a9fb506d).(); ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).pi ) |
| 33 | if ( !(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).pi)->isSynonymcxx . . $ ClassifiableEntry#isSynonym(50ce9a9e25b4a850).() ) |
| 34 | Nominalscxx . . $ NominalReasoner#Nominals..push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).pi); |
| 35 | } |
| 36 | |
| 37 | /// prepare Nominal Reasoner to a new job |
| 38 | void |
| 39 | NominalReasonercxx . . $ NominalReasoner# :: prepareReasonercxx . . $ NominalReasoner#prepareReasoner(49f6e7a06ebc5aa8). ( void ) |
| 40 | { |
| 41 | if ( LLMcxx . . $ LLM..isWritablecxx . . $ LeveLogger#isWritable(8de63fdb265b07c1).(llSRStatecxx . . $ llSRState.) ) |
| 42 | LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\nInitNominalReasoner:"; |
| 43 | |
| 44 | restorecxx . . $ DlSatTester#restore(cb2f890c2fdad230).(1); |
| 45 | |
| 46 | // check whether branching op is not a barrier... |
| 47 | if ( dynamic_cast<BCBarriercxx . . $ BCBarrier#*>(bContextcxx . . $ DlSatTester#bContext.) == nullptr ) |
| 48 | { // replace it with a barrier |
| 49 | Stackcxx . . $ DlSatTester#Stack..popcxx . . $ TSaveStack#pop(155dc7f103cdb9db).(); |
| 50 | createBCBarriercxx . . $ DlSatTester#createBCBarrier(49f6e7a06ebc5aa8).(); |
| 51 | } |
| 52 | // save the barrier (also remember the entry to be produced) |
| 53 | savecxx . . $ DlSatTester#save(49f6e7a06ebc5aa8).(); |
| 54 | // free the memory used in the pools before |
| 55 | Stackcxx . . $ DlSatTester#Stack..clearPoolscxx . . $ DlSatTester#BCStack#clearPools(49f6e7a06ebc5aa8).(); |
| 56 | |
| 57 | // clear last session information |
| 58 | resetSessionFlagscxx . . $ DlSatTester#resetSessionFlags(49f6e7a06ebc5aa8).(); |
| 59 | } |
| 60 | |
| 61 | bool |
| 62 | NominalReasonercxx . . $ NominalReasoner# :: consistentNominalCloudcxx . . $ NominalReasoner#consistentNominalCloud(c9857a73d68e59ba). ( void ) |
| 63 | { |
| 64 | if ( LLMcxx . . $ LLM..isWritablecxx . . $ LeveLogger#isWritable(8de63fdb265b07c1).(llBegSatcxx . . $ llBegSat.) ) |
| 65 | LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\n--------------------------------------------\n" |
| 66 | "Checking consistency of an ontology with individuals:"; |
| 67 | if ( LLMcxx . . $ LLM..isWritablecxx . . $ LeveLogger#isWritable(8de63fdb265b07c1).(llGTAcxx . . $ llGTA.) ) |
| 68 | LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\n"; |
| 69 | |
| 70 | bool result = false; |
| 71 | |
| 72 | // reserve the root for the forthcoming reasoning |
| 73 | if ( initNewNodecxx . . $ DlSatTester#initNewNode(96e59f80c609b310). ( CGraphcxx . . $ DlSatTester#CGraph..getRootcxx . . $ DlCompletionGraph#getRoot(8f504d760f19febe).(), DepSetcxx . . $ TDepSet#TDepSet(49f6e7a06ebc5aa8).(), bpTOPcxx . . $ bpTOP. ) || |
| 74 | initNominalCloudcxx . . $ NominalReasoner#initNominalCloud(c9857a73d68e59ba).() ) // clash during initialisation |
| 75 | result = false; |
| 76 | else // perform a normal reasoning |
| 77 | result = runSatcxx . . $ DlSatTester#runSat(c9857a73d68e59ba).(); |
| 78 | |
| 79 | if ( result && noBranchingOpscxx . . $ DlSatTester#noBranchingOps(50ce9a9e25b4a850).() ) |
| 80 | { // all nominal cloud is classified w/o branching -- make a barrier |
| 81 | if ( LLMcxx . . $ LLM..isWritablecxx . . $ LeveLogger#isWritable(8de63fdb265b07c1).(llSRStatecxx . . $ llSRState.) ) |
| 82 | LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "InitNominalReasoner["; |
| 83 | curNodecxx . . $ DlSatTester#curNode. = nullptr; |
| 84 | createBCBarriercxx . . $ DlSatTester#createBCBarrier(49f6e7a06ebc5aa8).(); |
| 85 | savecxx . . $ DlSatTester#save(49f6e7a06ebc5aa8).(); |
| 86 | nonDetShiftcxx . . $ DlSatTester#nonDetShift. = 1; // the barrier doesn't introduce branching itself |
| 87 | if ( LLMcxx . . $ LLM..isWritablecxx . . $ LeveLogger#isWritable(8de63fdb265b07c1).(llSRStatecxx . . $ llSRState.) ) |
| 88 | LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "]"; |
| 89 | } |
| 90 | |
| 91 | if ( LLMcxx . . $ LLM..isWritablecxx . . $ LeveLogger#isWritable(8de63fdb265b07c1).(llSatResultcxx . . $ llSatResult.) ) |
| 92 | LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\nThe ontology is " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). (result ? "consistent" : "INCONSISTENT"); |
| 93 | |
| 94 | if ( !result ) |
| 95 | return false; |
| 96 | |
| 97 | // ABox is consistent -> create cache for every nominal in KB |
| 98 | for ( auto& ind: Nominalscxx . . $ NominalReasoner#Nominals. ) |
| 99 | updateClassifiedSingletoncxx . . $ NominalReasoner#updateClassifiedSingleton(8c463a1a9ca3e3d3).(ind); |
| 100 | |
| 101 | if (tBoxcxx . . $ DlSatTester#tBox..precacheRelatedcxx . . $ TBox#precacheRelated.) |
| 102 | precacheRelatedcxx . . $ NominalReasoner#precacheRelated(49f6e7a06ebc5aa8).(); |
| 103 | |
| 104 | return true; |
| 105 | } |
| 106 | |
| 107 | /// create nominal nodes for all individuals in TBox |
| 108 | bool |
| 109 | NominalReasonercxx . . $ NominalReasoner# :: initNominalCloudcxx . . $ NominalReasoner#initNominalCloud(c9857a73d68e59ba). ( void ) |
| 110 | { |
| 111 | // create nominal nodes and fills them with initial values |
| 112 | for ( const auto& ind: Nominalscxx . . $ NominalReasoner#Nominals. ) |
| 113 | if ( initNominalNodecxx . . $ NominalReasoner#initNominalNode(d8fe2b44a0fc0e9f).(ind) ) |
| 114 | return true; // ABox is inconsistent |
| 115 | |
| 116 | // create edges between related nodes |
| 117 | for ( TBoxcxx . . $ TBox#::RelatedCollectioncxx . . $ TBox#RelatedCollection#::const_iteratorcxx . . $ std/vector#const_iterator# q = tBoxcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(ea0f1a22ba5f21a0)..RelatedIcxx . . $ TBox#RelatedI..begincxx . . $ std/vector#begin(33b10a496a38335b).(); q !=cxx . . $ __gnu_cxx/`operator!=`(9b2ee563b24e7156). tBoxcxx . . $ DlSatTester#tBox..RelatedIcxx . . $ TBox#RelatedI..endcxx . . $ std/vector#end(33b10a496a38335b).(); ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).q, ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).q ) |
| 118 | if ( initRelatedNominalscxx . . $ NominalReasoner#initRelatedNominals(10d4b22f0a012a34).(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).q) ) |
| 119 | return true; // ABox is inconsistent |
| 120 | |
| 121 | // create disjoint markers on nominal nodes |
| 122 | if ( tBoxcxx . . $ DlSatTester#tBox..Differentcxx . . $ TBox#Different..emptycxx . . $ std/vector#empty(50ce9a9e25b4a850).() ) |
| 123 | return false; |
| 124 | |
| 125 | DepSetcxx . . $ DepSet# dummycxx . . $ TDepSet#TDepSet(49f6e7a06ebc5aa8).; // empty dep-set for the CGraph |
| 126 | |
| 127 | for ( const auto& di: tBoxcxx . . $ DlSatTester#tBox..Differentcxx . . $ TBox#Different. ) |
| 128 | { |
| 129 | CGraphcxx . . $ DlSatTester#CGraph..initIRcxx . . $ DlCompletionGraph#initIR(49f6e7a06ebc5aa8).(); |
| 130 | for ( const auto& ind: di ) |
| 131 | if ( CGraphcxx . . $ DlSatTester#CGraph..setCurIRcxx . . $ DlCompletionGraph#setCurIR(9c3f4bbfaa7a98e6). ( resolveSynonymcxx . . $ resolveSynonym(98ea26de6545f0ca).(ind)->nodecxx . . $ TIndividual#node., dummy ) ) // different(c,c) |
| 132 | return true; |
| 133 | CGraphcxx . . $ DlSatTester#CGraph..finiIRcxx . . $ DlCompletionGraph#finiIR(49f6e7a06ebc5aa8).(); |
| 134 | } |
| 135 | |
| 136 | // init was OK |
| 137 | return false; |
| 138 | } |
| 139 | |
| 140 | bool |
| 141 | NominalReasonercxx . . $ NominalReasoner# :: initRelatedNominalscxx . . $ NominalReasoner#initRelatedNominals(10d4b22f0a012a34). ( const TRelatedcxx . . $ TRelated#* rel ) |
| 142 | { |
| 143 | DlCompletionTreecxx . . $ DlCompletionTree#* from = resolveSynonymcxx . . $ resolveSynonym(98ea26de6545f0ca).(rel->acxx . . $ TRelated#a.)->nodecxx . . $ TIndividual#node.; |
| 144 | DlCompletionTreecxx . . $ DlCompletionTree#* to = resolveSynonymcxx . . $ resolveSynonym(98ea26de6545f0ca).(rel->bcxx . . $ TRelated#b.)->nodecxx . . $ TIndividual#node.; |
| 145 | TRolecxx . . $ TRole#* R = resolveSynonymcxx . . $ resolveSynonym(98ea26de6545f0ca).(rel->Rcxx . . $ TRelated#R.); |
| 146 | DepSetcxx . . $ DepSet# depcxx . . $ TDepSet#TDepSet(49f6e7a06ebc5aa8).; // empty dep-set |
| 147 | |
| 148 | // check if merging will lead to clash because of disjoint roles |
| 149 | if ( R->isDisjointcxx . . $ TRole#isDisjoint(50ce9a9e25b4a850).() && checkDisjointRoleClashcxx . . $ DlSatTester#checkDisjointRoleClash(e9490775c569687e). ( from, to, R, dep ) ) |
| 150 | return true; |
| 151 | |
| 152 | // create new edge between FROM and TO |
| 153 | DlCompletionTreeArccxx . . $ DlCompletionTreeArc#* pA = |
| 154 | CGraphcxx . . $ DlSatTester#CGraph..addRoleLabelcxx . . $ DlCompletionGraph#addRoleLabel(2369b4bf26f5db64). ( from, to, /*isPredEdge=*/false, R, dep ); |
| 155 | |
| 156 | // return OK iff setup new edge didn't lead to clash |
| 157 | // do NOT need to re-check anything: nothing was processed yet |
| 158 | return setupEdgecxx . . $ DlSatTester#setupEdge(4031d85ce7510aa7). ( pA, dep ); |
| 159 | } |
| 160 | |
| 161 | bool NominalReasonercxx . . $ NominalReasoner#::hasIndividualscxx . . $ NominalReasoner#hasIndividuals(6c1e73ffdfd78b24).(const DlCompletionTreecxx . . $ DlCompletionTree#* node) |
| 162 | { |
| 163 | auto& label = node->labelcxx . . $ DlCompletionTree#label(fdeef9563491d77a).().getLabelcxx . . $ CGLabel#getLabel(ca01410c9270c655).(false); |
| 164 | |
| 165 | for (auto p = label.begincxx . . $ CWDArray#begin(e55d760a93e9f197).(); p !=cxx . . $ __gnu_cxx/`operator!=`(ef3c5749062e825c). label.endcxx . . $ CWDArray#end(e55d760a93e9f197).(); p++cxx . . $ __gnu_cxx/__normal_iterator#operator++(c443b773b1266d5a).) |
| 166 | { |
| 167 | auto pName = (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p).bpcxx . . $ ConceptWDep#bp(455f465bc33b4cdf).(); |
| 168 | |
| 169 | if (pName > 0 && (DLHeapcxx . . $ DlSatTester#DLHeap.[cxx . . $ DLDag#`operator[]`(e265d70853dfed20).pName].Typecxx . . $ DLVertexTagDFS#Type(d9c59f5f195b46b8).() == dtPSingletoncxx . . $ dtPSingleton. || DLHeapcxx . . $ DlSatTester#DLHeap.[cxx . . $ DLDag#`operator[]`(e265d70853dfed20).pName].Typecxx . . $ DLVertexTagDFS#Type(d9c59f5f195b46b8).() == dtNSingletoncxx . . $ dtNSingleton.)) |
| 170 | return true; |
| 171 | } |
| 172 | |
| 173 | return false; |
| 174 | } |
| 175 | |
| 176 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<TIndividualcxx . . $ TIndividual#*> NominalReasonercxx . . $ NominalReasoner#::getIndividualscxx . . $ NominalReasoner#getIndividuals(8565562e7f92868).(const DlCompletionTreecxx . . $ DlCompletionTree#* node) |
| 177 | { |
| 178 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<TIndividualcxx . . $ TIndividual#*> individualscxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 179 | |
| 180 | auto& label = node->labelcxx . . $ DlCompletionTree#label(fdeef9563491d77a).().getLabelcxx . . $ CGLabel#getLabel(ca01410c9270c655).(false); |
| 181 | |
| 182 | for (auto p = label.begincxx . . $ CWDArray#begin(e55d760a93e9f197).(); p !=cxx . . $ __gnu_cxx/`operator!=`(ef3c5749062e825c). label.endcxx . . $ CWDArray#end(e55d760a93e9f197).(); p++cxx . . $ __gnu_cxx/__normal_iterator#operator++(c443b773b1266d5a).) |
| 183 | { |
| 184 | auto pName = (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p).bpcxx . . $ ConceptWDep#bp(455f465bc33b4cdf).(); |
| 185 | |
| 186 | if (pName > 0 && (DLHeapcxx . . $ DlSatTester#DLHeap.[cxx . . $ DLDag#`operator[]`(e265d70853dfed20).pName].Typecxx . . $ DLVertexTagDFS#Type(d9c59f5f195b46b8).() == dtPSingletoncxx . . $ dtPSingleton. || DLHeapcxx . . $ DlSatTester#DLHeap.[cxx . . $ DLDag#`operator[]`(e265d70853dfed20).pName].Typecxx . . $ DLVertexTagDFS#Type(d9c59f5f195b46b8).() == dtNSingletoncxx . . $ dtNSingleton.)) |
| 187 | individuals.push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(static_cast<TIndividualcxx . . $ TIndividual#*>(DLHeapcxx . . $ DlSatTester#DLHeap.[cxx . . $ DLDag#`operator[]`(e265d70853dfed20).pName].getConceptcxx . . $ DLVertex#getConcept(f3d19eb180c44c64).())); |
| 188 | } |
| 189 | |
| 190 | return individualscxx . . $ std/vector#vector(b1ea180184b47f03).; |
| 191 | } |
| 192 | |
| 193 | void NominalReasonercxx . . $ NominalReasoner#::followTransitioncxx . . $ NominalReasoner#followTransition(a64339adbff287a2).(stdcxx . . $ std/::mapcxx . . $ std/map#<TIndividualcxx . . $ TIndividual#*, stdcxx . . $ std/::mapcxx . . $ std/map#<const TRolecxx . . $ TRole#*, stdcxx . . $ std/::setcxx . . $ std/set#<TIndividualcxx . . $ TIndividual#*>>>& role_map, const DlCompletionTreecxx . . $ DlCompletionTree#* first, const TRolecxx . . $ TRole#* role, const DlCompletionTreecxx . . $ DlCompletionTree#* current, const RoleAutomatoncxx . . $ RoleAutomaton#& automaton, RAStatecxx . . $ RAState# state, stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<const DlCompletionTreecxx . . $ DlCompletionTree#*, const DlCompletionTreecxx . . $ DlCompletionTree#*>>, stdcxx . . $ std/::mapcxx . . $ std/map#<RAStatecxx . . $ RAState#, stdcxx . . $ std/::setcxx . . $ std/set#<const DlCompletionTreecxx . . $ DlCompletionTree#*>>>& visited, stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<const DlCompletionTreecxx . . $ DlCompletionTree#*, const DlCompletionTreecxx . . $ DlCompletionTree#*>> blocker_stack) |
| 194 | { |
| 195 | // Check whether we already visited this function with this state and this node |
| 196 | // If so we won't be able to derive anything new - just return |
| 197 | |
| 198 | if (visited.countcxx . . $ std/map#count(ea780b5adf43227).(blocker_stack) == 0) |
| 199 | visited[cxx . . $ std/map#`operator[]`(bbd415b616967878).blocker_stack] =cxx . . $ std/map#`operator=`(304b443dccc1907e). stdcxx . . $ std/map#map(49f6e7a06ebc5aa8).::mapcxx . . $ std/map#<RAStatecxx . . $ RAState#, stdcxx . . $ std/::setcxx . . $ std/set#<const DlCompletionTreecxx . . $ DlCompletionTree#*>>(); |
| 200 | |
| 201 | if (visited[cxx . . $ std/map#`operator[]`(bbd415b616967878).blocker_stack].countcxx . . $ std/map#count(ea780b5adf43227).(state) == 0) |
| 202 | visited[cxx . . $ std/map#`operator[]`(bbd415b616967878).blocker_stack][cxx . . $ std/map#`operator[]`(bbd415b616967878).state] =cxx . . $ std/set#`operator=`(3c964fc90d3047d2). stdcxx . . $ std/set#set(49f6e7a06ebc5aa8).::setcxx . . $ std/set#<const DlCompletionTreecxx . . $ DlCompletionTree#*>(); |
| 203 | |
| 204 | if (visited[cxx . . $ std/map#`operator[]`(bbd415b616967878).blocker_stack][cxx . . $ std/map#`operator[]`(bbd415b616967878).state].countcxx . . $ std/set#count(a9c5b6ffd713dfa6).(current) > 0) |
| 205 | return; |
| 206 | |
| 207 | visited[cxx . . $ std/map#`operator[]`(bbd415b616967878).blocker_stack][cxx . . $ std/map#`operator[]`(bbd415b616967878).state].insertcxx . . $ std/set#insert(411a10a755068dfe).(current); |
| 208 | |
| 209 | |
| 210 | // Collect all states accessible through an empty transition from the current state |
| 211 | |
| 212 | stdcxx . . $ std/::setcxx . . $ std/set#<RAStatecxx . . $ RAState#> statescxx . . $ std/set#set(49f6e7a06ebc5aa8).; |
| 213 | states.insertcxx . . $ std/set#insert(411a10a755068dfe).(state); |
| 214 | |
| 215 | for (const RATransitioncxx . . $ RATransition#& transition : automaton[cxx . . $ RoleAutomaton#`operator[]`(49d1c2a99a57610b).state]) |
| 216 | { |
| 217 | if (transition.begincxx . . $ RATransition#begin(506035cb53656567).() ==cxx . . $ __gnu_cxx/`operator==`(ef3c5749062e825c). transition.endcxx . . $ RATransition#end(506035cb53656567).()) |
| 218 | states.insertcxx . . $ std/set#insert(10916b2dbd511ba8).(transition.finalcxx . . $ RATransition#final(ddd8539a2fcdd4ce).()); |
| 219 | } |
| 220 | |
| 221 | |
| 222 | // If the set of states contains the final state (and there are no blockers) - add a relation to the map of individual relations |
| 223 | |
| 224 | if (blocker_stack.emptycxx . . $ std/vector#empty(50ce9a9e25b4a850).() && states.countcxx . . $ std/set#count(a9c5b6ffd713dfa6).(automaton.finalcxx . . $ RoleAutomaton#final(ddd8539a2fcdd4ce).()) > 0) |
| 225 | { |
| 226 | for (TIndividualcxx . . $ TIndividual#* a : getIndividualscxx . . $ NominalReasoner#getIndividuals(8565562e7f92868).(first)) |
| 227 | { |
| 228 | for (TIndividualcxx . . $ TIndividual#* b : getIndividualscxx . . $ NominalReasoner#getIndividuals(8565562e7f92868).(current)) |
| 229 | { |
| 230 | if (role_map.countcxx . . $ std/map#count(ea780b5adf43227).(a) == 0) |
| 231 | role_map[cxx . . $ std/map#`operator[]`(bbd415b616967878).a] =cxx . . $ std/map#`operator=`(304b443dccc1907e). stdcxx . . $ std/map#map(49f6e7a06ebc5aa8).::mapcxx . . $ std/map#<const TRolecxx . . $ TRole#*, stdcxx . . $ std/::setcxx . . $ std/set#<TIndividualcxx . . $ TIndividual#*>>(); |
| 232 | |
| 233 | if (role_map[cxx . . $ std/map#`operator[]`(bbd415b616967878).a].countcxx . . $ std/map#count(ea780b5adf43227).(role) == 0) |
| 234 | role_map[cxx . . $ std/map#`operator[]`(bbd415b616967878).a][cxx . . $ std/map#`operator[]`(bbd415b616967878).role] =cxx . . $ std/set#`operator=`(3c964fc90d3047d2). stdcxx . . $ std/set#set(49f6e7a06ebc5aa8).::setcxx . . $ std/set#<TIndividualcxx . . $ TIndividual#*>(); |
| 235 | |
| 236 | role_map[cxx . . $ std/map#`operator[]`(bbd415b616967878).a][cxx . . $ std/map#`operator[]`(bbd415b616967878).role].insertcxx . . $ std/set#insert(411a10a755068dfe).(b); |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | |
| 242 | // Check the current node for possible (non-empty) transitions from the current state and follow them |
| 243 | |
| 244 | for (auto p_arc = current->begincxx . . $ DlCompletionTree#begin(d3473f034184ffc9).(); p_arc !=cxx . . $ __gnu_cxx/`operator!=`(ef3c5749062e825c). current->endcxx . . $ DlCompletionTree#end(d3473f034184ffc9).(); p_arc++cxx . . $ __gnu_cxx/__normal_iterator#operator++(c443b773b1266d5a).) |
| 245 | { |
| 246 | DlCompletionTreeArccxx . . $ DlCompletionTreeArc#* arc = *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p_arc; |
| 247 | |
| 248 | const TRolecxx . . $ TRole#* next_role = arc->getRolecxx . . $ DlCompletionTreeArc#getRole(69f26110a94b259f).(); |
| 249 | |
| 250 | if (next_role != nullptr) |
| 251 | { |
| 252 | const DlCompletionTreecxx . . $ DlCompletionTree#* next_node = arc->getArcEndcxx . . $ DlCompletionTreeArc#getArcEnd(1b0634bb62d2788b).(); |
| 253 | |
| 254 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<const DlCompletionTreecxx . . $ DlCompletionTree#*, stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<const DlCompletionTreecxx . . $ DlCompletionTree#*, const DlCompletionTreecxx . . $ DlCompletionTree#*>>>> next_nodescxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 255 | |
| 256 | if (!blocker_stack.emptycxx . . $ std/vector#empty(50ce9a9e25b4a850).() && (*cxx . . $ std/reverse_iterator#`operator*`(c076846f881f3e7e).blocker_stack.rbegincxx . . $ std/vector#rbegin(9dcc1de6a3b68785).()).firstcxx . . $ std/pair#first. == next_node) |
| 257 | { |
| 258 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<const DlCompletionTreecxx . . $ DlCompletionTree#*, const DlCompletionTreecxx . . $ DlCompletionTree#*>> smaller_blocker_stackcxx . . $ std/vector#vector(a1201200cf0efa42).(blocker_stack); |
| 259 | smaller_blocker_stack.pop_backcxx . . $ std/vector#pop_back(49f6e7a06ebc5aa8).(); |
| 260 | next_nodes.push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(stdcxx . . $ std/pair#pair(14d64bafa7379ebc).::paircxx . . $ std/pair#<const DlCompletionTreecxx . . $ DlCompletionTree#*, stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<const DlCompletionTreecxx . . $ DlCompletionTree#*, const DlCompletionTreecxx . . $ DlCompletionTree#*>>>((*cxx . . $ std/reverse_iterator#`operator*`(c076846f881f3e7e).blocker_stack.rbegincxx . . $ std/vector#rbegin(9dcc1de6a3b68785).()).secondcxx . . $ std/pair#second., smaller_blocker_stack)); |
| 261 | } |
| 262 | |
| 263 | next_nodes.push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(stdcxx . . $ std/pair#pair(14d64bafa7379ebc).::paircxx . . $ std/pair#<const DlCompletionTreecxx . . $ DlCompletionTree#*, stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<const DlCompletionTreecxx . . $ DlCompletionTree#*, const DlCompletionTreecxx . . $ DlCompletionTree#*>>>(next_node, blocker_stack)); |
| 264 | |
| 265 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<const DlCompletionTreecxx . . $ DlCompletionTree#*, const DlCompletionTreecxx . . $ DlCompletionTree#*>> bigger_blocker_stackcxx . . $ std/vector#vector(a1201200cf0efa42).(blocker_stack); |
| 266 | |
| 267 | if (next_node->getBlockercxx . . $ DlCompletionTree#getBlocker(19e040716207bced).() != nullptr && next_node->getBlockercxx . . $ DlCompletionTree#getBlocker(19e040716207bced).() != next_node) |
| 268 | { |
| 269 | auto pair = stdcxx . . $ std/pair#pair(59816e23a2f1b31c).::paircxx . . $ std/pair#<const DlCompletionTreecxx . . $ DlCompletionTree#*, const DlCompletionTreecxx . . $ DlCompletionTree#*>(next_node->getBlockercxx . . $ DlCompletionTree#getBlocker(19e040716207bced).(), next_node); |
| 270 | |
| 271 | if (stdcxx . . $ std/::findcxx . . $ std/find(a92da12e15934614).(bigger_blocker_stack.begincxx . . $ std/vector#begin(33b10a496a38335b).(), bigger_blocker_stack.endcxx . . $ std/vector#end(33b10a496a38335b).(), pair) ==cxx . . $ __gnu_cxx/`operator==`(ef3c5749062e825c). bigger_blocker_stack.endcxx . . $ std/vector#end(33b10a496a38335b).()) |
| 272 | { |
| 273 | bigger_blocker_stack.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(pair); |
| 274 | next_nodes.push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(stdcxx . . $ std/pair#pair(14d64bafa7379ebc).::paircxx . . $ std/pair#<const DlCompletionTreecxx . . $ DlCompletionTree#*, stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<const DlCompletionTreecxx . . $ DlCompletionTree#*, const DlCompletionTreecxx . . $ DlCompletionTree#*>>>(next_node->getBlockercxx . . $ DlCompletionTree#getBlocker(19e040716207bced).(), bigger_blocker_stack)); |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | for (auto& next : next_nodes) |
| 279 | { |
| 280 | const DlCompletionTreecxx . . $ DlCompletionTree#* next_node = next.firstcxx . . $ std/pair#first.; |
| 281 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<const DlCompletionTreecxx . . $ DlCompletionTree#*, const DlCompletionTreecxx . . $ DlCompletionTree#*>> next_blocker_stack = nextcxx . . $ std/vector#vector(a1201200cf0efa42)..secondcxx . . $ std/pair#second.; |
| 282 | |
| 283 | for (RAStatecxx . . $ RAState# state : states) |
| 284 | { |
| 285 | for (const RATransitioncxx . . $ RATransition#& transition : automaton[cxx . . $ RoleAutomaton#`operator[]`(49d1c2a99a57610b).state]) |
| 286 | { |
| 287 | for (RATransitioncxx . . $ RATransition#::const_iteratorcxx . . $ RATransition#const_iterator# q = transition.begincxx . . $ RATransition#begin(506035cb53656567).(); q !=cxx . . $ __gnu_cxx/`operator!=`(ef3c5749062e825c). transition.endcxx . . $ RATransition#end(506035cb53656567).(); q++cxx . . $ __gnu_cxx/__normal_iterator#operator++(c443b773b1266d5a).) |
| 288 | { |
| 289 | if (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).q == next_role) |
| 290 | followTransitioncxx . . $ NominalReasoner#followTransition(a64339adbff287a2).(role_map, first, role, next_node, automaton, transition.finalcxx . . $ RATransition#final(ddd8539a2fcdd4ce).(), visited, next_blocker_stackcxx . . $ std/vector#vector(a1201200cf0efa42).); |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | void NominalReasonercxx . . $ NominalReasoner#::precacheRelatedcxx . . $ NominalReasoner#precacheRelated(49f6e7a06ebc5aa8).() |
| 300 | { |
| 301 | auto& ORM = tBoxcxx . . $ DlSatTester#tBox..getORMcxx . . $ TBox#getORM(94330852db6e789a).(); |
| 302 | stdcxx . . $ std/::mapcxx . . $ std/map#<TIndividualcxx . . $ TIndividual#*, stdcxx . . $ std/::mapcxx . . $ std/map#<const TRolecxx . . $ TRole#*, stdcxx . . $ std/::setcxx . . $ std/set#<TIndividualcxx . . $ TIndividual#*>>> role_mapcxx . . $ std/map#map(49f6e7a06ebc5aa8).; |
| 303 | |
| 304 | |
| 305 | // Collect information of all relations going out of all individual nodes in the completion graph |
| 306 | |
| 307 | for (auto p_node = CGraphcxx . . $ DlSatTester#CGraph..begincxx . . $ DlCompletionGraph#begin(279e9fe68f310cbf).(); p_node !=cxx . . $ __gnu_cxx/`operator!=`(ef3c5749062e825c). CGraphcxx . . $ DlSatTester#CGraph..endcxx . . $ DlCompletionGraph#end(279e9fe68f310cbf).(); p_node++cxx . . $ __gnu_cxx/__normal_iterator#operator++(c443b773b1266d5a).) |
| 308 | { |
| 309 | const DlCompletionTreecxx . . $ DlCompletionTree#* node = *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p_node; |
| 310 | |
| 311 | if (hasIndividualscxx . . $ NominalReasoner#hasIndividuals(6c1e73ffdfd78b24).(node)) |
| 312 | { |
| 313 | for (RoleMastercxx . . $ RoleMaster#::iteratorcxx . . $ RoleMaster#iterator# p = ORM.begincxx . . $ RoleMaster#begin(f6b8bc1058fc1c99).(); p !=cxx . . $ __gnu_cxx/`operator!=`(ef3c5749062e825c). ORM.endcxx . . $ RoleMaster#end(f6b8bc1058fc1c99).(); p++cxx . . $ __gnu_cxx/__normal_iterator#operator++(c443b773b1266d5a).) |
| 314 | { |
| 315 | //if (std::string(getIndividuals(node)[0]->getName()) == "i0" && std::string((*p)->getName()) == "isSecondCousinOf") |
| 316 | // int a = 0; |
| 317 | |
| 318 | const RoleAutomatoncxx . . $ RoleAutomaton#& automaton = (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p)->getAutomatoncxx . . $ TRole#getAutomaton(63b0d77ccf579a4).(); |
| 319 | stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<const DlCompletionTreecxx . . $ DlCompletionTree#*, const DlCompletionTreecxx . . $ DlCompletionTree#*>>, stdcxx . . $ std/::mapcxx . . $ std/map#<RAStatecxx . . $ RAState#, stdcxx . . $ std/::setcxx . . $ std/set#<const DlCompletionTreecxx . . $ DlCompletionTree#*>>> empty_visitedcxx . . $ std/map#map(49f6e7a06ebc5aa8).; |
| 320 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<const DlCompletionTreecxx . . $ DlCompletionTree#*, const DlCompletionTreecxx . . $ DlCompletionTree#*>> empty_blocker_stackcxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 321 | followTransitioncxx . . $ NominalReasoner#followTransition(a64339adbff287a2).(role_map, node, *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p, node, automaton, automaton.initialcxx . . $ RoleAutomaton#initial(ddd8539a2fcdd4ce).(), empty_visited, empty_blocker_stackcxx . . $ std/vector#vector(a1201200cf0efa42).); |
| 322 | } |
| 323 | |
| 324 | for (auto p_neighbor = node->begincxx . . $ DlCompletionTree#begin(d3473f034184ffc9).(); p_neighbor !=cxx . . $ __gnu_cxx/`operator!=`(ef3c5749062e825c). node->endcxx . . $ DlCompletionTree#end(d3473f034184ffc9).(); p_neighbor++cxx . . $ __gnu_cxx/__normal_iterator#operator++(c443b773b1266d5a).) |
| 325 | { |
| 326 | const DlCompletionTreeArccxx . . $ DlCompletionTreeArc#* neighbor = *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p_neighbor; |
| 327 | const TRolecxx . . $ TRole#* role = neighbor->getRolecxx . . $ DlCompletionTreeArc#getRole(69f26110a94b259f).(); |
| 328 | |
| 329 | if (role != nullptr && role->isDataRolecxx . . $ TRole#isDataRole(50ce9a9e25b4a850).()) |
| 330 | { |
| 331 | for (TIndividualcxx . . $ TIndividual#* a : getIndividualscxx . . $ NominalReasoner#getIndividuals(8565562e7f92868).(node)) |
| 332 | { |
| 333 | DLVertexcxx . . $ DLVertex#& vertex = DLHeapcxx . . $ DlSatTester#DLHeap.[cxx . . $ DLDag#`operator[]`(e265d70853dfed20).neighbor->getArcEndcxx . . $ DlCompletionTreeArc#getArcEnd(1b0634bb62d2788b).()->getInitcxx . . $ DlCompletionTree#getInit(b126dc7c1de90089).()]; |
| 334 | a->addDataValueCachecxx . . $ TIndividual#addDataValueCache(4e3cfdb1d573acf4).(role, static_cast<TDataEntrycxx . . $ TDataEntry#*>(vertex.getConceptcxx . . $ DLVertex#getConcept(f3d19eb180c44c64).())); |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | |
| 342 | // Set individual cache for all collected relations |
| 343 | |
| 344 | for (auto& ind_roles : role_map) |
| 345 | { |
| 346 | TIndividualcxx . . $ TIndividual#* a = ind_roles.firstcxx . . $ std/pair#first.; |
| 347 | |
| 348 | for (auto& role_obj : ind_roles.secondcxx . . $ std/pair#second.) |
| 349 | { |
| 350 | const TRolecxx . . $ TRole#* role = role_obj.firstcxx . . $ std/pair#first.; |
| 351 | a->setRelatedCachecxx . . $ TIndividual#setRelatedCache(f6cb271f73b2b7b3).(role, stdcxx . . $ std/vector#vector(13e0640cd3842f28).::vectorcxx . . $ std/vector#<const TIndividualcxx . . $ TIndividual#*>(role_obj.secondcxx . . $ std/pair#second..begincxx . . $ std/set#begin(a1617ab40ea76896).(), role_obj.secondcxx . . $ std/pair#second..endcxx . . $ std/set#end(a1617ab40ea76896).())); |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | |
| 356 | // For the rest - either copy related from the role synonym or set up an empty cache |
| 357 | |
| 358 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<const TIndividualcxx . . $ TIndividual#*> empty_cachecxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 359 | |
| 360 | for (auto& individual : Nominalscxx . . $ NominalReasoner#Nominals.) |
| 361 | { |
| 362 | for (RoleMastercxx . . $ RoleMaster#::iteratorcxx . . $ RoleMaster#iterator# role = ORM.begincxx . . $ RoleMaster#begin(f6b8bc1058fc1c99).(); role !=cxx . . $ __gnu_cxx/`operator!=`(ef3c5749062e825c). ORM.endcxx . . $ RoleMaster#end(f6b8bc1058fc1c99).(); role++cxx . . $ __gnu_cxx/__normal_iterator#operator++(c443b773b1266d5a).) |
| 363 | { |
| 364 | if (!individual->hasRelatedCachecxx . . $ TIndividual#hasRelatedCache(81d69a9c8508a392).(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).role)) |
| 365 | { |
| 366 | TRolecxx . . $ TRole#* synonym = static_cast<TRolecxx . . $ TRole#*>((*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).role)->getSynonymcxx . . $ ClassifiableEntry#getSynonym(106bdcbfaabaf9a3).()); |
| 367 | |
| 368 | if (synonym != nullptr && individual->hasRelatedCachecxx . . $ TIndividual#hasRelatedCache(81d69a9c8508a392).(synonym)) |
| 369 | individual->setRelatedCachecxx . . $ TIndividual#setRelatedCache(f6cb271f73b2b7b3).(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).role, individual->getRelatedCachecxx . . $ TIndividual#getRelatedCache(e8cb65e6fd10a881).(synonym)); |
| 370 | else |
| 371 | individual->setRelatedCachecxx . . $ TIndividual#setRelatedCache(f6cb271f73b2b7b3).(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).role, empty_cache); |
| 372 | } |
| 373 | } |
| 374 | } |
| 375 | } |