| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#ifndef MODELCACHEIAN_H |
| 21 |
#define MODELCACHEIAN_H |
| 22 |
|
| 23 |
#include "modelCacheSingleton.h" |
| 24 |
#include "dlCompletionTree.h" |
| 25 |
#include "dlDag.h" |
| 26 |
#include "tSetAsTree.h" |
| 27 |
|
| 28 |
class SaveLoadManager; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
class modelCacheIan: public modelCacheInterface |
| 34 |
{ |
| 35 |
|
| 36 |
friend class DLConceptTaxonomy; |
| 37 |
protected: |
| 38 |
|
| 39 |
typedef TSetAsTree IndexSet; |
| 40 |
|
| 41 |
typedef DlCompletionTree::const_label_iterator l_iterator; |
| 42 |
|
| 43 |
typedef DlCompletionTree::const_edge_iterator e_iterator; |
| 44 |
|
| 45 |
protected: |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
IndexSet posDConcepts; |
| 50 |
|
| 51 |
IndexSet posNConcepts; |
| 52 |
|
| 53 |
IndexSet negDConcepts; |
| 54 |
|
| 55 |
IndexSet negNConcepts; |
| 56 |
#ifdef RKG_USE_SIMPLE_RULES |
| 57 |
|
| 58 |
IndexSet extraDConcepts; |
| 59 |
|
| 60 |
IndexSet extraNConcepts; |
| 61 |
#endif |
| 62 |
|
| 63 |
IndexSet existsRoles; |
| 64 |
|
| 65 |
IndexSet forallRoles; |
| 66 |
|
| 67 |
IndexSet funcRoles; |
| 68 |
|
| 69 |
|
| 70 |
modelCacheState curState = csValid; |
| 71 |
|
| 72 |
protected: |
| 73 |
|
| 74 |
void logCacheEntryImpl ( void ) const override; |
| 75 |
|
| 76 |
void processConcept ( const DLVertex& cur, bool pos, bool det ); |
| 77 |
|
| 78 |
void processAutomaton ( const DLVertex& cur ); |
| 79 |
|
| 80 |
void processLabelInterval ( const DLDag& DLHeap, l_iterator start, l_iterator end ) |
| 81 |
{ |
| 82 |
for ( l_iterator p = start; p != end; ++p ) |
| 83 |
processConcept ( DLHeap[*p], isPositive(p->bp()), p->getDep().empty() ); |
| 84 |
} |
| 85 |
|
| 86 |
void initCacheByLabel ( const DLDag& DLHeap, const DlCompletionTree* pCT ) |
| 87 |
{ |
| 88 |
processLabelInterval ( DLHeap, pCT->beginl_sc(), pCT->endl_sc() ); |
| 89 |
processLabelInterval ( DLHeap, pCT->beginl_cc(), pCT->endl_cc() ); |
| 90 |
} |
| 91 |
|
| 92 |
void addRoleToCache ( const TRole* R ) |
| 93 |
{ |
| 94 |
existsRoles.insert(R->index()); |
| 95 |
if ( R->isTopFunc() ) |
| 96 |
funcRoles.insert(R->index()); |
| 97 |
} |
| 98 |
|
| 99 |
void addExistsRole ( const TRole* R ) |
| 100 |
{ |
| 101 |
addRoleToCache(R); |
| 102 |
for ( auto sup: R->ancestors() ) |
| 103 |
addRoleToCache(sup); |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
IndexSet& getDConcepts ( bool pos ) { return pos ? posDConcepts : negDConcepts; } |
| 110 |
|
| 111 |
IndexSet& getNConcepts ( bool pos ) { return pos ? posNConcepts : negNConcepts; } |
| 112 |
|
| 113 |
const IndexSet& getDConcepts ( bool pos ) const { return pos ? posDConcepts : negDConcepts; } |
| 114 |
|
| 115 |
const IndexSet& getNConcepts ( bool pos ) const { return pos ? posNConcepts : negNConcepts; } |
| 116 |
#ifdef RKG_USE_SIMPLE_RULES |
| 117 |
|
| 118 |
IndexSet& getExtra ( bool det ) { return det ? extraDConcepts : extraNConcepts; } |
| 119 |
|
| 120 |
const IndexSet& getExtra ( bool det ) const { return det ? extraDConcepts : extraNConcepts; } |
| 121 |
#endif |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
modelCacheState isMergeableSingleton ( BipolarPointer bp ) const; |
| 127 |
|
| 128 |
modelCacheState isMergeableIan ( const modelCacheIan* p ) const; |
| 129 |
|
| 130 |
void mergeSingleton ( BipolarPointer bp ); |
| 131 |
|
| 132 |
void mergeIan ( const modelCacheIan* p ); |
| 133 |
|
| 134 |
public: |
| 135 |
|
| 136 |
modelCacheIan ( const DLDag& heap, const DlCompletionTree* p, bool flagNominals, unsigned int nC, unsigned int nR ) |
| 137 |
: modelCacheInterface(flagNominals) |
| 138 |
, posDConcepts(nC) |
| 139 |
, posNConcepts(nC) |
| 140 |
, negDConcepts(nC) |
| 141 |
, negNConcepts(nC) |
| 142 |
# ifdef RKG_USE_SIMPLE_RULES |
| 143 |
, extraDConcepts(nC) |
| 144 |
, extraNConcepts(nC) |
| 145 |
# endif |
| 146 |
, existsRoles(nR) |
| 147 |
, forallRoles(nR) |
| 148 |
, funcRoles(nR) |
| 149 |
{ |
| 150 |
initCacheByLabel ( heap, p ); |
| 151 |
initRolesFromArcs(p); |
| 152 |
} |
| 153 |
|
| 154 |
modelCacheIan ( bool flagNominals, unsigned int nC, unsigned int nR ) |
| 155 |
: modelCacheInterface(flagNominals) |
| 156 |
, posDConcepts(nC) |
| 157 |
, posNConcepts(nC) |
| 158 |
, negDConcepts(nC) |
| 159 |
, negNConcepts(nC) |
| 160 |
# ifdef RKG_USE_SIMPLE_RULES |
| 161 |
, extraDConcepts(nC) |
| 162 |
, extraNConcepts(nC) |
| 163 |
# endif |
| 164 |
, existsRoles(nR) |
| 165 |
, forallRoles(nR) |
| 166 |
, funcRoles(nR) |
| 167 |
{} |
| 168 |
|
| 169 |
modelCacheIan ( const modelCacheIan& m ) |
| 170 |
: modelCacheInterface(m.hasNominalNode) |
| 171 |
, posDConcepts(m.posDConcepts) |
| 172 |
, posNConcepts(m.posNConcepts) |
| 173 |
, negDConcepts(m.negDConcepts) |
| 174 |
, negNConcepts(m.negNConcepts) |
| 175 |
# ifdef RKG_USE_SIMPLE_RULES |
| 176 |
, extraDConcepts(m.extraDConcepts) |
| 177 |
, extraNConcepts(m.extraNConcepts) |
| 178 |
# endif |
| 179 |
, existsRoles(m.existsRoles) |
| 180 |
, forallRoles(m.forallRoles) |
| 181 |
, funcRoles(m.funcRoles) |
| 182 |
, curState(m.getState()) |
| 183 |
{} |
| 184 |
|
| 185 |
modelCacheIan* clone ( void ) const { return new modelCacheIan(*this); } |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
modelCacheState getState ( void ) const override { return curState; } |
| 191 |
|
| 192 |
|
| 193 |
void initRolesFromArcs ( const DlCompletionTree* pCT ) |
| 194 |
{ |
| 195 |
for ( e_iterator q = pCT->begin(), q_end = pCT->end(); q < q_end; ++q ) |
| 196 |
if ( !(*q)->isIBlocked() ) |
| 197 |
addExistsRole ( (*q)->getRole() ); |
| 198 |
|
| 199 |
curState = csValid; |
| 200 |
} |
| 201 |
|
| 202 |
void clear ( void ); |
| 203 |
|
| 204 |
|
| 205 |
modelCacheState canMerge ( const modelCacheInterface* cache ) const override; |
| 206 |
|
| 207 |
modelCacheState merge ( const modelCacheInterface* cache ); |
| 208 |
|
| 209 |
|
| 210 |
bool shallowCache ( void ) const override { return existsRoles.empty(); } |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
void Save ( SaveLoadManager& m ) const; |
| 218 |
|
| 219 |
void Load ( SaveLoadManager& m ); |
| 220 |
}; |
| 221 |
|
| 222 |
#endif |