| 1 | /* This file is part of the FaCT++ DL reasoner |
| 2 | Copyright (C) 2011-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 | #ifndef SIGINDEX_H |
| 21 | #define SIGINDEX_Hcxx . . $ `Kernel/SigIndex.h:21:9`! |
| 22 | |
| 23 | #include <map> |
| 24 | |
| 25 | #include "tDLAxiom.h"cxx . . $ `<file>/Kernel/tDLAxiom.h`/ |
| 26 | #include "tSignature.h"cxx . . $ `<file>/Kernel/tSignature.h`/ |
| 27 | #include "LocalityChecker.h"cxx . . $ `<file>/Kernel/LocalityChecker.h`/ |
| 28 | |
| 29 | class SigIndexcxx . . $ SigIndex# |
| 30 | { |
| 31 | public: // types |
| 32 | /// RW iterator over set of axioms |
| 33 | typedef AxiomVeccxx . . $ AxiomVec#::iteratorcxx . . $ std/vector#iterator# iteratorcxx . . $ SigIndex#iterator#; |
| 34 | /// RO iterator over set of axioms |
| 35 | typedef AxiomVeccxx . . $ AxiomVec#::const_iteratorcxx . . $ std/vector#const_iterator# const_iteratorcxx . . $ SigIndex#const_iterator#; |
| 36 | |
| 37 | protected: // types |
| 38 | /// map between entities and axioms that contains them in their signature |
| 39 | typedef stdcxx . . $ std/::mapcxx . . $ std/map#<const TNamedEntitycxx . . $ TNamedEntity#*, AxiomVeccxx . . $ AxiomVec#> EntityAxiomMapcxx . . $ SigIndex#EntityAxiomMap#; |
| 40 | |
| 41 | protected: // members |
| 42 | /// map itself |
| 43 | EntityAxiomMapcxx . . $ SigIndex#EntityAxiomMap# Basecxx . . $ SigIndex#Base.; |
| 44 | /// locality checker |
| 45 | LocalityCheckercxx . . $ LocalityChecker#* Checkercxx . . $ SigIndex#Checker.; |
| 46 | /// sets of axioms non-local wrt the empty signature |
| 47 | AxiomVeccxx . . $ AxiomVec# topNonLocalcxx . . $ SigIndex#topNonLocal., botNonLocalcxx . . $ SigIndex#botNonLocal.; |
| 48 | /// empty signature to test the non-locality |
| 49 | TSignaturecxx . . $ TSignature# emptySigcxx . . $ SigIndex#emptySig.; |
| 50 | /// number of registered axioms |
| 51 | unsigned int nRegisteredcxx . . $ SigIndex#nRegistered. = 0; |
| 52 | /// number of registered axioms |
| 53 | unsigned int nUnregisteredcxx . . $ SigIndex#nUnregistered. = 0; |
| 54 | |
| 55 | protected: // methods |
| 56 | /// add an axiom AX to an axiom set AXIOMS |
| 57 | void addcxx . . $ SigIndex#add(a451758bfa4a01cc). ( AxiomVeccxx . . $ AxiomVec#& axioms, TDLAxiomcxx . . $ TDLAxiom#* ax ) { axioms.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(ax); } |
| 58 | /// remove an axiom AX from an axiom set AXIOMS |
| 59 | void removecxx . . $ SigIndex#remove(a451758bfa4a01cc). ( AxiomVeccxx . . $ AxiomVec#& axioms, TDLAxiomcxx . . $ TDLAxiom#* ax ) |
| 60 | { |
| 61 | for ( iteratorcxx . . $ SigIndex#iterator# p = axioms.begincxx . . $ std/vector#begin(33b10a496a38335b).(), p_end = axioms.endcxx . . $ std/vector#end(33b10a496a38335b).(); p !=cxx . . $ __gnu_cxx/`operator!=`(ef3c5749062e825c). p_end; ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).p ) |
| 62 | if ( *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p == ax ) |
| 63 | { |
| 64 | *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).p = axioms.backcxx . . $ std/vector#back(feee51535944b307).(); |
| 65 | axioms.pop_backcxx . . $ std/vector#pop_back(49f6e7a06ebc5aa8).(); |
| 66 | break; |
| 67 | } |
| 68 | } |
| 69 | /// add axiom AX to the non-local set with top-locality value TOP |
| 70 | void checkNonLocalcxx . . $ SigIndex#checkNonLocal(9ec1dfe7d5aa700a). ( TDLAxiomcxx . . $ TDLAxiom#* ax, bool top ) |
| 71 | { |
| 72 | emptySigcxx . . $ SigIndex#emptySig..setLocalitycxx . . $ TSignature#setLocality(b45ddcbc8423892c).(top); |
| 73 | Checkercxx . . $ SigIndex#Checker.->setSignatureValuecxx . . $ LocalityChecker#setSignatureValue(7393b46d99f9f765).(emptySigcxx . . $ SigIndex#emptySig.); |
| 74 | if ( !Checkercxx . . $ SigIndex#Checker.->localcxx . . $ LocalityChecker#local(c12ce7eacb2f7daa).(ax) ) |
| 75 | addcxx . . $ SigIndex#add(a451758bfa4a01cc). ( top ? topNonLocalcxx . . $ SigIndex#topNonLocal. : botNonLocalcxx . . $ SigIndex#botNonLocal., ax ); |
| 76 | } |
| 77 | |
| 78 | // work with axioms |
| 79 | |
| 80 | /// register an axiom |
| 81 | void registerAxcxx . . $ SigIndex#registerAx(ade74f2f8b540a23). ( TDLAxiomcxx . . $ TDLAxiom#* ax ) |
| 82 | { |
| 83 | for ( TSignaturecxx . . $ TSignature#::iteratorcxx . . $ TSignature#iterator# p = ax->getSignaturecxx . . $ TDLAxiom#getSignature(67d28bb768a72444).().begincxx . . $ TSignature#begin(e7f351f2dad9f44a).(), p_end = ax->getSignaturecxx . . $ TDLAxiom#getSignature(67d28bb768a72444).().endcxx . . $ TSignature#end(e7f351f2dad9f44a).(); p !=cxx . . $ std/`operator!=`(7e1308a0738ea758). p_end; ++cxx . . $ std/_Rb_tree_const_iterator#operator++(998dce1072ed46d4).p ) |
| 84 | addcxx . . $ SigIndex#add(a451758bfa4a01cc). ( Basecxx . . $ SigIndex#Base.[cxx . . $ std/map#`operator[]`(bbd415b616967878).*cxx . . $ std/_Rb_tree_const_iterator#`operator*`(ea465e50d690edfe).p], ax ); |
| 85 | // check whether the axiom is non-local |
| 86 | checkNonLocalcxx . . $ SigIndex#checkNonLocal(9ec1dfe7d5aa700a). ( ax, /*top=*/false ); |
| 87 | checkNonLocalcxx . . $ SigIndex#checkNonLocal(9ec1dfe7d5aa700a). ( ax, /*top=*/true ); |
| 88 | ++nRegisteredcxx . . $ SigIndex#nRegistered.; |
| 89 | } |
| 90 | /// unregister an axiom AX |
| 91 | void unregisterAxcxx . . $ SigIndex#unregisterAx(ade74f2f8b540a23). ( TDLAxiomcxx . . $ TDLAxiom#* ax ) |
| 92 | { |
| 93 | for ( TSignaturecxx . . $ TSignature#::iteratorcxx . . $ TSignature#iterator# p = ax->getSignaturecxx . . $ TDLAxiom#getSignature(67d28bb768a72444).().begincxx . . $ TSignature#begin(e7f351f2dad9f44a).(), p_end = ax->getSignaturecxx . . $ TDLAxiom#getSignature(67d28bb768a72444).().endcxx . . $ TSignature#end(e7f351f2dad9f44a).(); p !=cxx . . $ std/`operator!=`(7e1308a0738ea758). p_end; ++cxx . . $ std/_Rb_tree_const_iterator#operator++(998dce1072ed46d4).p ) |
| 94 | removecxx . . $ SigIndex#remove(a451758bfa4a01cc). ( Basecxx . . $ SigIndex#Base.[cxx . . $ std/map#`operator[]`(bbd415b616967878).*cxx . . $ std/_Rb_tree_const_iterator#`operator*`(ea465e50d690edfe).p], ax ); |
| 95 | // remove from the non-locality |
| 96 | removecxx . . $ SigIndex#remove(a451758bfa4a01cc). ( topNonLocalcxx . . $ SigIndex#topNonLocal., ax ); |
| 97 | removecxx . . $ SigIndex#remove(a451758bfa4a01cc). ( botNonLocalcxx . . $ SigIndex#botNonLocal., ax ); |
| 98 | ++nUnregisteredcxx . . $ SigIndex#nUnregistered.; |
| 99 | } |
| 100 | |
| 101 | public: // interface |
| 102 | /// empty c'tor |
| 103 | explicit SigIndexcxx . . $ SigIndex#SigIndex(924e09907996ba86). ( LocalityCheckercxx . . $ LocalityChecker#* checker ) : Checkercxx . . $ SigIndex#Checker.(checker) {} |
| 104 | |
| 105 | // work with axioms |
| 106 | |
| 107 | /// process an axiom wrt its Used status |
| 108 | void processAxcxx . . $ SigIndex#processAx(ade74f2f8b540a23). ( TDLAxiomcxx . . $ TDLAxiom#* ax ) |
| 109 | { |
| 110 | if ( ax->isUsedcxx . . $ TDLAxiom#isUsed(50ce9a9e25b4a850).() ) |
| 111 | registerAxcxx . . $ SigIndex#registerAx(ade74f2f8b540a23).(ax); |
| 112 | else |
| 113 | unregisterAxcxx . . $ SigIndex#unregisterAx(ade74f2f8b540a23).(ax); |
| 114 | } |
| 115 | /// preprocess given set of axioms |
| 116 | void preprocessOntologycxx . . $ SigIndex#preprocessOntology(b963b3dd7533a896). ( const AxiomVeccxx . . $ AxiomVec#& axioms ) |
| 117 | { |
| 118 | for (TDLAxiomcxx . . $ TDLAxiom#* axiom : axioms) |
| 119 | processAxcxx . . $ SigIndex#processAx(ade74f2f8b540a23).(axiom); |
| 120 | } |
| 121 | /// clear internal structures |
| 122 | void clearcxx . . $ SigIndex#clear(49f6e7a06ebc5aa8). ( void ) |
| 123 | { |
| 124 | Basecxx . . $ SigIndex#Base..clearcxx . . $ std/map#clear(49f6e7a06ebc5aa8).(); |
| 125 | topNonLocalcxx . . $ SigIndex#topNonLocal..clearcxx . . $ std/vector#clear(49f6e7a06ebc5aa8).(); |
| 126 | botNonLocalcxx . . $ SigIndex#botNonLocal..clearcxx . . $ std/vector#clear(49f6e7a06ebc5aa8).(); |
| 127 | } |
| 128 | |
| 129 | // get the set by the index |
| 130 | |
| 131 | /// given an entity, return a set of all axioms that contain this entity in a signature |
| 132 | const AxiomVeccxx . . $ AxiomVec#& getAxiomscxx . . $ SigIndex#getAxioms(cd43868b9f3c5fba). ( const TNamedEntitycxx . . $ TNamedEntity#* entity ) { return Basecxx . . $ SigIndex#Base.[cxx . . $ std/map#`operator[]`(bbd415b616967878).entity]; } |
| 133 | /// get the non-local axioms with top-locality value TOP |
| 134 | const AxiomVeccxx . . $ AxiomVec#& getNonLocalcxx . . $ SigIndex#getNonLocal(78afa40af56be0e7). ( bool top ) const { return top ? topNonLocalcxx . . $ SigIndex#topNonLocal. : botNonLocalcxx . . $ SigIndex#botNonLocal.; } |
| 135 | |
| 136 | // access to statistics |
| 137 | |
| 138 | /// get number of ever processed axioms |
| 139 | unsigned int nProcessedAxcxx . . $ SigIndex#nProcessedAx(ddd8539a2fcdd4ce). ( void ) const { return nRegisteredcxx . . $ SigIndex#nRegistered.; } |
| 140 | /// get number of currently registered axioms |
| 141 | unsigned int nRegisteredAxcxx . . $ SigIndex#nRegisteredAx(ddd8539a2fcdd4ce). ( void ) const { return nRegisteredcxx . . $ SigIndex#nRegistered. - nUnregisteredcxx . . $ SigIndex#nUnregistered.; } |
| 142 | }; // SigIndex |
| 143 | |
| 144 | #endif |