| 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 library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | This library 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 GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with this library; if not, write to the Free Software |
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include "dlTBox.h"cxx . . $ `<file>/Kernel/dlTBox.h`/ |
| 21 | |
| 22 | #include <fstream> |
| 23 | |
| 24 | #include "cppi.h"cxx . . $ `<file>/Kernel/cppi.h`/ |
| 25 | |
| 26 | #include "globaldef.h"cxx . . $ `<file>/Kernel/globaldef.h`/ |
| 27 | #include "ReasonerNom.h"cxx . . $ `<file>/Kernel/ReasonerNom.h`/ |
| 28 | #include "DLConceptTaxonomy.h"cxx . . $ `<file>/Kernel/DLConceptTaxonomy.h`/ |
| 29 | #include "procTimer.h"cxx . . $ `<file>/Kernel/procTimer.h`/ |
| 30 | #include "dumpLisp.h"cxx . . $ `<file>/Kernel/dumpLisp.h`/ |
| 31 | #include "logging.h"cxx . . $ `<file>/Kernel/logging.h`/ |
| 32 | |
| 33 | // uncomment the following line to print currently checking subsumption |
| 34 | //#define FPP_DEBUG_PRINT_CURRENT_SUBSUMPTION |
| 35 | |
| 36 | TBoxcxx . . $ TBox# :: TBoxcxx . . $ TBox#TBox(da4a163a7cd92f4d). ( const ifOptionSetcxx . . $ ifOptionSet#* Options, const stdcxx . . $ std/::stringcxx . . $ std/string#& TopORoleName, const stdcxx . . $ std/::stringcxx . . $ std/string#& BotORoleName, const stdcxx . . $ std/::stringcxx . . $ std/string#& TopDRoleName, const stdcxx . . $ std/::stringcxx . . $ std/string#& BotDRoleName ) |
| 37 | : DLHeapcxx . . $ TBox#DLHeap.(Options) |
| 38 | , pOptionscxx . . $ TBox#pOptions. (Options) |
| 39 | , Conceptscxx . . $ TBox#Concepts.("concept"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).) |
| 40 | , Individualscxx . . $ TBox#Individuals.("individual"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).) |
| 41 | , ORMcxx . . $ TBox#ORM. ( /*data=*/false, TopORoleName, BotORoleName ) |
| 42 | , DRMcxx . . $ TBox#DRM. ( /*data=*/true, TopDRoleName, BotDRoleName ) |
| 43 | , Axiomscxx . . $ TBox#Axioms.(*this) |
| 44 | { |
| 45 | readConfigcxx . . $ TBox#readConfig(caa43d10477a9290). ( Options ); |
| 46 | initTopBottomcxx . . $ TBox#initTopBottom(49f6e7a06ebc5aa8). (); |
| 47 | |
| 48 | setForbidUndefinedNamescxx . . $ TBox#setForbidUndefinedNames(efaadfb7dc14930a).(false); |
| 49 | } |
| 50 | |
| 51 | TBoxcxx . . $ TBox# :: ~cxx . . $ TBox#`~TBox`(49f6e7a06ebc5aa8).TBoxcxx . . $ TBox#() |
| 52 | { |
| 53 | // remove all RELATED structures |
| 54 | for ( RelatedCollectioncxx . . $ TBox#RelatedCollection#::iteratorcxx . . $ std/vector#iterator# p = RelatedIcxx . . $ TBox#RelatedI..begincxx . . $ std/vector#begin(33b10a496a38335b).(), p_end = RelatedIcxx . . $ TBox#RelatedI..endcxx . . $ std/vector#end(33b10a496a38335b).(); p <cxx . . $ __gnu_cxx/`operator<`(ef3c5749062e825c). p_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).p ) |
| 55 | delete *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p; |
| 56 | |
| 57 | // remove all simple rules |
| 58 | for ( TSimpleRulescxx . . $ TBox#TSimpleRules#::iteratorcxx . . $ std/vector#iterator# q = SimpleRulescxx . . $ TBox#SimpleRules..begincxx . . $ std/vector#begin(33b10a496a38335b).(), q_end = SimpleRulescxx . . $ TBox#SimpleRules..endcxx . . $ std/vector#end(33b10a496a38335b).(); q <cxx . . $ __gnu_cxx/`operator<`(ef3c5749062e825c). q_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).q ) |
| 59 | delete *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).q; |
| 60 | |
| 61 | // empty R-C cache |
| 62 | for ( TRCCachecxx . . $ TBox#TRCCache#::iteratorcxx . . $ std/vector#iterator# r = RCCachecxx . . $ TBox#RCCache..begincxx . . $ std/vector#begin(33b10a496a38335b).(), r_end = RCCachecxx . . $ TBox#RCCache..endcxx . . $ std/vector#end(33b10a496a38335b).(); r <cxx . . $ __gnu_cxx/`operator<`(ef3c5749062e825c). r_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).r ) |
| 63 | deleteTreecxx . . $ deleteTree(c5beffd064a5e5b2).(r->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(a68f0626e749d9f6).firstcxx . . $ std/pair#first.); |
| 64 | |
| 65 | // remove all concepts |
| 66 | delete pTopcxx . . $ TBox#pTop.; |
| 67 | delete pBottomcxx . . $ TBox#pBottom.; |
| 68 | delete pTempcxx . . $ TBox#pTemp.; |
| 69 | delete pQuerycxx . . $ TBox#pQuery.; |
| 70 | |
| 71 | // remove aux structures |
| 72 | delete stdReasonercxx . . $ TBox#stdReasoner.; |
| 73 | delete nomReasonercxx . . $ TBox#nomReasoner.; |
| 74 | delete pTaxcxx . . $ TBox#pTax.; |
| 75 | delete pTaxCreatorcxx . . $ TBox#pTaxCreator.; |
| 76 | } |
| 77 | |
| 78 | /// get unique aux concept |
| 79 | TConceptcxx . . $ TConcept#* TBoxcxx . . $ TBox# :: getAuxConceptcxx . . $ TBox#getAuxConcept(9b2c8167507be48a). ( DLTreecxx . . $ DLTree#* desc ) |
| 80 | { |
| 81 | stdcxx . . $ std/::stringcxx . . $ std/string# namecxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d). {" aux"}; |
| 82 | name +=cxx . . $ std/__cxx11/basic_string#`operator+=`(c0b47be1fddc0e75). stdcxx . . $ std/::to_stringcxx . . $ std/__cxx11/to_string(8297fed3afd4179b).(++auxConceptIDcxx . . $ TBox#auxConceptID.); |
| 83 | bool old = setForbidUndefinedNamescxx . . $ TBox#setForbidUndefinedNames(efaadfb7dc14930a).(false); |
| 84 | TConceptcxx . . $ TConcept#* C = getConceptcxx . . $ TBox#getConcept(91c47a16c070dcb4).(name); |
| 85 | setForbidUndefinedNamescxx . . $ TBox#setForbidUndefinedNames(efaadfb7dc14930a).(old); |
| 86 | C->setSystemcxx . . $ TNamedEntry#setSystem(49f6e7a06ebc5aa8).(); |
| 87 | C->setNonClassifiablecxx . . $ ClassifiableEntry#setNonClassifiable(49f6e7a06ebc5aa8).(); |
| 88 | C->setPrimitivecxx . . $ TConcept#setPrimitive(49f6e7a06ebc5aa8).(); |
| 89 | C->Descriptioncxx . . $ TConcept#Description. = desc; |
| 90 | C->initToldSubsumerscxx . . $ TConcept#initToldSubsumers(49f6e7a06ebc5aa8).(); // it is created after this is done centrally |
| 91 | return C; |
| 92 | } |
| 93 | |
| 94 | /// replace (AR:C) with X such that C [= AR^-:X for fresh X. @return X |
| 95 | TConceptcxx . . $ TConcept#* |
| 96 | TBoxcxx . . $ TBox# :: replaceForallcxx . . $ TBox#replaceForall(9b2c8167507be48a). ( DLTreecxx . . $ DLTree#* RC ) |
| 97 | { |
| 98 | // check whether we already did this before for given R,C |
| 99 | TConceptcxx . . $ TConcept#* X = getRCCachecxx . . $ TBox#getRCCache(87b5a9ed25249735).(RC); |
| 100 | |
| 101 | if ( X != nullptr ) |
| 102 | { |
| 103 | deleteTreecxx . . $ deleteTree(c5beffd064a5e5b2).(RC); |
| 104 | return X; |
| 105 | } |
| 106 | |
| 107 | // see R and C at the first time |
| 108 | X = getAuxConceptcxx . . $ TBox#getAuxConcept(9b2c8167507be48a).(); |
| 109 | DLTreecxx . . $ DLTree#* C = createSNFNotcxx . . $ createSNFNot(1bf715d485c1268).(clonecxx . . $ clone(ec41a33c52a5614b).(RC->Rightcxx . . $ TsTTree#Right(f4b2f47551fb31d7).())); |
| 110 | DLTreecxx . . $ DLTree#* Forall = createSNFForallcxx . . $ createSNFForall(f2877343b7b69ea7). ( createInversecxx . . $ createInverse(1bf715d485c1268).(clonecxx . . $ clone(ec41a33c52a5614b).(RC->Leftcxx . . $ TsTTree#Left(f4b2f47551fb31d7).())), getTreecxx . . $ TBox#getTree(8f1a6b264b733ed7).(X) ); |
| 111 | #ifdef RKG_DEBUG_ABSORPTION |
| 112 | std::cout << "\nReplaceForall: add" << C << " [=" << Forall; |
| 113 | #endif |
| 114 | // create ax axiom C [= AR^-.X |
| 115 | addSubsumeAxiomcxx . . $ TBox#addSubsumeAxiom(237c04ede5740138). ( C, Forall ); |
| 116 | // save cache for R,C |
| 117 | setRCCachecxx . . $ TBox#setRCCache(c9a684c58d5a1e4b). ( RC, X ); |
| 118 | |
| 119 | return X; |
| 120 | } |
| 121 | |
| 122 | void TBoxcxx . . $ TBox# :: initTopBottomcxx . . $ TBox#initTopBottom(49f6e7a06ebc5aa8). ( void ) |
| 123 | { |
| 124 | // create BOTTOM concept |
| 125 | TConceptcxx . . $ TConcept#* p = new TConceptcxx . . $ TConcept#TConcept(9c546c94e5fcce4e). ("BOTTOM"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 126 | p->setBottomcxx . . $ TNamedEntry#setBottom(49f6e7a06ebc5aa8).(); |
| 127 | p->setIdcxx . . $ TNamedEntry#setId(d4f767463ce0a6b3).(-1); |
| 128 | p->pNamecxx . . $ TConcept#pName. = p->pBodycxx . . $ TConcept#pBody. = bpBOTTOMcxx . . $ bpBOTTOM.; |
| 129 | pBottomcxx . . $ TBox#pBottom. = p; |
| 130 | |
| 131 | // create TOP concept |
| 132 | p = new TConceptcxx . . $ TConcept#TConcept(9c546c94e5fcce4e). ("TOP"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 133 | p->setTopcxx . . $ TNamedEntry#setTop(49f6e7a06ebc5aa8).(); |
| 134 | p->setIdcxx . . $ TNamedEntry#setId(d4f767463ce0a6b3).(-1); |
| 135 | p->pNamecxx . . $ TConcept#pName. = p->pBodycxx . . $ TConcept#pBody. = bpTOPcxx . . $ bpTOP.; |
| 136 | p->tsDepthcxx . . $ TConcept#tsDepth.=1; |
| 137 | p->classTagcxx . . $ TConcept#classTag. = cttTrueCompletelyDefinedcxx . . $ cttTrueCompletelyDefined.; |
| 138 | pTopcxx . . $ TBox#pTop. = p; |
| 139 | |
| 140 | // "fresh" concept |
| 141 | p = new TConceptcxx . . $ TConcept#TConcept(9c546c94e5fcce4e). (" "cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 142 | p->setIdcxx . . $ TNamedEntry#setId(d4f767463ce0a6b3).(-1); |
| 143 | p->tsDepthcxx . . $ TConcept#tsDepth.=1; |
| 144 | p->classTagcxx . . $ TConcept#classTag. = cttTrueCompletelyDefinedcxx . . $ cttTrueCompletelyDefined.; |
| 145 | pTempcxx . . $ TBox#pTemp. = p; |
| 146 | |
| 147 | // query concept |
| 148 | p = new TConceptcxx . . $ TConcept#TConcept(9c546c94e5fcce4e).("FaCT++.default"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 149 | p->setSystemcxx . . $ TNamedEntry#setSystem(49f6e7a06ebc5aa8).(); |
| 150 | pQuerycxx . . $ TBox#pQuery. = p; |
| 151 | } |
| 152 | |
| 153 | void TBoxcxx . . $ TBox# :: prepareReasoningcxx . . $ TBox#prepareReasoning(49f6e7a06ebc5aa8). ( void ) |
| 154 | { |
| 155 | // do the preprocessing |
| 156 | Preprocesscxx . . $ TBox#Preprocess(49f6e7a06ebc5aa8).(); |
| 157 | |
| 158 | // init reasoner (if not exist) |
| 159 | initReasonercxx . . $ TBox#initReasoner(49f6e7a06ebc5aa8).(); |
| 160 | |
| 161 | // check if it is necessary to dump relevant part TBox |
| 162 | if ( dumpQuerycxx . . $ TBox#dumpQuery. ) |
| 163 | { |
| 164 | // set up relevance info |
| 165 | markAllRelevantcxx . . $ TBox#markAllRelevant(49f6e7a06ebc5aa8).(); |
| 166 | stdcxx . . $ std/::ofstreamcxx . . $ std/ofstream# ofcxx . . $ std/basic_ofstream#basic_ofstream(b8cd37071ce335df). ( "tbox" ); |
| 167 | fpp_assertcxx . . $ `Kernel/fpp_assert.h:46:10`! ( of.good() ); |
| 168 | dumpLispcxx . . $ dumpLisp# lDumpcxx . . $ dumpLisp#dumpLisp(f7f45734e6842120).(of); |
| 169 | dumpcxx . . $ TBox#dump(338ae63f5fd45b1b).(&lDump); |
| 170 | clearRelevanceInfocxx . . $ TBox#clearRelevanceInfo(49f6e7a06ebc5aa8).(); |
| 171 | } |
| 172 | |
| 173 | // init values for SAT tests -- either cache, or consistency check |
| 174 | DLHeapcxx . . $ TBox#DLHeap..setSatOrdercxx . . $ DLDag#setSatOrder(49f6e7a06ebc5aa8).(); |
| 175 | } |
| 176 | |
| 177 | /// prepare features for SAT(P), or SUB(P,Q) test |
| 178 | void TBoxcxx . . $ TBox# :: prepareFeaturescxx . . $ TBox#prepareFeatures(774c8a5cd0d40bb6). ( const TConceptcxx . . $ TConcept#* pConcept, const TConceptcxx . . $ TConcept#* qConcept ) |
| 179 | { |
| 180 | auxFeaturescxx . . $ TBox#auxFeatures. =cxx . . $ LogicFeatures#`operator=`(9c0e370cfff66a7a). GCIFeaturescxx . . $ TBox#GCIFeatures.; |
| 181 | if ( pConcept != nullptr ) |
| 182 | updateAuxFeaturescxx . . $ TBox#updateAuxFeatures(b5b90b78616ed72d).(pConcept->posFeaturescxx . . $ TConcept#posFeatures.); |
| 183 | if ( qConcept != nullptr ) |
| 184 | updateAuxFeaturescxx . . $ TBox#updateAuxFeatures(b5b90b78616ed72d).(qConcept->negFeaturescxx . . $ TConcept#negFeatures.); |
| 185 | if ( auxFeaturescxx . . $ TBox#auxFeatures..hasSingletonscxx . . $ LogicFeatures#hasSingletons(50ce9a9e25b4a850).() ) |
| 186 | updateAuxFeaturescxx . . $ TBox#updateAuxFeatures(b5b90b78616ed72d).(NCFeaturescxx . . $ TBox#NCFeatures.); |
| 187 | curFeaturecxx . . $ TBox#curFeature. = &auxFeaturescxx . . $ TBox#auxFeatures.; |
| 188 | |
| 189 | // set blocking method for the current reasoning session |
| 190 | getReasonercxx . . $ TBox#getReasoner(975d19aa5547cabb).()->setBlockingMethodcxx . . $ DlSatTester#setBlockingMethod(b0b38cda41d4ede4). ( isIRinQuerycxx . . $ TBox#isIRinQuery(50ce9a9e25b4a850).(), isNRinQuerycxx . . $ TBox#isNRinQuery(50ce9a9e25b4a850).() ); |
| 191 | } |
| 192 | |
| 193 | void |
| 194 | TBoxcxx . . $ TBox# :: buildSimpleCachecxx . . $ TBox#buildSimpleCache(49f6e7a06ebc5aa8). ( void ) |
| 195 | { |
| 196 | // set cache for BOTTOM entry |
| 197 | initConstCachecxx . . $ TBox#initConstCache(d4f767463ce0a6b3).(bpBOTTOMcxx . . $ bpBOTTOM.); |
| 198 | |
| 199 | // set all the caches for the temp concept |
| 200 | initSingletonCachecxx . . $ TBox#initSingletonCache(f6c6a24de40d17e0). ( pTempcxx . . $ TBox#pTemp., /*pos=*/true ); |
| 201 | initSingletonCachecxx . . $ TBox#initSingletonCache(f6c6a24de40d17e0). ( pTempcxx . . $ TBox#pTemp., /*pos=*/false ); |
| 202 | |
| 203 | // inapplicable if KB contains CGIs in any form |
| 204 | if ( GCIscxx . . $ TBox#GCIs..isGCIcxx . . $ TKBFlags#isGCI(50ce9a9e25b4a850).() || GCIscxx . . $ TBox#GCIs..isReflexivecxx . . $ TKBFlags#isReflexive(50ce9a9e25b4a850).() ) |
| 205 | return; |
| 206 | |
| 207 | // it is now safe to make a TOP cache |
| 208 | initConstCachecxx . . $ TBox#initConstCache(d4f767463ce0a6b3).(bpTOPcxx . . $ bpTOP.); |
| 209 | |
| 210 | for ( c_const_iteratorcxx . . $ TBox#c_const_iterator# c = c_begincxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(ea0f1a22ba5f21a0).(), cend = c_endcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(ea0f1a22ba5f21a0).(); c <cxx . . $ __gnu_cxx/`operator<`(ef3c5749062e825c). cend; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).c ) |
| 211 | if ( (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).c)->isPrimitivecxx . . $ TConcept#isPrimitive(50ce9a9e25b4a850).() ) |
| 212 | initSingletonCachecxx . . $ TBox#initSingletonCache(f6c6a24de40d17e0). ( (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).c), /*pos=*/false ); |
| 213 | |
| 214 | for ( i_const_iteratorcxx . . $ TBox#i_const_iterator# i = i_begincxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(ea0f1a22ba5f21a0).(), iend = i_endcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(ea0f1a22ba5f21a0).(); i <cxx . . $ __gnu_cxx/`operator<`(ef3c5749062e825c). iend; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).i ) |
| 215 | if ( (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).i)->isPrimitivecxx . . $ TConcept#isPrimitive(50ce9a9e25b4a850).() ) |
| 216 | initSingletonCachecxx . . $ TBox#initSingletonCache(f6c6a24de40d17e0). ( (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).i), /*pos=*/false ); |
| 217 | } |
| 218 | |
| 219 | /// check if the ontology is consistent |
| 220 | bool |
| 221 | TBoxcxx . . $ TBox# :: performConsistencyCheckcxx . . $ TBox#performConsistencyCheck(c9857a73d68e59ba). ( void ) |
| 222 | { |
| 223 | if ( verboseOutputcxx . . $ TBox#verboseOutput. ) |
| 224 | stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Consistency checking..."; |
| 225 | TsProcTimercxx . . $ TsProcTimer# pt; |
| 226 | pt.Startcxx . . $ TsProcTimer#Start(49f6e7a06ebc5aa8).(); |
| 227 | |
| 228 | buildSimpleCachecxx . . $ TBox#buildSimpleCache(49f6e7a06ebc5aa8).(); |
| 229 | |
| 230 | TConceptcxx . . $ TConcept#* test = ( NCFeaturescxx . . $ TBox#NCFeatures..hasSingletonscxx . . $ LogicFeatures#hasSingletons(50ce9a9e25b4a850).() ? *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).i_begincxx . . $ TBox#i_begin(78b5d4d1a9fb506d).() : nullptr ); |
| 231 | prepareFeaturescxx . . $ TBox#prepareFeatures(774c8a5cd0d40bb6). ( test, nullptr ); |
| 232 | // DlSatTester* Reasoner = getReasoner(); |
| 233 | bool ret = false; |
| 234 | |
| 235 | if ( test ) |
| 236 | { |
| 237 | // make a cache for TOP if it is not there |
| 238 | if ( DLHeapcxx . . $ TBox#DLHeap..getCachecxx . . $ DLDag#getCache(a400da756ae1652b).(bpTOPcxx . . $ bpTOP.) == nullptr ) |
| 239 | initConstCachecxx . . $ TBox#initConstCache(d4f767463ce0a6b3).(bpTOPcxx . . $ bpTOP.); |
| 240 | |
| 241 | ret = static_cast<NominalReasonercxx . . $ NominalReasoner#*>(nomReasonercxx . . $ TBox#nomReasoner.)->consistentNominalCloudcxx . . $ NominalReasoner#consistentNominalCloud(c9857a73d68e59ba).(); |
| 242 | } |
| 243 | else |
| 244 | ret = isSatisfiablecxx . . $ TBox#isSatisfiable(15d44b555a30180e).(pTopcxx . . $ TBox#pTop.); |
| 245 | |
| 246 | // setup cache for GCI |
| 247 | if ( GCIscxx . . $ TBox#GCIs..isGCIcxx . . $ TKBFlags#isGCI(50ce9a9e25b4a850).() ) |
| 248 | { |
| 249 | // there is no much win to have it together with special-domains-as-GCIs ATM. |
| 250 | // DLHeap.setCache ( T_G, Reasoner->buildCacheByCGraph(ret) ); |
| 251 | DLHeapcxx . . $ TBox#DLHeap..setCachecxx . . $ DLDag#setCache(5d5e965ff81adf26). ( inversecxx . . $ inverse(7864480464b09eea).(T_Gcxx . . $ TBox#T_G.), new modelCacheConstcxx . . $ modelCacheConst#(/*sat=*/false) ); |
| 252 | } |
| 253 | |
| 254 | pt.Stopcxx . . $ TsProcTimer#Stop(49f6e7a06ebc5aa8).(); |
| 255 | consistTimecxx . . $ TBox#consistTime. = pt; |
| 256 | if ( verboseOutputcxx . . $ TBox#verboseOutput. ) |
| 257 | stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " done in " <<cxx . . $ std/basic_ostream#`operator<<`(2b73cd0f0517cf77). pt <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " seconds\n"; |
| 258 | |
| 259 | return ret; |
| 260 | } |
| 261 | |
| 262 | bool |
| 263 | TBoxcxx . . $ TBox# :: isSatisfiablecxx . . $ TBox#isSatisfiable(15d44b555a30180e). ( const TConceptcxx . . $ TConcept#* pConcept ) |
| 264 | { |
| 265 | fpp_assertcxx . . $ `Kernel/fpp_assert.h:46:10`! ( pConcept != nullptr ); |
| 266 | |
| 267 | // check whether we already does the test |
| 268 | const modelCacheInterfacecxx . . $ modelCacheInterface#* cache = DLHeapcxx . . $ TBox#DLHeap..getCachecxx . . $ DLDag#getCache(a400da756ae1652b).(pConcept->pNamecxx . . $ TConcept#pName.); |
| 269 | if ( cache != nullptr ) |
| 270 | return ( cache->getStatecxx . . $ modelCacheInterface#getState(2c070a27c5715e50).() != csInvalidcxx . . $ csInvalid. ); |
| 271 | |
| 272 | // logging the startpoint |
| 273 | if ( LLMcxx . . $ LLM..isWritablecxx . . $ LeveLogger#isWritable(8de63fdb265b07c1).(llBegSatcxx . . $ llBegSat.) ) |
| 274 | LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\n--------------------------------------------\n" |
| 275 | "Checking satisfiability of '" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). pConcept->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "':"; |
| 276 | if ( LLMcxx . . $ LLM..isWritablecxx . . $ LeveLogger#isWritable(8de63fdb265b07c1).(llGTAcxx . . $ llGTA.) ) |
| 277 | LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\n"; |
| 278 | |
| 279 | // perform reasoning with a proper logical features |
| 280 | prepareFeaturescxx . . $ TBox#prepareFeatures(774c8a5cd0d40bb6). ( pConcept, nullptr ); |
| 281 | bool result = getReasonercxx . . $ TBox#getReasoner(975d19aa5547cabb).()->runSatcxx . . $ DlSatTester#runSat(cf9ef193275fa6d8). ( pConcept->resolveIdcxx . . $ TConcept#resolveId(455f465bc33b4cdf).(), bpTOPcxx . . $ bpTOP. ); |
| 282 | // save cache |
| 283 | DLHeapcxx . . $ TBox#DLHeap..setCachecxx . . $ DLDag#setCache(5d5e965ff81adf26). ( pConcept->pNamecxx . . $ TConcept#pName., getReasonercxx . . $ TBox#getReasoner(975d19aa5547cabb).()->buildCacheByCGraphcxx . . $ DlSatTester#buildCacheByCGraph(b0360ae62ba10694).(result) ); |
| 284 | clearFeaturescxx . . $ TBox#clearFeatures(49f6e7a06ebc5aa8).(); |
| 285 | |
| 286 | CHECK_LL_RETURN_VALUEcxx . . $ `Kernel/LeveLogger.h:64:9`!(llSatResult,result); |
| 287 | |
| 288 | #if 1 |
| 289 | LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\n"; // usual checking -- time is extra info |
| 290 | #else |
| 291 | LL << " "; // time tests -- time is necessary info |
| 292 | #endif |
| 293 | |
| 294 | LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "The '" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). pConcept->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "' concept is "; |
| 295 | if ( !result ) |
| 296 | LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "un"; |
| 297 | LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "satisfiable w.r.t. TBox"; |
| 298 | |
| 299 | return result; |
| 300 | } |
| 301 | |
| 302 | bool |
| 303 | TBoxcxx . . $ TBox# :: isSubHoldscxx . . $ TBox#isSubHolds(7e9f35c32394b4f5). ( const TConceptcxx . . $ TConcept#* pConcept, const TConceptcxx . . $ TConcept#* qConcept ) |
| 304 | { |
| 305 | fpp_assertcxx . . $ `Kernel/fpp_assert.h:46:10`! ( pConcept != nullptr && qConcept != nullptr ); |
| 306 | |
| 307 | #ifdef FPP_DEBUG_PRINT_CURRENT_SUBSUMPTION |
| 308 | std::cerr << "Checking '" << pConcept->getName() << "' [= '" << qConcept->getName() << "'..."; |
| 309 | #endif |
| 310 | |
| 311 | // logging the startpoint |
| 312 | if ( LLMcxx . . $ LLM..isWritablecxx . . $ LeveLogger#isWritable(8de63fdb265b07c1).(llBegSatcxx . . $ llBegSat.) ) |
| 313 | LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\n--------------------------------------------\nChecking subsumption '" |
| 314 | <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). pConcept->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " [= " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). qConcept->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "':"; |
| 315 | if ( LLMcxx . . $ LLM..isWritablecxx . . $ LeveLogger#isWritable(8de63fdb265b07c1).(llGTAcxx . . $ llGTA.) ) |
| 316 | LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\n"; |
| 317 | |
| 318 | // perform reasoning with a proper logical features |
| 319 | prepareFeaturescxx . . $ TBox#prepareFeatures(774c8a5cd0d40bb6). ( pConcept, qConcept ); |
| 320 | bool result = !getReasonercxx . . $ TBox#getReasoner(975d19aa5547cabb).()->runSatcxx . . $ DlSatTester#runSat(cf9ef193275fa6d8). ( pConcept->resolveIdcxx . . $ TConcept#resolveId(455f465bc33b4cdf).(), inversecxx . . $ inverse(7864480464b09eea).(qConcept->resolveIdcxx . . $ TConcept#resolveId(455f465bc33b4cdf).()) ); |
| 321 | clearFeaturescxx . . $ TBox#clearFeatures(49f6e7a06ebc5aa8).(); |
| 322 | |
| 323 | #ifdef FPP_DEBUG_PRINT_CURRENT_SUBSUMPTION |
| 324 | std::cerr << " done\n"; |
| 325 | #endif |
| 326 | |
| 327 | CHECK_LL_RETURN_VALUEcxx . . $ `Kernel/LeveLogger.h:64:9`!(llSatResult,result); |
| 328 | |
| 329 | #if 1 |
| 330 | LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\n"; // usual checking -- time is extra info |
| 331 | #else |
| 332 | LL << " "; // time tests -- time is necessary info |
| 333 | #endif |
| 334 | |
| 335 | LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "The '" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). pConcept->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " [= " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). qConcept->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "' subsumption"; |
| 336 | if (!result) |
| 337 | LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " NOT"; |
| 338 | LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " holds w.r.t. TBox"; |
| 339 | |
| 340 | return result; |
| 341 | } |
| 342 | |
| 343 | /// check that 2 individuals are the same |
| 344 | bool TBoxcxx . . $ TBox# :: isSameIndividualscxx . . $ TBox#isSameIndividuals(3993f6531b750ef8). ( const TIndividualcxx . . $ TIndividual#* a, const TIndividualcxx . . $ TIndividual#* b ) |
| 345 | { |
| 346 | a = resolveSynonymcxx . . $ resolveSynonym(bd9f52c6ae4be57a).(a); |
| 347 | b = resolveSynonymcxx . . $ resolveSynonym(bd9f52c6ae4be57a).(b); |
| 348 | if ( a == b ) // known synonyms |
| 349 | return true; |
| 350 | if ( !isIndividualcxx . . $ TBox#isIndividual(d8a4b25e330b0b26).(a) || !isIndividualcxx . . $ TBox#isIndividual(d8a4b25e330b0b26).(b) ) |
| 351 | throw EFaCTPlusPluscxx . . $ EFaCTPlusPlus#("Individuals are expected in the isSameIndividuals() query"); |
| 352 | if ( a->nodecxx . . $ TIndividual#node. == nullptr || b->nodecxx . . $ TIndividual#node. == nullptr ) // fresh individuals couldn't be the same |
| 353 | return false; |
| 354 | return a->getTaxVertexcxx . . $ ClassifiableEntry#getTaxVertex(16f9ca5fa66f7d36).() == b->getTaxVertexcxx . . $ ClassifiableEntry#getTaxVertex(16f9ca5fa66f7d36).(); |
| 355 | } |
| 356 | |
| 357 | /// check if 2 roles are disjoint |
| 358 | bool |
| 359 | TBoxcxx . . $ TBox# :: isDisjointRolescxx . . $ TBox#isDisjointRoles(ee962dbb2fa027b9). ( const TRolecxx . . $ TRole#* R, const TRolecxx . . $ TRole#* S ) |
| 360 | { |
| 361 | fpp_assertcxx . . $ `Kernel/fpp_assert.h:46:10`! ( R != nullptr && S != nullptr ); |
| 362 | |
| 363 | // object roles are disjoint with data roles |
| 364 | if ( R->isDataRolecxx . . $ TRole#isDataRole(50ce9a9e25b4a850).() != S->isDataRolecxx . . $ TRole#isDataRole(50ce9a9e25b4a850).() ) |
| 365 | return true; |
| 366 | // prepare feature that are KB features |
| 367 | // FIXME!! overkill, but fine for now as it is sound |
| 368 | curFeaturecxx . . $ TBox#curFeature. = &KBFeaturescxx . . $ TBox#KBFeatures.; |
| 369 | getReasonercxx . . $ TBox#getReasoner(975d19aa5547cabb).()->setBlockingMethodcxx . . $ DlSatTester#setBlockingMethod(b0b38cda41d4ede4). ( isIRinQuerycxx . . $ TBox#isIRinQuery(50ce9a9e25b4a850).(), isNRinQuerycxx . . $ TBox#isNRinQuery(50ce9a9e25b4a850).() ); |
| 370 | bool result = getReasonercxx . . $ TBox#getReasoner(975d19aa5547cabb).()->checkDisjointRolescxx . . $ DlSatTester#checkDisjointRoles(ee962dbb2fa027b9). ( R, S ); |
| 371 | clearFeaturescxx . . $ TBox#clearFeatures(49f6e7a06ebc5aa8).(); |
| 372 | return result; |
| 373 | } |
| 374 | |
| 375 | /// check if the role R is irreflexive |
| 376 | bool |
| 377 | TBoxcxx . . $ TBox# :: isIrreflexivecxx . . $ TBox#isIrreflexive(f4c3e7633be50e77). ( const TRolecxx . . $ TRole#* R ) |
| 378 | { |
| 379 | fpp_assertcxx . . $ `Kernel/fpp_assert.h:46:10`! ( R != nullptr ); |
| 380 | |
| 381 | // data roles are irreflexive |
| 382 | if ( R->isDataRolecxx . . $ TRole#isDataRole(50ce9a9e25b4a850).() ) |
| 383 | return true; |
| 384 | // prepare feature that are KB features |
| 385 | // FIXME!! overkill, but fine for now as it is sound |
| 386 | curFeaturecxx . . $ TBox#curFeature. = &KBFeaturescxx . . $ TBox#KBFeatures.; |
| 387 | getReasonercxx . . $ TBox#getReasoner(975d19aa5547cabb).()->setBlockingMethodcxx . . $ DlSatTester#setBlockingMethod(b0b38cda41d4ede4). ( isIRinQuerycxx . . $ TBox#isIRinQuery(50ce9a9e25b4a850).(), isNRinQuerycxx . . $ TBox#isNRinQuery(50ce9a9e25b4a850).() ); |
| 388 | bool result = getReasonercxx . . $ TBox#getReasoner(975d19aa5547cabb).()->checkIrreflexivitycxx . . $ DlSatTester#checkIrreflexivity(f4c3e7633be50e77).(R); |
| 389 | clearFeaturescxx . . $ TBox#clearFeatures(49f6e7a06ebc5aa8).(); |
| 390 | return result; |
| 391 | } |
| 392 | |
| 393 | // load init values from config file |
| 394 | void TBoxcxx . . $ TBox# :: readConfigcxx . . $ TBox#readConfig(caa43d10477a9290). ( const ifOptionSetcxx . . $ ifOptionSet#* Options ) |
| 395 | { |
| 396 | fpp_assertcxx . . $ `Kernel/fpp_assert.h:46:10`! ( Options != nullptr ); // safety check |
| 397 | |
| 398 | // define a macro for registering boolean option |
| 399 | # define addBoolOptioncxx . . $ `Kernel/dlTBox.cpp:399:10`!(name) \ |
| 400 | name = Options->getBool ( #name ); \ |
| 401 | if ( LLM.isWritable(llAlways) ) \ |
| 402 | LL << "Init " #name " = " << name << "\n" |
| 403 | |
| 404 | // TBox options |
| 405 | addBoolOptioncxx . . $ `Kernel/dlTBox.cpp:399:10`!(useCompletelyDefined); |
| 406 | addBoolOptioncxx . . $ `Kernel/dlTBox.cpp:399:10`!(dumpQuery); |
| 407 | addBoolOptioncxx . . $ `Kernel/dlTBox.cpp:399:10`!(alwaysPreferEquals); |
| 408 | addBoolOptioncxx . . $ `Kernel/dlTBox.cpp:399:10`!(useSpecialDomains); |
| 409 | // reasoner's options |
| 410 | addBoolOptioncxx . . $ `Kernel/dlTBox.cpp:399:10`!(useSemanticBranching); |
| 411 | addBoolOptioncxx . . $ `Kernel/dlTBox.cpp:399:10`!(useBackjumping); |
| 412 | addBoolOptioncxx . . $ `Kernel/dlTBox.cpp:399:10`!(useLazyBlocking); |
| 413 | addBoolOptioncxx . . $ `Kernel/dlTBox.cpp:399:10`!(useAnywhereBlocking); |
| 414 | addBoolOptioncxx . . $ `Kernel/dlTBox.cpp:399:10`!(precacheRelated); |
| 415 | |
| 416 | if ( Axiomscxx . . $ TBox#Axioms..initAbsorptionFlagscxx . . $ TAxiomSet#initAbsorptionFlags(7c222eea44a24d43).(Options->getTextcxx . . $ ifOptionSet#getText(d33e27454d79bb74).("absorptionFlags"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).)) ) |
| 417 | throw EFaCTPlusPluscxx . . $ EFaCTPlusPlus# ( "Incorrect absorption flags given" ); |
| 418 | |
| 419 | testTimeoutcxx . . $ TBox#testTimeout. = (unsigned)Options->getIntcxx . . $ ifOptionSet#getInt(22cc3a531165f6b0).("testTimeout"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 420 | if ( LLMcxx . . $ LLM..isWritablecxx . . $ LeveLogger#isWritable(8de63fdb265b07c1).(llAlwayscxx . . $ llAlways.) ) |
| 421 | LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Init testTimeout = " <<cxx . . $ std/basic_ostream#`operator<<`(b09cd8ec4365c7ed). testTimeoutcxx . . $ TBox#testTimeout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\n"; |
| 422 | |
| 423 | PriorityMatrixcxx . . $ TBox#PriorityMatrix..initPrioritiescxx . . $ ToDoPriorMatrix#initPriorities(32373b8560f77290). ( Options->getTextcxx . . $ ifOptionSet#getText(d33e27454d79bb74).("IAOEFLG"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).), "IAOEFLG" ); |
| 424 | |
| 425 | if ( RKG_USE_FAIRNESScxx . . $ `Kernel/globaldef.h:65:10`! ) |
| 426 | { |
| 427 | nSkipBeforeBlockcxx . . $ TBox#nSkipBeforeBlock. = Options->getIntcxx . . $ ifOptionSet#getInt(22cc3a531165f6b0).("skipBeforeBlock"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 428 | if ( LLMcxx . . $ LLM..isWritablecxx . . $ LeveLogger#isWritable(8de63fdb265b07c1).(llAlwayscxx . . $ llAlways.) ) |
| 429 | LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Init nSkipBeforeBlock = " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). nSkipBeforeBlockcxx . . $ TBox#nSkipBeforeBlock. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\n"; |
| 430 | } |
| 431 | else |
| 432 | nSkipBeforeBlockcxx . . $ TBox#nSkipBeforeBlock. = 0; |
| 433 | |
| 434 | verboseOutputcxx . . $ TBox#verboseOutput. = false; |
| 435 | #undef addBoolOptioncxx . . $ `Kernel/dlTBox.cpp:399:10`! |
| 436 | } |
| 437 | |
| 438 | /// create (and DAG-ify) query concept via its definition |
| 439 | TConceptcxx . . $ TConcept#* |
| 440 | TBoxcxx . . $ TBox# :: createQueryConceptcxx . . $ TBox#createQueryConcept(a9db10ac0cf504ba). ( const DLTreecxx . . $ DLTree#* desc ) |
| 441 | { |
| 442 | fpp_assertcxx . . $ `Kernel/fpp_assert.h:46:10`! ( desc != nullptr ); |
| 443 | |
| 444 | // make sure that an old query is gone |
| 445 | clearQueryConceptcxx . . $ TBox#clearQueryConcept(49f6e7a06ebc5aa8).(); |
| 446 | // create description |
| 447 | // std::cerr << "Create new temp concept with description =" << desc << "\n"; |
| 448 | deleteTreecxx . . $ deleteTree(c5beffd064a5e5b2). ( makeNonPrimitivecxx . . $ TBox#makeNonPrimitive(1e45738bba157392). ( pQuerycxx . . $ TBox#pQuery., clonecxx . . $ clone(ec41a33c52a5614b).(desc) ) ); |
| 449 | pQuerycxx . . $ TBox#pQuery.->setIndexcxx . . $ ClassifiableEntry#setIndex(cb2f890c2fdad230).(nCcxx . . $ TBox#nC.-1); |
| 450 | |
| 451 | return pQuerycxx . . $ TBox#pQuery.; |
| 452 | } |
| 453 | |
| 454 | /// preprocess query concept: put description into DAG |
| 455 | void |
| 456 | TBoxcxx . . $ TBox# :: preprocessQueryConceptcxx . . $ TBox#preprocessQueryConcept(3f0281ca3ae282d4). ( TConceptcxx . . $ TConcept#* query ) |
| 457 | { |
| 458 | // build DAG entries for the default concept |
| 459 | addConceptToHeapcxx . . $ TBox#addConceptToHeap(3f0281ca3ae282d4).(query); |
| 460 | |
| 461 | // gather statistics about the concept |
| 462 | setConceptRelevantcxx . . $ TBox#setConceptRelevant(3f0281ca3ae282d4).(query); |
| 463 | |
| 464 | // DEBUG_ONLY: print the DAG info |
| 465 | // std::ofstream debugPrint ( defConceptName, std::ios::app|std::ios::out ); |
| 466 | // Print (debugPrint); |
| 467 | // debugPrint << std::endl; |
| 468 | |
| 469 | // check satisfiability of the concept |
| 470 | initCachecxx . . $ TBox#initCache(6e2e6147ec169214).(query); |
| 471 | } |
| 472 | |
| 473 | /// classify query concept |
| 474 | void |
| 475 | TBoxcxx . . $ TBox# :: classifyQueryConceptcxx . . $ TBox#classifyQueryConcept(49f6e7a06ebc5aa8). ( void ) |
| 476 | { |
| 477 | // prepare told subsumers for classification; as it is non-primitive, it is not CD |
| 478 | pQuerycxx . . $ TBox#pQuery.->initToldSubsumerscxx . . $ TConcept#initToldSubsumers(49f6e7a06ebc5aa8).(); |
| 479 | |
| 480 | // setup taxonomy behaviour flags |
| 481 | fpp_assertcxx . . $ `Kernel/fpp_assert.h:46:10`! ( pTax != nullptr ); |
| 482 | pTaxCreatorcxx . . $ TBox#pTaxCreator.->setCompletelyDefinedcxx . . $ TaxonomyCreator#setCompletelyDefined(b45ddcbc8423892c).(false); // non-primitive concept |
| 483 | // printf("qz 3\n"); |
| 484 | |
| 485 | // classify the concept |
| 486 | pTaxCreatorcxx . . $ TBox#pTaxCreator.->classifyEntrycxx . . $ TaxonomyCreator#classifyEntry(866fbb357e35bef0).(pQuerycxx . . $ TBox#pQuery.); |
| 487 | // printf("qz 4\n"); |
| 488 | } |
| 489 | |
| 490 | /// knowledge exploration: build a model and return a link to the root |
| 491 | const DlCompletionTreecxx . . $ DlCompletionTree#* |
| 492 | TBoxcxx . . $ TBox# :: buildCompletionTreecxx . . $ TBox#buildCompletionTree(a413042f62b2ffcc). ( const TConceptcxx . . $ TConcept#* pConcept ) |
| 493 | { |
| 494 | const DlCompletionTreecxx . . $ DlCompletionTree#* ret = nullptr; |
| 495 | // perform reasoning with a proper logical features |
| 496 | prepareFeaturescxx . . $ TBox#prepareFeatures(774c8a5cd0d40bb6). ( pConcept, nullptr ); |
| 497 | // turn off caching of CT nodes during reasoning |
| 498 | setUseNodeCachecxx . . $ TBox#setUseNodeCache(b45ddcbc8423892c).(false); |
| 499 | // do the SAT test, save the CT if satisfiable |
| 500 | if ( getReasonercxx . . $ TBox#getReasoner(975d19aa5547cabb).()->runSatcxx . . $ DlSatTester#runSat(cf9ef193275fa6d8). ( pConcept->resolveIdcxx . . $ TConcept#resolveId(455f465bc33b4cdf).() ) ) |
| 501 | ret = getReasonercxx . . $ TBox#getReasoner(975d19aa5547cabb).()->getRootNodecxx . . $ DlSatTester#getRootNode(19e040716207bced).(); |
| 502 | // turn on caching of CT nodes during reasoning |
| 503 | setUseNodeCachecxx . . $ TBox#setUseNodeCache(b45ddcbc8423892c).(true); |
| 504 | clearFeaturescxx . . $ TBox#clearFeatures(49f6e7a06ebc5aa8).(); |
| 505 | return ret; |
| 506 | } |
| 507 | |
| 508 | /// dump QUERY processing time, reasoning statistics and a (preprocessed) TBox |
| 509 | void |
| 510 | TBoxcxx . . $ TBox# :: writeReasoningResultcxx . . $ TBox#writeReasoningResult(2d0f4d08371733d). ( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& o, float time ) const |
| 511 | { |
| 512 | if ( nomReasonercxx . . $ TBox#nomReasoner. ) |
| 513 | { |
| 514 | o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Query processing reasoning statistic: Nominals"; |
| 515 | nomReasonercxx . . $ TBox#nomReasoner.->writeTotalStatisticcxx . . $ DlSatTester#writeTotalStatistic(f7f45734e6842120).(o); |
| 516 | } |
| 517 | o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Query processing reasoning statistic: Standard"; |
| 518 | stdReasonercxx . . $ TBox#stdReasoner.->writeTotalStatisticcxx . . $ DlSatTester#writeTotalStatistic(f7f45734e6842120).(o); |
| 519 | |
| 520 | // we know here whether KB is consistent |
| 521 | fpp_assertcxx . . $ `Kernel/fpp_assert.h:46:10`! ( getStatus() >= kbCChecked ); |
| 522 | if ( Consistentcxx . . $ TBox#Consistent. ) |
| 523 | o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Required"; |
| 524 | else |
| 525 | o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "KB is inconsistent. Query is NOT processed\nConsistency"; |
| 526 | |
| 527 | float sum = preprocTimecxx . . $ TBox#preprocTime. + consistTimecxx . . $ TBox#consistTime.; |
| 528 | o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " check done in " <<cxx . . $ std/basic_ostream#`operator<<`(2b73cd0f0517cf77). time <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " seconds\nof which:\nPreproc. takes " |
| 529 | <<cxx . . $ std/basic_ostream#`operator<<`(2b73cd0f0517cf77). preprocTimecxx . . $ TBox#preprocTime. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " seconds\nConsist. takes " <<cxx . . $ std/basic_ostream#`operator<<`(2b73cd0f0517cf77). consistTimecxx . . $ TBox#consistTime. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " seconds"; |
| 530 | |
| 531 | if ( nomReasonercxx . . $ TBox#nomReasoner. ) |
| 532 | { |
| 533 | o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\nReasoning NOM:"; |
| 534 | sum += nomReasonercxx . . $ TBox#nomReasoner.->printReasoningTimecxx . . $ DlSatTester#printReasoningTime(aa6fa99658f404e2).(o); |
| 535 | } |
| 536 | o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\nReasoning STD:"; |
| 537 | sum += stdReasonercxx . . $ TBox#stdReasoner.->printReasoningTimecxx . . $ DlSatTester#printReasoningTime(aa6fa99658f404e2).(o); |
| 538 | |
| 539 | o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\nThe rest takes "; |
| 540 | // determine and normalize the rest |
| 541 | float f = time - sum; |
| 542 | if ( f < 0 ) |
| 543 | f = 0; |
| 544 | f = ((unsigned long)(f*100))/100.f; |
| 545 | o <<cxx . . $ std/basic_ostream#`operator<<`(2b73cd0f0517cf77). f <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " seconds\n"; |
| 546 | Printcxx . . $ TBox#Print(490063bd7e6d8d5d).(o); |
| 547 | } |
| 548 | |
| 549 | void TBoxcxx . . $ TBox# :: PrintDagEntrycxx . . $ TBox#PrintDagEntry(94fe421b246ddbdb). ( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& o, BipolarPointercxx . . $ BipolarPointer# p ) const |
| 550 | { |
| 551 | fpp_assertcxx . . $ `Kernel/fpp_assert.h:46:10`! ( isValid (p) ); |
| 552 | |
| 553 | // primitive ones -- check first |
| 554 | if ( p == bpTOPcxx . . $ bpTOP. ) |
| 555 | { |
| 556 | o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " *TOP*"; |
| 557 | return; |
| 558 | } |
| 559 | else if ( p == bpBOTTOMcxx . . $ bpBOTTOM. ) |
| 560 | { |
| 561 | o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " *BOTTOM*"; |
| 562 | return; |
| 563 | } |
| 564 | |
| 565 | // checks inversion |
| 566 | if ( isNegativecxx . . $ isNegative(83c267b20bac841a).(p) ) |
| 567 | { |
| 568 | o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " (not"; |
| 569 | PrintDagEntrycxx . . $ TBox#PrintDagEntry(94fe421b246ddbdb). ( o, inversecxx . . $ inverse(7864480464b09eea).(p) ); |
| 570 | o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ")"; |
| 571 | return; |
| 572 | } |
| 573 | |
| 574 | const DLVertexcxx . . $ DLVertex#& v = DLHeapcxx . . $ TBox#DLHeap.[cxx . . $ DLDag#`operator[]`(5fe3b8e96045ba2c).p]; |
| 575 | |
| 576 | switch ( v.Typecxx . . $ DLVertexTagDFS#Type(d9c59f5f195b46b8).() ) |
| 577 | { |
| 578 | case dtTopcxx . . $ dtTop.: |
| 579 | o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " *TOP*"; |
| 580 | return; |
| 581 | |
| 582 | case dtNamecxx . . $ `Kernel/dlVertex.h:89:9`!: |
| 583 | case dtDataTypecxx . . $ dtDataType.: |
| 584 | case dtDataValuecxx . . $ dtDataValue.: |
| 585 | o <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' ' <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). v.getConceptcxx . . $ DLVertex#getConcept(1867504d72698304).()->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).(); |
| 586 | return; |
| 587 | |
| 588 | case dtDataExprcxx . . $ dtDataExpr.: |
| 589 | o <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' ' <<cxx . . $ `operator<<`(71e68dfacb67ce94). *getDataEntryByBPcxx . . $ TBox#getDataEntryByBP(8513d1ebfa7d4562).(p)->getFacetcxx . . $ TDataEntry#getFacet(e55f2b8bb1ed2996).(); |
| 590 | return; |
| 591 | |
| 592 | case dtIrrcxx . . $ dtIrr.: |
| 593 | o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " (" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). v.getTagNamecxx . . $ DLVertex#getTagName(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' ' <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). v.getRolecxx . . $ DLVertex#getRole(69f26110a94b259f).()->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ")"; |
| 594 | return; |
| 595 | |
| 596 | case dtAndcxx . . $ dtAnd.: |
| 597 | o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " (" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). v.getTagNamecxx . . $ DLVertex#getTagName(a9f41ea0e82d88cf).(); |
| 598 | for ( DLVertexcxx . . $ DLVertex#::const_iteratorcxx . . $ DLVertex#const_iterator# q = v.begincxx . . $ DLVertex#begin(d2502ee2ca3b883a).(); q !=cxx . . $ __gnu_cxx/`operator!=`(ef3c5749062e825c). v.endcxx . . $ DLVertex#end(d2502ee2ca3b883a).(); ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).q ) |
| 599 | PrintDagEntrycxx . . $ TBox#PrintDagEntry(94fe421b246ddbdb). ( o, *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).q ); |
| 600 | o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ")"; |
| 601 | return; |
| 602 | |
| 603 | case dtForallcxx . . $ dtForall.: |
| 604 | case dtLEcxx . . $ dtLE.: |
| 605 | o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " (" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). v.getTagNamecxx . . $ DLVertex#getTagName(a9f41ea0e82d88cf).(); |
| 606 | if ( v.Typecxx . . $ DLVertexTagDFS#Type(d9c59f5f195b46b8).() == dtLEcxx . . $ dtLE. ) |
| 607 | o <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' ' <<cxx . . $ std/basic_ostream#`operator<<`(b4c055c363850233). v.getNumberLEcxx . . $ DLVertex#getNumberLE(ddd8539a2fcdd4ce).(); |
| 608 | o <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' ' <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). v.getRolecxx . . $ DLVertex#getRole(69f26110a94b259f).()->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).(); |
| 609 | PrintDagEntrycxx . . $ TBox#PrintDagEntry(94fe421b246ddbdb). ( o, v.getCcxx . . $ DLVertex#getC(455f465bc33b4cdf).() ); |
| 610 | o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ")"; |
| 611 | return; |
| 612 | |
| 613 | case dtProjcxx . . $ dtProj.: |
| 614 | o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " (" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). v.getTagNamecxx . . $ DLVertex#getTagName(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' ' <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). v.getRolecxx . . $ DLVertex#getRole(69f26110a94b259f).()->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' '; |
| 615 | PrintDagEntrycxx . . $ TBox#PrintDagEntry(94fe421b246ddbdb). ( o, v.getCcxx . . $ DLVertex#getC(455f465bc33b4cdf).() ); |
| 616 | o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " => " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). v.getProjRolecxx . . $ DLVertex#getProjRole(69f26110a94b259f).()->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ")"; |
| 617 | return; |
| 618 | |
| 619 | case dtNNcxx . . $ dtNN.: // shouldn't appears in the expressions |
| 620 | case dtChoosecxx . . $ dtChoose.: |
| 621 | fpp_unreachablecxx . . $ `Kernel/fpp_assert.h:49:9`!(); |
| 622 | |
| 623 | default: // invalid value |
| 624 | stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Error printing vertex of type " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). v.getTagNamecxx . . $ DLVertex#getTagName(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "(" <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). v.Typecxx . . $ DLVertexTagDFS#Type(d9c59f5f195b46b8). () <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ")"; |
| 625 | fpp_unreachablecxx . . $ `Kernel/fpp_assert.h:49:9`!(); |
| 626 | return; |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | void TBoxcxx . . $ TBox# :: PrintConceptcxx . . $ TBox#PrintConcept(2c84f40513d9abdd). ( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& o, const TConceptcxx . . $ TConcept#* p ) const |
| 631 | { |
| 632 | // print only relevant concepts |
| 633 | if ( isValidcxx . . $ isValid(83c267b20bac841a).(p->pNamecxx . . $ TConcept#pName.) ) |
| 634 | { |
| 635 | o <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). getCTTagNamecxx . . $ getCTTagName(b73a14fb0f7cb229).(p->getClassTagcxx . . $ TConcept#getClassTag(863da13868153a34).()); |
| 636 | |
| 637 | if ( p->isSingletoncxx . . $ TConcept#isSingleton(50ce9a9e25b4a850).() ) |
| 638 | o <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). (p->isNominalcxx . . $ TConcept#isNominal(50ce9a9e25b4a850).() ? 'o' : '!'); |
| 639 | |
| 640 | o <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '.' <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). p->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " [" <<cxx . . $ std/basic_ostream#`operator<<`(b4c055c363850233). p->tsDepthcxx . . $ TConcept#tsDepth. |
| 641 | <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "] " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). (p->isNonPrimitivecxx . . $ TConcept#isNonPrimitive(50ce9a9e25b4a850).() ? "=" : "[="); |
| 642 | |
| 643 | if ( isValidcxx . . $ isValid(83c267b20bac841a). (p->pBodycxx . . $ TConcept#pBody.) ) |
| 644 | PrintDagEntrycxx . . $ TBox#PrintDagEntry(94fe421b246ddbdb). ( o, p->pBodycxx . . $ TConcept#pBody. ); |
| 645 | |
| 646 | // if you want to check correctness of translation (print following info) |
| 647 | // you should comment out RemoveExtraDescription() in TBox::Preprocess() |
| 648 | // but check hasSynonym assignment |
| 649 | if ( p->Descriptioncxx . . $ TConcept#Description. != nullptr ) |
| 650 | o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). (p->isNonPrimitivecxx . . $ TConcept#isNonPrimitive(50ce9a9e25b4a850).() ? "\n-=" : "\n-[=") <<cxx . . $ `operator<<`(607b78f3c31ebc02). p->Descriptioncxx . . $ TConcept#Description.; |
| 651 | |
| 652 | o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\n"; |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | void |
| 657 | TBoxcxx . . $ TBox# :: printFeaturescxx . . $ TBox#printFeatures(83f5f38750778ac8). ( void ) const |
| 658 | { |
| 659 | KBFeaturescxx . . $ TBox#KBFeatures..writeStatecxx . . $ LogicFeatures#writeState(83f5f38750778ac8).(); |
| 660 | |
| 661 | if ( LLMcxx . . $ LLM..isWritablecxx . . $ LeveLogger#isWritable(8de63fdb265b07c1).(llAlwayscxx . . $ llAlways.) ) |
| 662 | LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "KB contains " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). (GCIscxx . . $ TBox#GCIs..isGCIcxx . . $ TKBFlags#isGCI(50ce9a9e25b4a850).() ? "" : "NO ") <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "GCIs\nKB contains " |
| 663 | <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). (GCIscxx . . $ TBox#GCIs..isReflexivecxx . . $ TKBFlags#isReflexive(50ce9a9e25b4a850).() ? "" : "NO ") <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "reflexive roles\nKB contains " |
| 664 | <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). (GCIscxx . . $ TBox#GCIs..isRnDcxx . . $ TKBFlags#isRnD(50ce9a9e25b4a850).() ? "" : "NO ") <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "range and domain restrictions\n"; |
| 665 | } |