| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#ifndef SIGINDEX_H |
| 21 |
#define SIGINDEX_H |
| 22 |
|
| 23 |
#include <map> |
| 24 |
|
| 25 |
#include "tDLAxiom.h" |
| 26 |
#include "tSignature.h" |
| 27 |
#include "LocalityChecker.h" |
| 28 |
|
| 29 |
class SigIndex |
| 30 |
{ |
| 31 |
public: |
| 32 |
|
| 33 |
typedef AxiomVec::iterator iterator; |
| 34 |
|
| 35 |
typedef AxiomVec::const_iterator const_iterator; |
| 36 |
|
| 37 |
protected: |
| 38 |
|
| 39 |
typedef std::map<const TNamedEntity*, AxiomVec> EntityAxiomMap; |
| 40 |
|
| 41 |
protected: |
| 42 |
|
| 43 |
EntityAxiomMap Base; |
| 44 |
|
| 45 |
LocalityChecker* Checker; |
| 46 |
|
| 47 |
AxiomVec topNonLocal, botNonLocal; |
| 48 |
|
| 49 |
TSignature emptySig; |
| 50 |
|
| 51 |
unsigned int nRegistered = 0; |
| 52 |
|
| 53 |
unsigned int nUnregistered = 0; |
| 54 |
|
| 55 |
protected: |
| 56 |
|
| 57 |
void add ( AxiomVec& axioms, TDLAxiom* ax ) { axioms.push_back(ax); } |
| 58 |
|
| 59 |
void remove ( AxiomVec& axioms, TDLAxiom* ax ) |
| 60 |
{ |
| 61 |
for ( iterator p = axioms.begin(), p_end = axioms.end(); p != p_end; ++p ) |
| 62 |
if ( *p == ax ) |
| 63 |
{ |
| 64 |
*p = axioms.back(); |
| 65 |
axioms.pop_back(); |
| 66 |
break; |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
void checkNonLocal ( TDLAxiom* ax, bool top ) |
| 71 |
{ |
| 72 |
emptySig.setLocality(top); |
| 73 |
Checker->setSignatureValue(emptySig); |
| 74 |
if ( !Checker->local(ax) ) |
| 75 |
add ( top ? topNonLocal : botNonLocal, ax ); |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
void registerAx ( TDLAxiom* ax ) |
| 82 |
{ |
| 83 |
for ( TSignature::iterator p = ax->getSignature().begin(), p_end = ax->getSignature().end(); p != p_end; ++p ) |
| 84 |
add ( Base[*p], ax ); |
| 85 |
|
| 86 |
checkNonLocal ( ax, false ); |
| 87 |
checkNonLocal ( ax, true ); |
| 88 |
++nRegistered; |
| 89 |
} |
| 90 |
|
| 91 |
void unregisterAx ( TDLAxiom* ax ) |
| 92 |
{ |
| 93 |
for ( TSignature::iterator p = ax->getSignature().begin(), p_end = ax->getSignature().end(); p != p_end; ++p ) |
| 94 |
remove ( Base[*p], ax ); |
| 95 |
|
| 96 |
remove ( topNonLocal, ax ); |
| 97 |
remove ( botNonLocal, ax ); |
| 98 |
++nUnregistered; |
| 99 |
} |
| 100 |
|
| 101 |
public: |
| 102 |
|
| 103 |
explicit SigIndex ( LocalityChecker* checker ) : Checker(checker) {} |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
void processAx ( TDLAxiom* ax ) |
| 109 |
{ |
| 110 |
if ( ax->isUsed() ) |
| 111 |
registerAx(ax); |
| 112 |
else |
| 113 |
unregisterAx(ax); |
| 114 |
} |
| 115 |
|
| 116 |
void preprocessOntology ( const AxiomVec& axioms ) |
| 117 |
{ |
| 118 |
for (TDLAxiom* axiom : axioms) |
| 119 |
processAx(axiom); |
| 120 |
} |
| 121 |
|
| 122 |
void clear ( void ) |
| 123 |
{ |
| 124 |
Base.clear(); |
| 125 |
topNonLocal.clear(); |
| 126 |
botNonLocal.clear(); |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
const AxiomVec& getAxioms ( const TNamedEntity* entity ) { return Base[entity]; } |
| 133 |
|
| 134 |
const AxiomVec& getNonLocal ( bool top ) const { return top ? topNonLocal : botNonLocal; } |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
unsigned int nProcessedAx ( void ) const { return nRegistered; } |
| 140 |
|
| 141 |
unsigned int nRegisteredAx ( void ) const { return nRegistered - nUnregistered; } |
| 142 |
}; |
| 143 |
|
| 144 |
#endif |