1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
/* This file is part of the FaCT++ DL reasoner
Copyright (C) 2011-2015 Dmitry Tsarkov and The University of Manchester
Copyright (C) 2015-2016 Dmitry Tsarkov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef SIGINDEX_H
#define SIGINDEX_H
#include "tDLAxiom.h"
#include "tSignature.h"
#include "LocalityChecker.h"
class SigIndex
{
public: // types
/// RW iterator over set of axioms
typedef AxiomVec::iterator iterator;
/// RO iterator over set of axioms
typedef AxiomVec::const_iterator const_iterator;
protected: // types
/// map between entities and axioms that contains them in their signature
typedef std::map<const TNamedEntity*, AxiomVec> EntityAxiomMap;
protected: // members
/// map itself
EntityAxiomMap Base;
/// locality checker
LocalityChecker* Checker;
/// sets of axioms non-local wrt the empty signature
AxiomVec topNonLocal, botNonLocal;
/// empty signature to test the non-locality
TSignature emptySig;
/// number of registered axioms
unsigned int nRegistered;
/// number of registered axioms
unsigned int nUnregistered;
protected: // methods
/// add an axiom AX to an axiom set AXIOMS
void add ( AxiomVec& axioms, TDLAxiom* ax ) { axioms.push_back(ax); }
/// remove an axiom AX from an axiom set AXIOMS
void remove ( AxiomVec& axioms, TDLAxiom* ax )
{
for ( iterator p = axioms.begin(), p_end = axioms.end(); p != p_end; ++p )
if ( *p == ax )
{
*p = axioms.back();
axioms.pop_back();
break;
}
}
/// add axiom AX to the non-local set with top-locality value TOP
void checkNonLocal ( TDLAxiom* ax, bool top )
{
emptySig.setLocality(top);
Checker->setSignatureValue(emptySig);
if ( !Checker->local(ax) )
add ( top ? topNonLocal : botNonLocal, ax );
}
// work with axioms
/// register an axiom
void registerAx ( TDLAxiom* ax )
{
for ( TSignature::iterator p = ax->getSignature().begin(), p_end = ax->getSignature().end(); p != p_end; ++p )
add ( Base[*p], ax );
// check whether the axiom is non-local
checkNonLocal ( ax, /*top=*/false );
checkNonLocal ( ax, /*top=*/true );
++nRegistered;
}
/// unregister an axiom AX
void unregisterAx ( TDLAxiom* ax )
{
for ( TSignature::iterator p = ax->getSignature().begin(), p_end = ax->getSignature().end(); p != p_end; ++p )
remove ( Base[*p], ax );
// remove from the non-locality
remove ( topNonLocal, ax );
remove ( botNonLocal, ax );
++nUnregistered;
}
public: // interface
/// empty c'tor
SigIndex ( LocalityChecker* checker ) : Checker(checker), nRegistered(0), nUnregistered(0) {}
/// empty d'tor
~SigIndex ( void ) {}
// work with axioms
/// process an axiom wrt its Used status
void processAx ( TDLAxiom* ax )
{
if ( ax->isUsed() )
registerAx(ax);
else
unregisterAx(ax);
}
/// preprocess given set of axioms
void preprocessOntology ( const AxiomVec& axioms )
{
for ( const_iterator p = axioms.begin(), p_end = axioms.end(); p != p_end; ++p )
processAx(*p);
}
/// clear internal structures
void clear ( void )
{
Base.clear();
topNonLocal.clear();
botNonLocal.clear();
}
// get the set by the index
/// given an entity, return a set of all axioms that tontain this entity in a signature
const AxiomVec& getAxioms ( const TNamedEntity* entity ) { return Base[entity]; }
/// get the non-local axioms with top-locality value TOP
const AxiomVec& getNonLocal ( bool top ) const { return top ? topNonLocal : botNonLocal; }
// access to statistics
/// get number of ever processed axioms
unsigned int nProcessedAx ( void ) const { return nRegistered; }
/// get number of currently registered axioms
unsigned int nRegisteredAx ( void ) const { return nRegistered - nUnregistered; }
}; // SigIndex
#endif
|