| 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 | #ifndef REASONERNOM_H |
| 21 | #define REASONERNOM_Hcxx . . $ `Kernel/ReasonerNom.h:21:9`! |
| 22 | |
| 23 | #include "Reasoner.h"cxx . . $ `<file>/Kernel/Reasoner.h`/ |
| 24 | |
| 25 | class NominalReasonercxx . . $ NominalReasoner#: public DlSatTestercxx . . $ DlSatTester# |
| 26 | { |
| 27 | protected: // type definition |
| 28 | /// vector of singletons |
| 29 | typedef TBoxcxx . . $ TBox#::SingletonVectorcxx . . $ TBox#SingletonVector# SingletonVectorcxx . . $ NominalReasoner#SingletonVector#; |
| 30 | |
| 31 | protected: // members |
| 32 | /// all nominals defined in TBox |
| 33 | SingletonVectorcxx . . $ NominalReasoner#SingletonVector# Nominalscxx . . $ NominalReasoner#Nominals.; |
| 34 | |
| 35 | protected: // methods |
| 36 | /// prepare reasoning |
| 37 | void prepareReasonercxx . . $ NominalReasoner#prepareReasoner(49f6e7a06ebc5aa8). ( void ) override; |
| 38 | /// there are nominals |
| 39 | bool hasNominalscxx . . $ NominalReasoner#hasNominals(50ce9a9e25b4a850). ( void ) const override { return true; } |
| 40 | |
| 41 | //----------------------------------------------------------------------------- |
| 42 | //-- internal nominal reasoning interface |
| 43 | //----------------------------------------------------------------------------- |
| 44 | |
| 45 | /// init vector of nominals defined in TBox |
| 46 | void initNominalVectorcxx . . $ NominalReasoner#initNominalVector(49f6e7a06ebc5aa8). ( void ); |
| 47 | |
| 48 | /// create cache entry for given singleton |
| 49 | void registerNominalCachecxx . . $ NominalReasoner#registerNominalCache(cfdaafa68a432519). ( const TIndividualcxx . . $ TIndividual#* p ) |
| 50 | { DLHeapcxx . . $ DlSatTester#DLHeap..setCachecxx . . $ DLDag#setCache(5d5e965ff81adf26). ( p->pNamecxx . . $ TConcept#pName., createModelCachecxx . . $ DlSatTester#createModelCache(3b43971eaa030b12).(p->nodecxx . . $ TIndividual#node.->resolvePBlockercxx . . $ DlCompletionTree#resolvePBlocker(8f504d760f19febe).()) ); } |
| 51 | /// init single nominal node |
| 52 | bool initNominalNodecxx . . $ NominalReasoner#initNominalNode(d8fe2b44a0fc0e9f). ( const TIndividualcxx . . $ TIndividual#* nom ) |
| 53 | { |
| 54 | DlCompletionTreecxx . . $ DlCompletionTree#* node = CGraphcxx . . $ DlSatTester#CGraph..getNewNodecxx . . $ DlCompletionGraph#getNewNode(8f504d760f19febe).(); |
| 55 | node->setNominalLevelcxx . . $ DlCompletionTree#setNominalLevel(49f6e7a06ebc5aa8).(); |
| 56 | const_cast<TIndividualcxx . . $ TIndividual#*>(nom)->nodecxx . . $ TIndividual#node. = node; // init nominal with associated node |
| 57 | return initNewNodecxx . . $ DlSatTester#initNewNode(96e59f80c609b310). ( node, DepSetcxx . . $ TDepSet#TDepSet(49f6e7a06ebc5aa8).(), nom->pNamecxx . . $ TConcept#pName. ); // ABox is inconsistent |
| 58 | } |
| 59 | /// create nominal nodes for all individuals in TBox |
| 60 | bool initNominalCloudcxx . . $ NominalReasoner#initNominalCloud(c9857a73d68e59ba). ( void ); |
| 61 | /// make an R-edge between related nominals |
| 62 | bool initRelatedNominalscxx . . $ NominalReasoner#initRelatedNominals(10d4b22f0a012a34). ( const TRelatedcxx . . $ TRelated#* rel ); |
| 63 | /// use classification information for the nominal P |
| 64 | void updateClassifiedSingletoncxx . . $ NominalReasoner#updateClassifiedSingleton(8c463a1a9ca3e3d3). ( TIndividualcxx . . $ TIndividual#* p ) |
| 65 | { |
| 66 | registerNominalCachecxx . . $ NominalReasoner#registerNominalCache(cfdaafa68a432519).(p); |
| 67 | if ( unlikelycxx . . $ DlCompletionTree#isPBlocked(50ce9a9e25b4a850).(p->node->isPBlocked()) ) |
| 68 | { |
| 69 | // BP of the individual P is merged to |
| 70 | BipolarPointercxx . . $ BipolarPointer# bp = p->nodecxx . . $ TIndividual#node.->getBlockercxx . . $ DlCompletionTree#getBlocker(19e040716207bced).()->labelcxx . . $ DlCompletionTree#label(fdeef9563491d77a).().begin_sccxx . . $ CGLabel#begin_sc(e55d760a93e9f197).()->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(a68f0626e749d9f6).bpcxx . . $ ConceptWDep#bp(455f465bc33b4cdf).(); |
| 71 | TIndividualcxx . . $ TIndividual#* blocker = (TIndividualcxx . . $ TIndividual#*)DLHeapcxx . . $ DlSatTester#DLHeap.[cxx . . $ DLDag#`operator[]`(e265d70853dfed20).bp].getConceptcxx . . $ DLVertex#getConcept(f3d19eb180c44c64).(); |
| 72 | fpp_assertcxx . . $ EFPPAssertion#EFPPAssertion(85c52e162fed56f9). ( blocker->node == p->node->getBlocker() ); |
| 73 | tBoxcxx . . $ DlSatTester#tBox..SameIcxx . . $ TBox#SameI.[cxx . . $ std/map#`operator[]`(da459db78e6e18a3).p] =cxx . . $ std/pair#`operator=`(3e10bac4c1d57c4). stdcxx . . $ std/::make_paircxx . . $ std/make_pair(1d30b6e115203116). ( blocker, p->nodecxx . . $ TIndividual#node.->getPurgeDepcxx . . $ DlCompletionTree#getPurgeDep(bce6462a16d96b29).().emptycxx . . $ TDepSet#empty(50ce9a9e25b4a850).() ); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | // Checks whether a completion graph node has references to individuals (nominals) |
| 78 | bool hasIndividualscxx . . $ NominalReasoner#hasIndividuals(6c1e73ffdfd78b24).(const DlCompletionTreecxx . . $ DlCompletionTree#* node); |
| 79 | |
| 80 | // Returns a list of individuals referenced by a completion graph node |
| 81 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<TIndividualcxx . . $ TIndividual#*> getIndividualscxx . . $ NominalReasoner#getIndividuals(8565562e7f92868).(const DlCompletionTreecxx . . $ DlCompletionTree#* node); |
| 82 | |
| 83 | // Populates individual relations using the completion graph and the automaton transitions of a complex role |
| 84 | void 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); |
| 85 | |
| 86 | // Creates cache of individual relations based on the completion graph and roles automata (for faster but potentially incomplete queries) |
| 87 | void precacheRelatedcxx . . $ NominalReasoner#precacheRelated(49f6e7a06ebc5aa8).(); |
| 88 | |
| 89 | public: |
| 90 | /// c'tor |
| 91 | explicit NominalReasonercxx . . $ NominalReasoner#NominalReasoner(8683a8a7d2fb73f). ( TBoxcxx . . $ TBox#& tbox ) |
| 92 | : DlSatTestercxx . . $ DlSatTester#DlSatTester(8683a8a7d2fb73f).(tbox) |
| 93 | { |
| 94 | initNominalVectorcxx . . $ NominalReasoner#initNominalVector(49f6e7a06ebc5aa8).(); |
| 95 | } |
| 96 | |
| 97 | /// check whether ontology with nominals is consistent |
| 98 | bool consistentNominalCloudcxx . . $ NominalReasoner#consistentNominalCloud(c9857a73d68e59ba). ( void ); |
| 99 | }; // NominalReasoner |
| 100 | |
| 101 | //----------------------------------------------------------------------------- |
| 102 | //-- implementation of nominal reasoner-related parts of TBox |
| 103 | //----------------------------------------------------------------------------- |
| 104 | |
| 105 | inline void |
| 106 | TBoxcxx . . $ TBox# :: initReasonercxx . . $ TBox#initReasoner(49f6e7a06ebc5aa8). ( void ) |
| 107 | { |
| 108 | fpp_assertcxx . . $ TBox#reasonersInited(50ce9a9e25b4a850). ( !reasonersInited() ); // do init only once |
| 109 | stdReasonercxx . . $ TBox#stdReasoner. = new DlSatTestercxx . . $ DlSatTester#DlSatTester(8683a8a7d2fb73f).(*this); |
| 110 | |
| 111 | if ( NCFeaturescxx . . $ TBox#NCFeatures..hasSingletonscxx . . $ LogicFeatures#hasSingletons(50ce9a9e25b4a850).() ) |
| 112 | { |
| 113 | nomReasonercxx . . $ TBox#nomReasoner. = new NominalReasonercxx . . $ NominalReasoner#NominalReasoner(8683a8a7d2fb73f).(*this); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | #endif |