| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#ifndef TONTOLOGY_H |
| 21 |
#define TONTOLOGY_H |
| 22 |
|
| 23 |
#include <vector> |
| 24 |
|
| 25 |
#include "globaldef.h" |
| 26 |
#include "tDLAxiom.h" |
| 27 |
#include "tExpressionManager.h" |
| 28 |
|
| 29 |
|
| 30 |
class TOntology |
| 31 |
{ |
| 32 |
public: |
| 33 |
|
| 34 |
typedef AxiomVec::iterator iterator; |
| 35 |
|
| 36 |
protected: |
| 37 |
|
| 38 |
AxiomVec Axioms; |
| 39 |
|
| 40 |
AxiomVec Retracted; |
| 41 |
|
| 42 |
TExpressionManager EManager; |
| 43 |
|
| 44 |
unsigned int axiomId = 0; |
| 45 |
|
| 46 |
size_t axiomToProcess = 0; |
| 47 |
|
| 48 |
bool changed = false; |
| 49 |
|
| 50 |
public: |
| 51 |
|
| 52 |
TOntology() = default; |
| 53 |
|
| 54 |
~TOntology() { clear(); } |
| 55 |
|
| 56 |
|
| 57 |
bool isChanged ( void ) const { return changed; } |
| 58 |
|
| 59 |
void setProcessed ( void ) { axiomToProcess = Axioms.size(); Retracted.clear(); changed = false; } |
| 60 |
|
| 61 |
|
| 62 |
TDLAxiom* add ( TDLAxiom* p ) |
| 63 |
{ |
| 64 |
p->setId(++axiomId); |
| 65 |
Axioms.push_back(p); |
| 66 |
changed = true; |
| 67 |
return p; |
| 68 |
} |
| 69 |
|
| 70 |
void retract ( TDLAxiom* p ) |
| 71 |
{ |
| 72 |
|
| 73 |
{ |
| 74 |
changed = true; |
| 75 |
p->setUsed(false); |
| 76 |
Retracted.push_back(p); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
void clearModuleInfo ( void ) |
| 81 |
{ |
| 82 |
for ( iterator p = Axioms.begin(), p_end = Axioms.end(); p < p_end; ++p ) |
| 83 |
(*p)->setInModule(false); |
| 84 |
} |
| 85 |
|
| 86 |
void safeClear ( void ) { Axioms.clear(); } |
| 87 |
|
| 88 |
void clearAxioms ( void ) |
| 89 |
{ |
| 90 |
for ( iterator p = Axioms.begin(), p_end = Axioms.end(); p < p_end; ++p ) |
| 91 |
delete *p; |
| 92 |
safeClear(); |
| 93 |
} |
| 94 |
|
| 95 |
void clear ( void ) |
| 96 |
{ |
| 97 |
clearAxioms(); |
| 98 |
Retracted.clear(); |
| 99 |
EManager.clear(); |
| 100 |
axiomToProcess = 0; |
| 101 |
changed = false; |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
TExpressionManager* getExpressionManager ( void ) { return &EManager; } |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
AxiomVec& getAxioms ( void ) { return Axioms; } |
| 111 |
|
| 112 |
const AxiomVec& getAxioms ( void ) const { return Axioms; } |
| 113 |
|
| 114 |
|
| 115 |
iterator begin ( void ) { return Axioms.begin(); } |
| 116 |
|
| 117 |
iterator end ( void ) { return Axioms.end(); } |
| 118 |
|
| 119 |
iterator beginUnprocessed ( void ) { return Axioms.begin()+(long)axiomToProcess; } |
| 120 |
|
| 121 |
iterator endProcessed ( void ) { return beginUnprocessed(); } |
| 122 |
|
| 123 |
iterator beginRetracted ( void ) { return Retracted.begin(); } |
| 124 |
|
| 125 |
iterator endRetracted ( void ) { return Retracted.end(); } |
| 126 |
|
| 127 |
TDLAxiom* operator [] ( size_t i ) { return Axioms[i]; } |
| 128 |
|
| 129 |
|
| 130 |
void visitOntology ( DLAxiomVisitor& visitor ) |
| 131 |
{ |
| 132 |
for ( TOntology::iterator p = begin(), p_end = end(); p < p_end; ++p ) |
| 133 |
if ( likely((*p)->isUsed()) ) |
| 134 |
(*p)->accept(visitor); |
| 135 |
} |
| 136 |
|
| 137 |
size_t size ( void ) const { return Axioms.size(); } |
| 138 |
|
| 139 |
TSignature getSignature ( void ) |
| 140 |
{ |
| 141 |
TSignature sig; |
| 142 |
for ( iterator p = begin(), p_end = end(); p != p_end; ++p ) |
| 143 |
if ( likely((*p)->isUsed()) ) |
| 144 |
sig.add((*p)->getSignature()); |
| 145 |
return sig; |
| 146 |
} |
| 147 |
}; |
| 148 |
|
| 149 |
#endif |