| 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 "tAxiom.h"cxx . . $ `<file>/Kernel/tAxiom.h`/ |
| 21 | #include "dlTBox.h"cxx . . $ `<file>/Kernel/dlTBox.h`/ |
| 22 | |
| 23 | // this is to define the hard cycle in concepts: C = \exists R D, D = \exists S C |
| 24 | // we saw cycles of that type of length 2 |
| 25 | |
| 26 | typedef stdcxx . . $ std/::setcxx . . $ std/set#<const TConceptcxx . . $ TConcept#*> ConceptSetcxx . . $ ConceptSet#; |
| 27 | |
| 28 | static bool |
| 29 | hasDefCyclecxx . . $ hasDefCycle(c06090ff25f7d28a). ( const TConceptcxx . . $ TConcept#* C, ConceptSetcxx . . $ ConceptSet#& visited ) |
| 30 | { |
| 31 | // interested in non-primitive |
| 32 | if ( C->isPrimitivecxx . . $ TConcept#isPrimitive(50ce9a9e25b4a850).() ) |
| 33 | return false; |
| 34 | // already seen -- cycle |
| 35 | if ( visited.countcxx . . $ std/set#count(a9c5b6ffd713dfa6).(C) > 0 ) |
| 36 | return true; |
| 37 | // check the structure: looking for the \exists R.C |
| 38 | const DLTreecxx . . $ DLTree#* p = C->Descriptioncxx . . $ TConcept#Description.; |
| 39 | if ( p->Elementcxx . . $ TsTTree#Element(ea465e50d690edfe).().getTokencxx . . $ TLexeme#getToken(d71a1020745f3953).() != NOTcxx . . $ NOT. ) |
| 40 | return false; |
| 41 | p = p->Leftcxx . . $ TsTTree#Left(f4b2f47551fb31d7).(); |
| 42 | if ( p->Elementcxx . . $ TsTTree#Element(ea465e50d690edfe).().getTokencxx . . $ TLexeme#getToken(d71a1020745f3953).() != FORALLcxx . . $ FORALL. ) |
| 43 | return false; |
| 44 | p = p->Rightcxx . . $ TsTTree#Right(f4b2f47551fb31d7).(); |
| 45 | if ( p->Elementcxx . . $ TsTTree#Element(ea465e50d690edfe).().getTokencxx . . $ TLexeme#getToken(d71a1020745f3953).() != NOTcxx . . $ NOT. ) |
| 46 | return false; |
| 47 | p = p->Leftcxx . . $ TsTTree#Left(f4b2f47551fb31d7).(); |
| 48 | if ( !isNamecxx . . $ isName(937bda690ff1bb73).(p) ) |
| 49 | return false; |
| 50 | // here P is a concept |
| 51 | // remember C |
| 52 | visited.insertcxx . . $ std/set#insert(411a10a755068dfe).(C); |
| 53 | // check p |
| 54 | return hasDefCyclecxx . . $ hasDefCycle(c06090ff25f7d28a). ( static_cast<const TConceptcxx . . $ TConcept#*>(p->Elementcxx . . $ TsTTree#Element(ea465e50d690edfe).().getNEcxx . . $ TLexeme#getNE(28c03b9fd3c689f8).()), visited ); |
| 55 | } |
| 56 | |
| 57 | static bool |
| 58 | hasDefCyclecxx . . $ hasDefCycle(15d44b555a30180e). ( const TConceptcxx . . $ TConcept#* C ) |
| 59 | { |
| 60 | ConceptSetcxx . . $ ConceptSet# visitedcxx . . $ std/set#set(49f6e7a06ebc5aa8).; |
| 61 | return hasDefCyclecxx . . $ hasDefCycle(c06090ff25f7d28a). ( C, visited ); |
| 62 | } |
| 63 | |
| 64 | bool |
| 65 | InAxcxx . . $ InAx/ :: isNPcxx . . $ InAx/isNP(e710061aa085e772). ( const TConceptcxx . . $ TConcept#* C, TBoxcxx . . $ TBox#& ) |
| 66 | { |
| 67 | return C->isNonPrimitivecxx . . $ TConcept#isNonPrimitive(50ce9a9e25b4a850).() && !hasDefCyclecxx . . $ hasDefCycle(15d44b555a30180e).(C); |
| 68 | } |
| 69 | |
| 70 | /// add DLTree to an axiom |
| 71 | void |
| 72 | TAxiomcxx . . $ TAxiom# :: addcxx . . $ TAxiom#add(edf821a2fc5509f9). ( DLTreecxx . . $ DLTree#* p ) |
| 73 | { |
| 74 | if ( InAxcxx . . $ InAx/::isBotcxx . . $ InAx/isBot(937bda690ff1bb73).(p) ) // BOT or X == X |
| 75 | return; // nothing to do |
| 76 | // flatten the disjunctions on the fly |
| 77 | if ( InAxcxx . . $ InAx/::isOrcxx . . $ InAx/isOr(937bda690ff1bb73).(p) ) |
| 78 | { |
| 79 | addcxx . . $ TAxiom#add(edf821a2fc5509f9).(clonecxx . . $ clone(ec41a33c52a5614b).(p->Leftcxx . . $ TsTTree#Left(f4b2f47551fb31d7).())); |
| 80 | addcxx . . $ TAxiom#add(edf821a2fc5509f9).(clonecxx . . $ clone(ec41a33c52a5614b).(p->Rightcxx . . $ TsTTree#Right(f4b2f47551fb31d7).())); |
| 81 | deleteTreecxx . . $ deleteTree(c5beffd064a5e5b2).(p); |
| 82 | return; |
| 83 | } |
| 84 | for ( const auto& C: Disjunctscxx . . $ TAxiom#Disjuncts. ) |
| 85 | if ( equalTreescxx . . $ equalTrees(d3c03bdc42525896).(p,C) ) |
| 86 | { |
| 87 | deleteTreecxx . . $ deleteTree(c5beffd064a5e5b2).(p); |
| 88 | return; |
| 89 | } |
| 90 | Disjunctscxx . . $ TAxiom#Disjuncts..push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(p); |
| 91 | } |
| 92 | |
| 93 | TAxiomcxx . . $ TAxiom#* |
| 94 | TAxiomcxx . . $ TAxiom# :: simplifyCNcxx . . $ TAxiom#simplifyCN(78ec7736a2556433). ( TBoxcxx . . $ TBox#& KB ) const |
| 95 | { |
| 96 | for ( const auto& C: Disjunctscxx . . $ TAxiom#Disjuncts. ) |
| 97 | { |
| 98 | if ( InAxcxx . . $ InAx/::isPosNPcxx . . $ InAx/isPosNP(136d7af063eca941).(C,KB) ) |
| 99 | return simplifyPosNPcxx . . $ TAxiom#simplifyPosNP(f473873b85966b34).(C); |
| 100 | else if ( InAxcxx . . $ InAx/::isNegNPcxx . . $ InAx/isNegNP(136d7af063eca941).(C,KB) ) |
| 101 | return simplifyNegNPcxx . . $ TAxiom#simplifyNegNP(f473873b85966b34).(C); |
| 102 | } |
| 103 | |
| 104 | return nullptr; |
| 105 | } |
| 106 | |
| 107 | TAxiomcxx . . $ TAxiom#* |
| 108 | TAxiomcxx . . $ TAxiom# :: simplifyForallcxx . . $ TAxiom#simplifyForall(78ec7736a2556433). ( TBoxcxx . . $ TBox#& KB ) const |
| 109 | { |
| 110 | for ( const auto& C: Disjunctscxx . . $ TAxiom#Disjuncts. ) |
| 111 | if ( InAxcxx . . $ InAx/::isAbsForallcxx . . $ InAx/isAbsForall(937bda690ff1bb73).(C) ) |
| 112 | return simplifyForallcxx . . $ TAxiom#simplifyForall(ec547cdc3aed66c). ( C, KB ); |
| 113 | |
| 114 | return nullptr; |
| 115 | } |
| 116 | |
| 117 | TAxiomcxx . . $ TAxiom#* |
| 118 | TAxiomcxx . . $ TAxiom# :: simplifySForallcxx . . $ TAxiom#simplifySForall(78ec7736a2556433). ( TBoxcxx . . $ TBox#& KB ) const |
| 119 | { |
| 120 | for ( const auto& C: Disjunctscxx . . $ TAxiom#Disjuncts. ) |
| 121 | if ( InAxcxx . . $ InAx/::isSimpleForallcxx . . $ InAx/isSimpleForall(937bda690ff1bb73).(C) ) |
| 122 | return simplifyForallcxx . . $ TAxiom#simplifyForall(ec547cdc3aed66c). ( C, KB ); |
| 123 | |
| 124 | return nullptr; |
| 125 | } |
| 126 | |
| 127 | TAxiomcxx . . $ TAxiom#* |
| 128 | TAxiomcxx . . $ TAxiom# :: simplifyForallcxx . . $ TAxiom#simplifyForall(ec547cdc3aed66c). ( const DLTreecxx . . $ DLTree#* rep, TBoxcxx . . $ TBox#& KB ) const |
| 129 | { |
| 130 | Statcxx . . $ Stat/::SAbsRepForallcxx . . $ Stat/SAbsRepForall#(); |
| 131 | DLTreecxx . . $ DLTree#* pAll = rep->Leftcxx . . $ TsTTree#Left(f4b2f47551fb31d7).(); // (all R ~C) |
| 132 | #ifdef RKG_DEBUG_ABSORPTION |
| 133 | std::cout << " simplify ALL expression" << pAll; |
| 134 | #endif |
| 135 | TAxiomcxx . . $ TAxiom#* ret = copycxx . . $ TAxiom#copy(f473873b85966b34).(rep); |
| 136 | ret->addcxx . . $ TAxiom#add(edf821a2fc5509f9).(KB.getTreecxx . . $ TBox#getTree(8f1a6b264b733ed7).(KB.replaceForallcxx . . $ TBox#replaceForall(9b2c8167507be48a).(clonecxx . . $ clone(ec41a33c52a5614b).(pAll)))); |
| 137 | return ret; |
| 138 | } |
| 139 | |
| 140 | DLTreecxx . . $ DLTree#* |
| 141 | TAxiomcxx . . $ TAxiom# :: createAnAxiomcxx . . $ TAxiom#createAnAxiom(8f188fbd9d5632d6). ( const DLTreecxx . . $ DLTree#* skip ) const |
| 142 | { |
| 143 | // create new OR vertex for the axiom: |
| 144 | DLTreecxx . . $ DLTree#* Or = createTopcxx . . $ createTop(aa22cc08b69ae2ef).(); |
| 145 | for ( const auto& C: Disjunctscxx . . $ TAxiom#Disjuncts. ) |
| 146 | if ( C != skip ) |
| 147 | Or = createSNFAndcxx . . $ createSNFAnd(f2877343b7b69ea7). ( clonecxx . . $ clone(ec41a33c52a5614b).(C), Or ); |
| 148 | |
| 149 | return createSNFNotcxx . . $ createSNFNot(1bf715d485c1268).(Or); |
| 150 | } |
| 151 | |
| 152 | #ifdef RKG_DEBUG_ABSORPTION |
| 153 | void TAxiom :: dump ( std::ostream& o ) const |
| 154 | { |
| 155 | o << " (neg-and"; |
| 156 | for ( const auto& C: Disjuncts ) |
| 157 | o << C; |
| 158 | o << ")"; |
| 159 | } |
| 160 | #endif |
| 161 | |
| 162 | /// absorb into BOTTOM; @return true if absorption is performed |
| 163 | bool |
| 164 | TAxiomcxx . . $ TAxiom# :: absorbIntoBottomcxx . . $ TAxiom#absorbIntoBottom(50ce9a9e25b4a850). ( void ) const |
| 165 | { |
| 166 | absorptionSetcxx . . $ TAxiom#absorptionSet# Poscxx . . $ std/vector#vector(49f6e7a06ebc5aa8)., Negcxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 167 | for ( const auto& C: Disjunctscxx . . $ TAxiom#Disjuncts. ) |
| 168 | switch ( C->Elementcxx . . $ TsTTree#Element(19b2b6f17af048b).().getTokencxx . . $ TLexeme#getToken(d71a1020745f3953).() ) |
| 169 | { |
| 170 | case BOTTOMcxx . . $ BOTTOM.: // axiom in the form T [= T or ...; nothing to do |
| 171 | Statcxx . . $ Stat/::SAbsBApplycxx . . $ Stat/SAbsBApply#(); |
| 172 | # ifdef RKG_DEBUG_ABSORPTION |
| 173 | std::cout << " Absorb into BOTTOM"; |
| 174 | # endif |
| 175 | return true; |
| 176 | case TOPcxx . . $ TOP.: // skip it here |
| 177 | break; |
| 178 | case NOTcxx . . $ NOT.: // something negated: put it into NEG |
| 179 | Neg.push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(C->Leftcxx . . $ TsTTree#Left(f4b2f47551fb31d7).()); |
| 180 | break; |
| 181 | default: // something positive: save in POS |
| 182 | Pos.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(C); |
| 183 | break; |
| 184 | } |
| 185 | |
| 186 | // now check whether there is a concept in both POS and NEG |
| 187 | for ( const auto& neg: Neg ) |
| 188 | for ( const auto& pos: Pos ) |
| 189 | if ( equalTreescxx . . $ equalTrees(d3c03bdc42525896). ( neg, pos ) ) |
| 190 | { |
| 191 | Statcxx . . $ Stat/::SAbsBApplycxx . . $ Stat/SAbsBApply#(); |
| 192 | # ifdef RKG_DEBUG_ABSORPTION |
| 193 | std::cout << " Absorb into BOTTOM due to (not" << neg << ") and" << pos; |
| 194 | # endif |
| 195 | return true; |
| 196 | } |
| 197 | return false; |
| 198 | } |
| 199 | |
| 200 | bool |
| 201 | TAxiomcxx . . $ TAxiom# :: absorbIntoTopcxx . . $ TAxiom#absorbIntoTop(7e0306efbd9b1d86). ( TBoxcxx . . $ TBox#& KB ) const |
| 202 | { |
| 203 | TConceptcxx . . $ TConcept#* Cand = nullptr; |
| 204 | |
| 205 | // check whether the axiom is Top [= C |
| 206 | for ( const auto& C: Disjunctscxx . . $ TAxiom#Disjuncts. ) |
| 207 | if ( InAxcxx . . $ InAx/::isBotcxx . . $ InAx/isBot(937bda690ff1bb73).(C) ) // BOTTOMS are fine |
| 208 | continue; |
| 209 | else if ( InAxcxx . . $ InAx/::isPosCNcxx . . $ InAx/isPosCN(937bda690ff1bb73).(C) ) // CN found |
| 210 | { |
| 211 | if ( Cand != nullptr ) // more than one concept |
| 212 | return false; |
| 213 | Cand = InAxcxx . . $ InAx/::getConceptcxx . . $ InAx/getConcept(9b2c8167507be48a).(C->Leftcxx . . $ TsTTree#Left(f4b2f47551fb31d7).()); |
| 214 | if ( Cand->isSingletoncxx . . $ TConcept#isSingleton(50ce9a9e25b4a850).() ) // doesn't work with nominals |
| 215 | return false; |
| 216 | } |
| 217 | else |
| 218 | return false; |
| 219 | |
| 220 | if ( Cand == nullptr ) |
| 221 | return false; |
| 222 | |
| 223 | // make an absorption |
| 224 | Statcxx . . $ Stat/::SAbsTApplycxx . . $ Stat/SAbsTApply#(); |
| 225 | DLTreecxx . . $ DLTree#* desc = KB.makeNonPrimitivecxx . . $ TBox#makeNonPrimitive(1e45738bba157392). ( Cand, createTopcxx . . $ createTop(aa22cc08b69ae2ef).() ); |
| 226 | |
| 227 | #ifdef RKG_DEBUG_ABSORPTION |
| 228 | std::cout << " T-Absorb GCI to axiom"; |
| 229 | if ( desc ) |
| 230 | std::cout << "s *TOP* [=" << desc << " and"; |
| 231 | std::cout << " " << Cand->getName() << " = *TOP*"; |
| 232 | #endif |
| 233 | if ( desc ) |
| 234 | KB.addSubsumeAxiomcxx . . $ TBox#addSubsumeAxiom(237c04ede5740138). ( createTopcxx . . $ createTop(aa22cc08b69ae2ef).(), desc ); |
| 235 | |
| 236 | return true; |
| 237 | } |
| 238 | |
| 239 | bool |
| 240 | TAxiomcxx . . $ TAxiom# :: absorbIntoConceptcxx . . $ TAxiom#absorbIntoConcept(7e0306efbd9b1d86). ( TBoxcxx . . $ TBox#& KB ) const |
| 241 | { |
| 242 | WorkSetcxx . . $ TAxiom#WorkSet# Conscxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 243 | DLTreecxx . . $ DLTree#* bestConcept = nullptr; |
| 244 | |
| 245 | // finds all primitive concept names |
| 246 | for ( const auto& C: Disjunctscxx . . $ TAxiom#Disjuncts. ) |
| 247 | if ( InAxcxx . . $ InAx/::isNegPCcxx . . $ InAx/isNegPC(937bda690ff1bb73).(C) ) // FIXME!! review this during implementation of Nominal Absorption |
| 248 | { |
| 249 | Statcxx . . $ Stat/::SAbsCAttemptcxx . . $ Stat/SAbsCAttempt#(); |
| 250 | Cons.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(C); |
| 251 | if ( InAxcxx . . $ InAx/::getConceptcxx . . $ InAx/getConcept(9b2c8167507be48a).(C)->isSystemcxx . . $ TNamedEntry#isSystem(50ce9a9e25b4a850).() ) |
| 252 | bestConcept = C; |
| 253 | } |
| 254 | |
| 255 | // if no concept names -- return; |
| 256 | if ( Cons.emptycxx . . $ std/vector#empty(50ce9a9e25b4a850).() ) |
| 257 | return false; |
| 258 | |
| 259 | Statcxx . . $ Stat/::SAbsCApplycxx . . $ Stat/SAbsCApply#(); |
| 260 | // FIXME!! as for now: just take the 1st concept name |
| 261 | if ( bestConcept == nullptr ) |
| 262 | bestConcept = Cons[cxx . . $ std/vector#`operator[]`(428bb168810b9e52).0]; |
| 263 | |
| 264 | // normal concept absorption |
| 265 | TConceptcxx . . $ TConcept#* Concept = InAxcxx . . $ InAx/::getConceptcxx . . $ InAx/getConcept(9b2c8167507be48a).(bestConcept); |
| 266 | |
| 267 | #ifdef RKG_DEBUG_ABSORPTION |
| 268 | std::cout << " C-Absorb GCI to concept " << Concept->getName(); |
| 269 | if ( Cons.size() > 1 ) |
| 270 | { |
| 271 | std::cout << " (other options are"; |
| 272 | for ( const auto& C: Cons ) |
| 273 | if ( C != bestConcept ) |
| 274 | std::cout << " " << InAx::getConcept(C)->getName(); |
| 275 | std::cout << ")"; |
| 276 | } |
| 277 | #endif |
| 278 | |
| 279 | // adds a new definition |
| 280 | Concept->addDesccxx . . $ TConcept#addDesc(edf821a2fc5509f9).(createAnAxiomcxx . . $ TAxiom#createAnAxiom(8f188fbd9d5632d6).(bestConcept)); |
| 281 | Concept->removeSelfFromDescriptioncxx . . $ TConcept#removeSelfFromDescription(49f6e7a06ebc5aa8).(); |
| 282 | // in case T [= (A or \neg B) and (B and \neg A) there appears a cycle A [= B [= A |
| 283 | // so remove potential cycle |
| 284 | // FIXME!! just because TConcept can't get rid of cycle by itself |
| 285 | KB.clearRelevanceInfocxx . . $ TBox#clearRelevanceInfo(49f6e7a06ebc5aa8).(); |
| 286 | KB.checkToldCyclecxx . . $ TBox#checkToldCycle(2463a09a87430b75).(Concept); |
| 287 | KB.clearRelevanceInfocxx . . $ TBox#clearRelevanceInfo(49f6e7a06ebc5aa8).(); |
| 288 | |
| 289 | return true; |
| 290 | } |
| 291 | |
| 292 | /// absorb into negation of a concept; @return true if absorption is performed |
| 293 | bool |
| 294 | TAxiomcxx . . $ TAxiom# :: absorbIntoNegConceptcxx . . $ TAxiom#absorbIntoNegConcept(7e0306efbd9b1d86). ( TBoxcxx . . $ TBox#& KB ) const |
| 295 | { |
| 296 | WorkSetcxx . . $ TAxiom#WorkSet# Conscxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 297 | TConceptcxx . . $ TConcept#* Concept; |
| 298 | const DLTreecxx . . $ DLTree#* bestConcept = nullptr; |
| 299 | |
| 300 | // finds all primitive negated concept names without description |
| 301 | for ( const auto& C: Disjunctscxx . . $ TAxiom#Disjuncts. ) |
| 302 | if ( C->Elementcxx . . $ TsTTree#Element(19b2b6f17af048b).().getTokencxx . . $ TLexeme#getToken(d71a1020745f3953).() == NOTcxx . . $ NOT. && isNamecxx . . $ isName(937bda690ff1bb73).(C->Leftcxx . . $ TsTTree#Left(f4b2f47551fb31d7).()) |
| 303 | && (Concept = InAxcxx . . $ InAx/::getConceptcxx . . $ InAx/getConcept(9b2c8167507be48a).(C->Leftcxx . . $ TsTTree#Left(f4b2f47551fb31d7).()))->isPrimitivecxx . . $ TConcept#isPrimitive(50ce9a9e25b4a850).() |
| 304 | && !Concept->isSingletoncxx . . $ TConcept#isSingleton(50ce9a9e25b4a850).() && Concept->Descriptioncxx . . $ TConcept#Description. == nullptr ) |
| 305 | { |
| 306 | Statcxx . . $ Stat/::SAbsNAttemptcxx . . $ Stat/SAbsNAttempt#(); |
| 307 | Cons.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(C); |
| 308 | } |
| 309 | |
| 310 | // if no concept names -- return; |
| 311 | if ( Cons.emptycxx . . $ std/vector#empty(50ce9a9e25b4a850).() ) |
| 312 | return false; |
| 313 | |
| 314 | Statcxx . . $ Stat/::SAbsNApplycxx . . $ Stat/SAbsNApply#(); |
| 315 | // FIXME!! as for now: just take the 1st concept name |
| 316 | if ( bestConcept == nullptr ) |
| 317 | bestConcept = Cons[cxx . . $ std/vector#`operator[]`(428bb168810b9e52).0]; |
| 318 | |
| 319 | // normal concept absorption |
| 320 | Concept = InAxcxx . . $ InAx/::getConceptcxx . . $ InAx/getConcept(9b2c8167507be48a).(bestConcept->Leftcxx . . $ TsTTree#Left(f4b2f47551fb31d7).()); |
| 321 | |
| 322 | #ifdef RKG_DEBUG_ABSORPTION |
| 323 | std::cout << " N-Absorb GCI to concept " << Concept->getName(); |
| 324 | if ( Cons.size() > 1 ) |
| 325 | { |
| 326 | std::cout << " (other options are"; |
| 327 | for ( const auto& C: Cons ) |
| 328 | if ( C != bestConcept ) |
| 329 | std::cout << " " << InAx::getConcept(C->Left())->getName(); |
| 330 | std::cout << ")"; |
| 331 | } |
| 332 | #endif |
| 333 | |
| 334 | // replace ~C [= D with C=~notC, notC [= D: |
| 335 | // make notC [= D |
| 336 | TConceptcxx . . $ TConcept#* nC = KB.getAuxConceptcxx . . $ TBox#getAuxConcept(9b2c8167507be48a).(createAnAxiomcxx . . $ TAxiom#createAnAxiom(8f188fbd9d5632d6).(bestConcept)); |
| 337 | // define C = ~notC; C had an empty desc, so it's safe not to delete it |
| 338 | KB.makeNonPrimitivecxx . . $ TBox#makeNonPrimitive(1e45738bba157392). ( Concept, createSNFNotcxx . . $ createSNFNot(1bf715d485c1268).(KB.getTreecxx . . $ TBox#getTree(8f1a6b264b733ed7).(nC)) ); |
| 339 | return true; |
| 340 | } |
| 341 | |
| 342 | bool |
| 343 | TAxiomcxx . . $ TAxiom# :: absorbIntoDomaincxx . . $ TAxiom#absorbIntoDomain(50ce9a9e25b4a850). ( void ) const |
| 344 | { |
| 345 | WorkSetcxx . . $ TAxiom#WorkSet# Conscxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 346 | const DLTreecxx . . $ DLTree#* bestSome = nullptr; |
| 347 | |
| 348 | // find all forall concepts |
| 349 | for ( const auto& C: Disjunctscxx . . $ TAxiom#Disjuncts. ) |
| 350 | if ( C->Elementcxx . . $ TsTTree#Element(19b2b6f17af048b).() ==cxx . . $ TLexeme#`operator==`(b418e6031985303a). NOTcxx . . $ NOT. && |
| 351 | ( C->Leftcxx . . $ TsTTree#Left(f4b2f47551fb31d7).()->Elementcxx . . $ TsTTree#Element(19b2b6f17af048b).() ==cxx . . $ TLexeme#`operator==`(b418e6031985303a). FORALLcxx . . $ FORALL. // \neg ER.C |
| 352 | || C->Leftcxx . . $ TsTTree#Left(f4b2f47551fb31d7).()->Elementcxx . . $ TsTTree#Element(19b2b6f17af048b).() ==cxx . . $ TLexeme#`operator==`(b418e6031985303a). LEcxx . . $ LE. )) // \neg >= n R.C |
| 353 | { |
| 354 | Statcxx . . $ Stat/::SAbsRAttemptcxx . . $ Stat/SAbsRAttempt#(); |
| 355 | Cons.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(C); |
| 356 | // check for the direct domain case |
| 357 | if ( C->Leftcxx . . $ TsTTree#Left(f4b2f47551fb31d7).()->Rightcxx . . $ TsTTree#Right(f4b2f47551fb31d7).()->Elementcxx . . $ TsTTree#Element(19b2b6f17af048b).() ==cxx . . $ TLexeme#`operator==`(b418e6031985303a). BOTTOMcxx . . $ BOTTOM. ) |
| 358 | { // found proper absorption candidate |
| 359 | bestSome = C; |
| 360 | break; |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | // if there are no EXISTS concepts -- return; |
| 365 | if ( Cons.emptycxx . . $ std/vector#empty(50ce9a9e25b4a850).() ) |
| 366 | return false; |
| 367 | |
| 368 | Statcxx . . $ Stat/::SAbsRApplycxx . . $ Stat/SAbsRApply#(); |
| 369 | TRolecxx . . $ TRole#* Role; |
| 370 | |
| 371 | if ( bestSome != nullptr ) |
| 372 | Role = resolveRolecxx . . $ resolveRole(c256d257f6e22050).(bestSome->Leftcxx . . $ TsTTree#Left(f4b2f47551fb31d7).()->Leftcxx . . $ TsTTree#Left(f4b2f47551fb31d7).()); |
| 373 | else |
| 374 | // FIXME!! as for now: just take the 1st role name |
| 375 | Role = resolveRolecxx . . $ resolveRole(c256d257f6e22050).(Cons[cxx . . $ std/vector#`operator[]`(428bb168810b9e52).0]->Leftcxx . . $ TsTTree#Left(f4b2f47551fb31d7).()->Leftcxx . . $ TsTTree#Left(f4b2f47551fb31d7).()); |
| 376 | |
| 377 | #ifdef RKG_DEBUG_ABSORPTION |
| 378 | std::cout << " R-Absorb GCI to the domain of role " << Role->getName(); |
| 379 | if ( Cons.size() > 1 ) |
| 380 | { |
| 381 | std::cout << " (other options are"; |
| 382 | for ( const auto& C: Cons ) |
| 383 | if ( C != bestSome ) |
| 384 | std::cout << " " << resolveRole(C->Left()->Left())->getName(); |
| 385 | std::cout << ")"; |
| 386 | } |
| 387 | #endif |
| 388 | |
| 389 | // here bestSome is either actual domain, or END(); both cases are fine |
| 390 | Role->setDomaincxx . . $ TRole#setDomain(edf821a2fc5509f9).(createAnAxiomcxx . . $ TAxiom#createAnAxiom(8f188fbd9d5632d6).(bestSome)); |
| 391 | |
| 392 | return true; |
| 393 | } |