| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#ifndef TCONCEPT_H |
| 21 |
#define TCONCEPT_H |
| 22 |
|
| 23 |
#include <set> |
| 24 |
|
| 25 |
#include "taxNamEntry.h" |
| 26 |
#include "tNameSet.h" |
| 27 |
#include "tLabeller.h" |
| 28 |
#include "dltree.h" |
| 29 |
#include "dlVertex.h" |
| 30 |
#include "LogicFeature.h" |
| 31 |
|
| 32 |
|
| 33 |
enum CTTag |
| 34 |
{ |
| 35 |
|
| 36 |
cttUnspecified, |
| 37 |
|
| 38 |
cttTrueCompletelyDefined, |
| 39 |
|
| 40 |
cttOrphan, |
| 41 |
|
| 42 |
cttLikeCompletelyDefined, |
| 43 |
|
| 44 |
cttHasNonPrimitiveTS, |
| 45 |
|
| 46 |
cttRegular, |
| 47 |
|
| 48 |
cttNonPrimitive, |
| 49 |
}; |
| 50 |
|
| 51 |
inline char getCTTagName ( CTTag tag ) |
| 52 |
{ |
| 53 |
switch(tag) |
| 54 |
{ |
| 55 |
case cttUnspecified: return 'u'; |
| 56 |
case cttTrueCompletelyDefined: return 'T'; |
| 57 |
case cttOrphan: return 'O'; |
| 58 |
case cttLikeCompletelyDefined: return 'L'; |
| 59 |
case cttHasNonPrimitiveTS: return 'N'; |
| 60 |
case cttRegular: return 'r'; |
| 61 |
case cttNonPrimitive: return 'n'; |
| 62 |
default: return char(); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
class TRole; |
| 67 |
class SaveLoadManager; |
| 68 |
|
| 69 |
|
| 70 |
class TConcept: public ClassifiableEntry |
| 71 |
{ |
| 72 |
private: |
| 73 |
|
| 74 |
TLabeller::LabelType rel = 0; |
| 75 |
|
| 76 |
protected: |
| 77 |
|
| 78 |
typedef std::vector<size_t> ERSet; |
| 79 |
|
| 80 |
typedef std::set<const TRole*> RoleSSet; |
| 81 |
|
| 82 |
public: |
| 83 |
|
| 84 |
typedef ERSet::const_iterator er_iterator; |
| 85 |
|
| 86 |
public: |
| 87 |
|
| 88 |
DLTree* Description = nullptr; |
| 89 |
|
| 90 |
CTTag classTag = cttUnspecified; |
| 91 |
|
| 92 |
unsigned int tsDepth = 0; |
| 93 |
|
| 94 |
|
| 95 |
BipolarPointer pName = bpINVALID; |
| 96 |
|
| 97 |
BipolarPointer pBody = bpINVALID; |
| 98 |
|
| 99 |
|
| 100 |
LogicFeatures posFeatures; |
| 101 |
|
| 102 |
LogicFeatures negFeatures; |
| 103 |
|
| 104 |
|
| 105 |
ERSet erSet; |
| 106 |
|
| 107 |
protected: |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
CTTag determineClassTag ( void ); |
| 112 |
|
| 113 |
|
| 114 |
bool hasSelfInDesc ( const DLTree* p ) const; |
| 115 |
|
| 116 |
DLTree* replaceSelfWithConst ( const DLTree* p ) const; |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
bool addToldSubsumer ( TConcept* p ) |
| 122 |
{ |
| 123 |
if ( p != this ) |
| 124 |
{ |
| 125 |
addParentIfNew(p); |
| 126 |
if ( p->isSingleton() || p->isHasSP() ) |
| 127 |
setHasSP(); |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
return p->isPrimitive(); |
| 132 |
} |
| 133 |
|
| 134 |
bool initToldSubsumers ( const DLTree* desc, RoleSSet& RolesProcessed ); |
| 135 |
|
| 136 |
bool initToldSubsumers ( const DLTree* desc ) |
| 137 |
{ |
| 138 |
RoleSSet RolesProcessed; |
| 139 |
return initToldSubsumers ( desc, RolesProcessed ); |
| 140 |
} |
| 141 |
|
| 142 |
void SearchTSbyRole ( const TRole* R, RoleSSet& RolesProcessed ); |
| 143 |
|
| 144 |
void SearchTSbyRoleAndSupers ( const TRole* R, RoleSSet& RolesProcessed ); |
| 145 |
|
| 146 |
public: |
| 147 |
|
| 148 |
explicit TConcept ( const std::string& name ) |
| 149 |
: ClassifiableEntry (name) |
| 150 |
{ |
| 151 |
setPrimitive(); |
| 152 |
} |
| 153 |
|
| 154 |
TConcept ( const TConcept& ) = delete; |
| 155 |
|
| 156 |
TConcept& operator = ( const TConcept& ) = delete; |
| 157 |
|
| 158 |
~TConcept() override { deleteTree(Description); } |
| 159 |
|
| 160 |
void clear ( void ); |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
void addExtraRule ( size_t index ) |
| 166 |
{ |
| 167 |
erSet.push_back(index); |
| 168 |
|
| 169 |
setCompletelyDefined(false); |
| 170 |
} |
| 171 |
|
| 172 |
bool hasExtraRules ( void ) const { return !erSet.empty(); } |
| 173 |
|
| 174 |
er_iterator er_begin ( void ) const { return erSet.begin(); } |
| 175 |
|
| 176 |
er_iterator er_end ( void ) const { return erSet.end(); } |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
CTTag getClassTag ( void ) const { return classTag; } |
| 182 |
|
| 183 |
CTTag getClassTag ( void ) |
| 184 |
{ |
| 185 |
if ( classTag == cttUnspecified ) |
| 186 |
classTag = determineClassTag(); |
| 187 |
return classTag; |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
void addDesc ( DLTree* Desc ); |
| 194 |
|
| 195 |
bool hasSelfInDesc ( void ) const { return hasSelfInDesc(Description); } |
| 196 |
|
| 197 |
void removeSelfFromDescription ( void ) |
| 198 |
{ |
| 199 |
if ( hasSelfInDesc() ) |
| 200 |
{ |
| 201 |
DLTree* desc = Description; |
| 202 |
Description = replaceSelfWithConst(desc); |
| 203 |
deleteTree(desc); |
| 204 |
} |
| 205 |
initToldSubsumers(); |
| 206 |
} |
| 207 |
|
| 208 |
void removeDescription ( void ) |
| 209 |
{ |
| 210 |
deleteTree(Description); |
| 211 |
Description = nullptr; |
| 212 |
} |
| 213 |
|
| 214 |
bool canInitNonPrim ( DLTree* desc ) |
| 215 |
{ |
| 216 |
if ( Description == nullptr ) |
| 217 |
return true; |
| 218 |
if ( isNonPrimitive() && equalTrees(Description,desc) ) |
| 219 |
return true; |
| 220 |
return false; |
| 221 |
} |
| 222 |
|
| 223 |
DLTree* makeNonPrimitive ( DLTree* desc ) |
| 224 |
{ |
| 225 |
DLTree* ret = Description; |
| 226 |
Description = desc; |
| 227 |
setPrimitive(false); |
| 228 |
return ret; |
| 229 |
} |
| 230 |
|
| 231 |
|
| 232 |
virtual void initToldSubsumers ( void ) |
| 233 |
{ |
| 234 |
toldSubsumers.clear(); |
| 235 |
clearHasSP(); |
| 236 |
|
| 237 |
if ( isPrimitive() && Description && Description->Element() == TOP ) |
| 238 |
removeDescription(); |
| 239 |
|
| 240 |
bool CD = !hasExtraRules() && isPrimitive(); |
| 241 |
if ( Description != nullptr ) |
| 242 |
CD &= initToldSubsumers(Description); |
| 243 |
setCompletelyDefined(CD); |
| 244 |
} |
| 245 |
|
| 246 |
void setToldTop ( TConcept* top ) |
| 247 |
{ |
| 248 |
if ( Description == nullptr && !hasToldSubsumers() ) |
| 249 |
addParent(top); |
| 250 |
} |
| 251 |
|
| 252 |
unsigned int calculateTSDepth ( void ); |
| 253 |
|
| 254 |
|
| 255 |
BipolarPointer resolveId ( void ) const; |
| 256 |
|
| 257 |
|
| 258 |
FPP_ADD_FLAG(Primitive,0x10); |
| 259 |
|
| 260 |
FPP_ADD_FLAG(HasSP,0x20); |
| 261 |
|
| 262 |
FPP_ADD_FLAG(Nominal,0x40); |
| 263 |
|
| 264 |
FPP_ADD_FLAG(Singleton,0x80); |
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
bool isNonPrimitive ( void ) const { return !isPrimitive(); } |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
bool isRelevant ( const TLabeller& lab ) const { return lab.isLabelled(rel); } |
| 275 |
|
| 276 |
void setRelevant ( const TLabeller& lab ) { lab.set(rel); } |
| 277 |
|
| 278 |
void dropRelevant ( const TLabeller& lab ) { lab.clear(rel); } |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
void Save ( SaveLoadManager& m ) const override; |
| 284 |
|
| 285 |
void Load ( SaveLoadManager& m ) override; |
| 286 |
}; |
| 287 |
|
| 288 |
|
| 289 |
class TSDepthCompare |
| 290 |
{ |
| 291 |
public: |
| 292 |
bool operator() ( const TConcept* p, const TConcept* q ) const |
| 293 |
{ return p->tsDepth < q->tsDepth; } |
| 294 |
}; |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
inline BipolarPointer TConcept :: resolveId ( void ) const |
| 301 |
{ |
| 302 |
|
| 303 |
if ( pName == bpINVALID ) |
| 304 |
return pBody; |
| 305 |
|
| 306 |
if ( isSynonym() ) |
| 307 |
return resolveSynonym(this)->resolveId(); |
| 308 |
|
| 309 |
return pName; |
| 310 |
} |
| 311 |
|
| 312 |
#endif |