| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#ifndef KERNEL_H |
| 21 |
#define KERNEL_H |
| 22 |
|
| 23 |
#include <string> |
| 24 |
|
| 25 |
#include "fpp_assert.h" |
| 26 |
#include "eFPPInconsistentKB.h" |
| 27 |
#include "dlTBox.h" |
| 28 |
#include "ifOptions.h" |
| 29 |
#include "DLConceptTaxonomy.h" |
| 30 |
#include "tExpressionTranslator.h" |
| 31 |
#include "tOntology.h" |
| 32 |
#include "KnowledgeExplorer.h" |
| 33 |
#include "tOntologyAtom.h" |
| 34 |
#include "ModuleType.h" |
| 35 |
#include "ModuleMethod.h" |
| 36 |
|
| 37 |
class OntologyBasedModularizer; |
| 38 |
class AtomicDecomposer; |
| 39 |
class TJNICache; |
| 40 |
class SaveLoadManager; |
| 41 |
|
| 42 |
class ReasoningKernel |
| 43 |
{ |
| 44 |
public: |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
typedef const TDLExpression TExpr; |
| 66 |
|
| 67 |
typedef const TDLConceptExpression TConceptExpr; |
| 68 |
|
| 69 |
typedef const TDLIndividualExpression TIndividualExpr; |
| 70 |
|
| 71 |
typedef const TDLRoleExpression TRoleExpr; |
| 72 |
|
| 73 |
typedef const TDLObjectRoleComplexExpression TORoleComplexExpr; |
| 74 |
|
| 75 |
typedef const TDLObjectRoleExpression TORoleExpr; |
| 76 |
|
| 77 |
typedef const TDLDataRoleExpression TDRoleExpr; |
| 78 |
|
| 79 |
typedef const TDLDataExpression TDataExpr; |
| 80 |
|
| 81 |
typedef TDLDataTypeExpression TDataTypeExpr; |
| 82 |
|
| 83 |
typedef const TDLDataValue TDataValueExpr; |
| 84 |
|
| 85 |
typedef const TDLFacetExpression TFacetExpr; |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
typedef std::vector<const TNamedEntry*> NamesVector; |
| 91 |
|
| 92 |
typedef NamesVector IndividualSet; |
| 93 |
|
| 94 |
|
| 95 |
typedef TRelatedMap::CIVec CIVec; |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
typedef KnowledgeExplorer::TCGNode TCGNode; |
| 101 |
|
| 102 |
typedef KnowledgeExplorer::TCGNodeVec TCGNodeVec; |
| 103 |
|
| 104 |
typedef KnowledgeExplorer::TCGRoleSet TCGRoleSet; |
| 105 |
|
| 106 |
typedef KnowledgeExplorer::TCGItemVec TCGItemVec; |
| 107 |
|
| 108 |
protected: |
| 109 |
|
| 110 |
typedef const std::vector<const TDLExpression*> TExprVec; |
| 111 |
|
| 112 |
typedef TBox::NameSigMap NameSigMap; |
| 113 |
|
| 114 |
public: |
| 115 |
|
| 116 |
ifOptionSet KernelOptions; |
| 117 |
|
| 118 |
private: |
| 119 |
static const char* Version; |
| 120 |
static const char* SupportedDL; |
| 121 |
static const char* Copyright; |
| 122 |
static const char* ReleaseDate; |
| 123 |
|
| 124 |
static const char* InternalStateFileHeader; |
| 125 |
|
| 126 |
protected: |
| 127 |
|
| 128 |
enum cacheStatus { csEmpty, csSat, csClassified }; |
| 129 |
|
| 130 |
protected: |
| 131 |
|
| 132 |
TBox* pTBox = nullptr; |
| 133 |
|
| 134 |
TOntology Ontology; |
| 135 |
|
| 136 |
TExpressionTranslator* pET = nullptr; |
| 137 |
|
| 138 |
NameSigMap Name2Sig; |
| 139 |
|
| 140 |
TSignature OntoSig; |
| 141 |
|
| 142 |
AxiomVec TraceVec; |
| 143 |
|
| 144 |
KnowledgeExplorer* KE = nullptr; |
| 145 |
|
| 146 |
AtomicDecomposer* AD = nullptr; |
| 147 |
|
| 148 |
OntologyBasedModularizer* ModSyn = nullptr; |
| 149 |
|
| 150 |
OntologyBasedModularizer* ModSynCount = nullptr; |
| 151 |
|
| 152 |
OntologyBasedModularizer* ModSem = nullptr; |
| 153 |
|
| 154 |
AxiomVec Result; |
| 155 |
|
| 156 |
TJNICache* JNICache = nullptr; |
| 157 |
|
| 158 |
SaveLoadManager* pSLManager = nullptr; |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
std::string TopORoleName; |
| 164 |
|
| 165 |
std::string BotORoleName; |
| 166 |
|
| 167 |
std::string TopDRoleName; |
| 168 |
|
| 169 |
std::string BotDRoleName; |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
TProgressMonitor* pMonitor = nullptr; |
| 175 |
|
| 176 |
unsigned long OpTimeout = 0; |
| 177 |
|
| 178 |
bool verboseOutput = false; |
| 179 |
|
| 180 |
bool useUndefinedNames = true; |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
enum cacheStatus cacheLevel = csEmpty; |
| 186 |
|
| 187 |
TConceptExpr* cachedQuery = nullptr; |
| 188 |
|
| 189 |
DLTree* cachedQueryTree = nullptr; |
| 190 |
|
| 191 |
TConcept* cachedConcept = nullptr; |
| 192 |
|
| 193 |
TaxonomyVertex* cachedVertex = nullptr; |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
bool reasoningFailed = false; |
| 199 |
|
| 200 |
bool NeedTracing = false; |
| 201 |
|
| 202 |
bool ignoreExprCache = false; |
| 203 |
|
| 204 |
bool useIncrementalReasoning = false; |
| 205 |
|
| 206 |
bool dumpOntology = false; |
| 207 |
|
| 208 |
protected: |
| 209 |
|
| 210 |
|
| 211 |
bool initOptions ( void ); |
| 212 |
|
| 213 |
|
| 214 |
KBStatus getStatus ( void ) const |
| 215 |
{ |
| 216 |
if ( pTBox == nullptr ) |
| 217 |
return kbEmpty; |
| 218 |
|
| 219 |
if ( Ontology.isChanged() ) |
| 220 |
return kbLoading; |
| 221 |
return pTBox->getStatus(); |
| 222 |
} |
| 223 |
|
| 224 |
void processKB ( KBStatus status ); |
| 225 |
|
| 226 |
void ClassifyOrLoad ( bool needIndividuals ); |
| 227 |
|
| 228 |
|
| 229 |
DLTree* e ( const TExpr* expr ) |
| 230 |
{ |
| 231 |
fpp_assert ( pET != nullptr ); |
| 232 |
expr->accept(*pET); |
| 233 |
return *pET; |
| 234 |
} |
| 235 |
|
| 236 |
DLTree* getFreshFiller ( const TRole* R ) |
| 237 |
{ |
| 238 |
if ( R->isDataRole() ) |
| 239 |
return getTBox()->getDataTypeCenter().getFreshDataType(); |
| 240 |
else |
| 241 |
return getTBox()->getFreshConcept(); |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
void clearQueryCache ( void ) |
| 250 |
{ |
| 251 |
|
| 252 |
cachedQuery = nullptr; |
| 253 |
deleteTree(cachedQueryTree); |
| 254 |
cachedQueryTree = nullptr; |
| 255 |
|
| 256 |
cacheLevel = csEmpty; |
| 257 |
cachedConcept = nullptr; |
| 258 |
cachedVertex = nullptr; |
| 259 |
} |
| 260 |
|
| 261 |
bool isCacheEmpty ( void ) const { return (cachedQuery == nullptr) && (cachedQueryTree == nullptr); } |
| 262 |
|
| 263 |
void setQueryCache ( TConceptExpr* query ) { fpp_assert(isCacheEmpty()); cachedQuery = query; } |
| 264 |
|
| 265 |
void setQueryCache ( DLTree* query ) { fpp_assert(isCacheEmpty()); cachedQueryTree = query; } |
| 266 |
|
| 267 |
bool checkQueryCache ( TConceptExpr* query ) const { return ignoreExprCache ? false : cachedQuery == query; } |
| 268 |
|
| 269 |
bool checkQueryCache ( DLTree* query ) const { return ignoreExprCache ? false : equalTrees ( cachedQueryTree, query ); } |
| 270 |
|
| 271 |
void setQueryConcept ( const DLTree* query ) |
| 272 |
{ |
| 273 |
cachedConcept = isCN(query) ? getTBox()->getCI(query) : getTBox()->createQueryConcept(query); |
| 274 |
fpp_assert ( cachedConcept != nullptr ); |
| 275 |
|
| 276 |
if ( !isValid(cachedConcept->pName) ) |
| 277 |
getTBox()->preprocessQueryConcept(cachedConcept); |
| 278 |
} |
| 279 |
|
| 280 |
void classifyQuery ( void ); |
| 281 |
|
| 282 |
void setUpSatCache ( DLTree* query ); |
| 283 |
|
| 284 |
void setUpCache ( TConceptExpr* query, cacheStatus level ); |
| 285 |
|
| 286 |
void initCacheAndFlags ( void ) |
| 287 |
{ |
| 288 |
clearQueryCache(); |
| 289 |
NeedTracing = false; |
| 290 |
} |
| 291 |
|
| 292 |
|
| 293 |
CIVec buildRelatedCache ( TIndividual* I, const TRole* R ); |
| 294 |
|
| 295 |
const CIVec& getRelated ( TIndividual* I, const TRole* R ) |
| 296 |
{ |
| 297 |
if ( !I->hasRelatedCache(R) ) |
| 298 |
I->setRelatedCache ( R, buildRelatedCache ( I, R ) ); |
| 299 |
return I->getRelatedCache(R); |
| 300 |
} |
| 301 |
|
| 302 |
|
| 303 |
TDLRoleExpression* Role ( const TRole* R ) |
| 304 |
{ |
| 305 |
if ( unlikely(R->isDataRole()) ) |
| 306 |
return getExpressionManager()->DataRole(R->getName()); |
| 307 |
else |
| 308 |
return getExpressionManager()->ObjectRole(R->getName()); |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
bool checkSatTree ( DLTree* C ) |
| 317 |
{ |
| 318 |
if ( unlikely(C->Element().getToken() == TOP) ) |
| 319 |
{ |
| 320 |
deleteTree(C); |
| 321 |
return true; |
| 322 |
} |
| 323 |
if ( unlikely(C->Element().getToken() == BOTTOM) ) |
| 324 |
{ |
| 325 |
deleteTree(C); |
| 326 |
return false; |
| 327 |
} |
| 328 |
setUpSatCache(C); |
| 329 |
return getTBox()->isSatisfiable(cachedConcept); |
| 330 |
} |
| 331 |
|
| 332 |
bool checkSat ( const TConceptExpr* C ) |
| 333 |
{ |
| 334 |
setUpCache ( C, csSat ); |
| 335 |
return getTBox()->isSatisfiable(cachedConcept); |
| 336 |
} |
| 337 |
|
| 338 |
bool checkSub ( TConcept* C, TConcept* D ); |
| 339 |
|
| 340 |
static bool isNameOrConst ( const TConceptExpr* C ) |
| 341 |
{ |
| 342 |
return likely ( dynamic_cast<const TDLConceptName*>(C) != nullptr ) || |
| 343 |
unlikely ( dynamic_cast<const TDLConceptTop*>(C) != nullptr ) || |
| 344 |
unlikely ( dynamic_cast<const TDLConceptBottom*>(C) != nullptr ); |
| 345 |
} |
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
bool checkFunctionality ( TRole* R ) |
| 351 |
{ |
| 352 |
|
| 353 |
DLTree* tmp = createSNFExists ( createRole(R), createSNFNot(getFreshFiller(R)) ); |
| 354 |
tmp = createSNFAnd ( tmp, createSNFExists ( createRole(R), getFreshFiller(R) ) ); |
| 355 |
return !checkSatTree(tmp); |
| 356 |
} |
| 357 |
|
| 358 |
bool getFunctionality ( TRole* R ) |
| 359 |
{ |
| 360 |
if ( !R->isFunctionalityKnown() ) |
| 361 |
R->setFunctional(checkFunctionality(R)); |
| 362 |
return R->isFunctional(); |
| 363 |
} |
| 364 |
|
| 365 |
bool checkTransitivity ( DLTree* R ) |
| 366 |
{ |
| 367 |
|
| 368 |
DLTree* tmp = createSNFExists ( clone(R), createSNFNot(getTBox()->getFreshConcept()) ); |
| 369 |
tmp = createSNFExists ( clone(R), tmp ); |
| 370 |
tmp = createSNFAnd ( tmp, createSNFForall ( R, getTBox()->getFreshConcept() ) ); |
| 371 |
return !checkSatTree(tmp); |
| 372 |
} |
| 373 |
|
| 374 |
bool checkSymmetry ( DLTree* R ) |
| 375 |
{ |
| 376 |
|
| 377 |
DLTree* tmp = createSNFForall ( clone(R), createSNFNot(getTBox()->getFreshConcept()) ); |
| 378 |
tmp = createSNFAnd ( getTBox()->getFreshConcept(), createSNFExists ( R, tmp ) ); |
| 379 |
return !checkSatTree(tmp); |
| 380 |
} |
| 381 |
|
| 382 |
bool checkReflexivity ( DLTree* R ) |
| 383 |
{ |
| 384 |
|
| 385 |
DLTree* tmp = createSNFForall ( R, createSNFNot(getTBox()->getFreshConcept()) ); |
| 386 |
tmp = createSNFAnd ( getTBox()->getFreshConcept(), tmp ); |
| 387 |
return !checkSatTree(tmp); |
| 388 |
} |
| 389 |
|
| 390 |
bool checkRoleSubsumption ( TRole* R, TRole* S ) |
| 391 |
{ |
| 392 |
if ( unlikely ( R->isDataRole() != S->isDataRole() ) ) |
| 393 |
return false; |
| 394 |
|
| 395 |
DLTree* tmp = createSNFForall ( createRole(S), createSNFNot(getFreshFiller(S)) ); |
| 396 |
tmp = createSNFAnd ( createSNFExists ( createRole(R), getFreshFiller(R) ), tmp ); |
| 397 |
return !checkSatTree(tmp); |
| 398 |
} |
| 399 |
|
| 400 |
bool checkSubChain ( const TExprVec& Chain, TRole* R ) |
| 401 |
{ |
| 402 |
|
| 403 |
DLTree* tmp = createSNFNot(getTBox()->getFreshConcept()); |
| 404 |
for ( TExprVec::const_reverse_iterator p = Chain.rbegin(), p_end = Chain.rend(); p != p_end; ++p ) |
| 405 |
if ( TORoleExpr* Ri = dynamic_cast<TORoleExpr*>(*p) ) |
| 406 |
{ |
| 407 |
TRole* S = getRole ( Ri, "Role expression expected in chain of isSubChain()" ); |
| 408 |
if ( unlikely(S->isBottom()) ) |
| 409 |
{ |
| 410 |
deleteTree(tmp); |
| 411 |
return true; |
| 412 |
} |
| 413 |
tmp = createSNFExists ( createRole(S), tmp ); |
| 414 |
} |
| 415 |
else |
| 416 |
throw EFaCTPlusPlus("Role expression expected in the role chain construct"); |
| 417 |
|
| 418 |
tmp = createSNFAnd ( tmp, createSNFForall ( createEntry(RNAME,R), getTBox()->getFreshConcept() ) ); |
| 419 |
return !checkSatTree(tmp); |
| 420 |
} |
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
void checkTBox ( void ) const |
| 426 |
{ |
| 427 |
if ( pTBox == nullptr ) |
| 428 |
throw EFaCTPlusPlus("FaCT++ Kernel: KB Not Initialised"); |
| 429 |
} |
| 430 |
|
| 431 |
void clearTBox ( void ); |
| 432 |
|
| 433 |
|
| 434 |
RoleMaster& getORM ( void ) { return getTBox()->getORM(); } |
| 435 |
|
| 436 |
const RoleMaster& getORM ( void ) const { return getTBox()->getORM(); } |
| 437 |
|
| 438 |
RoleMaster& getDRM ( void ) { return getTBox()->getDRM(); } |
| 439 |
|
| 440 |
const RoleMaster& getDRM ( void ) const { return getTBox()->getDRM(); } |
| 441 |
|
| 442 |
|
| 443 |
Taxonomy* getCTaxonomy ( void ) |
| 444 |
{ |
| 445 |
|
| 446 |
|
| 447 |
return getTBox()->getTaxonomy(); |
| 448 |
} |
| 449 |
|
| 450 |
Taxonomy* getORTaxonomy ( void ) |
| 451 |
{ |
| 452 |
if ( !isKBPreprocessed() ) |
| 453 |
throw EFaCTPlusPlus("No access to the object role taxonomy: ontology not preprocessed"); |
| 454 |
return getORM().getTaxonomy(); |
| 455 |
} |
| 456 |
|
| 457 |
Taxonomy* getDRTaxonomy ( void ) |
| 458 |
{ |
| 459 |
if ( !isKBPreprocessed() ) |
| 460 |
throw EFaCTPlusPlus("No access to the data role taxonomy: ontology not preprocessed"); |
| 461 |
return getDRM().getTaxonomy(); |
| 462 |
} |
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
TConcept* getConcept ( const TConceptExpr* i, const char* reason ) |
| 468 |
{ |
| 469 |
try { return static_cast<TConcept*>(getTBox()->getCI(TreeDeleter(e(i)))); } |
| 470 |
catch(...) { throw EFaCTPlusPlus(reason); } |
| 471 |
} |
| 472 |
|
| 473 |
TIndividual* getIndividual ( const TIndividualExpr* i, const char* reason ) |
| 474 |
{ |
| 475 |
try { return static_cast<TIndividual*>(getTBox()->getCI(TreeDeleter(e(i)))); } |
| 476 |
catch(...) { throw EFaCTPlusPlus(reason); } |
| 477 |
} |
| 478 |
|
| 479 |
TRole* getRole ( const TRoleExpr* r, const char* reason ) |
| 480 |
{ |
| 481 |
try { return resolveRole(TreeDeleter(e(r))); } |
| 482 |
catch(...) { throw EFaCTPlusPlus(reason); } |
| 483 |
} |
| 484 |
|
| 485 |
|
| 486 |
Taxonomy* getTaxonomy ( TRole* R ) |
| 487 |
{ |
| 488 |
return R->isDataRole() ? getDRTaxonomy() : getORTaxonomy(); |
| 489 |
} |
| 490 |
|
| 491 |
TaxonomyVertex* getTaxVertex ( TRole* R ) |
| 492 |
{ |
| 493 |
return R->getTaxVertex(); |
| 494 |
} |
| 495 |
|
| 496 |
|
| 497 |
bool needForceReload ( void ) const; |
| 498 |
|
| 499 |
void forceReload ( void ); |
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
void setupSig ( const TNamedEntity* entity, const AxiomVec& Module ); |
| 507 |
|
| 508 |
void setupSig ( const TNamedEntity* entity ) { setupSig ( entity, Ontology.getAxioms() ); } |
| 509 |
|
| 510 |
void buildSignature ( const TNamedEntity* entity, const AxiomVec& Module, std::set<const TNamedEntity*>& toProcess ); |
| 511 |
|
| 512 |
void initIncremental ( void ); |
| 513 |
|
| 514 |
void doIncremental ( void ); |
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
void SaveHeader ( SaveLoadManager& m ) const; |
| 522 |
|
| 523 |
void SaveOptions ( SaveLoadManager& m ) const; |
| 524 |
|
| 525 |
void SaveKB ( SaveLoadManager& m ); |
| 526 |
|
| 527 |
void SaveIncremental ( SaveLoadManager& m ) const; |
| 528 |
|
| 529 |
void LoadHeader ( SaveLoadManager& m ); |
| 530 |
|
| 531 |
void LoadOptions ( SaveLoadManager& m ); |
| 532 |
|
| 533 |
void LoadKB ( SaveLoadManager& m ); |
| 534 |
|
| 535 |
void LoadIncremental ( SaveLoadManager& m ); |
| 536 |
|
| 537 |
void Save ( SaveLoadManager& m ); |
| 538 |
|
| 539 |
void Load ( SaveLoadManager& m ); |
| 540 |
|
| 541 |
void Save ( void ); |
| 542 |
|
| 543 |
void Load ( void ); |
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
OntologyBasedModularizer*& getModPointer ( ModuleMethod moduleMethod ) |
| 551 |
{ |
| 552 |
switch ( moduleMethod ) |
| 553 |
{ |
| 554 |
case SYN_LOC_STD: return ModSyn; |
| 555 |
case SYN_LOC_COUNT: return ModSynCount; |
| 556 |
case SEM_LOC: return ModSem; |
| 557 |
default: fpp_unreachable(); |
| 558 |
} |
| 559 |
} |
| 560 |
|
| 561 |
OntologyBasedModularizer* getModExtractor ( ModuleMethod moduleMethod ); |
| 562 |
|
| 563 |
public: |
| 564 |
|
| 565 |
ReasoningKernel ( void ); |
| 566 |
|
| 567 |
ReasoningKernel ( const ReasoningKernel& ) = delete; |
| 568 |
|
| 569 |
ReasoningKernel& operator = ( const ReasoningKernel& ) = delete; |
| 570 |
|
| 571 |
~ReasoningKernel(); |
| 572 |
|
| 573 |
ifOptionSet* getOptions ( void ) { return &KernelOptions; } |
| 574 |
const ifOptionSet* getOptions ( void ) const { return &KernelOptions; } |
| 575 |
|
| 576 |
static const char* getVersion ( void ) { return Version; } |
| 577 |
|
| 578 |
|
| 579 |
bool isKBPreprocessed ( void ) const { return getStatus() >= kbCChecked; } |
| 580 |
|
| 581 |
bool isKBClassified ( void ) const { return getStatus() >= kbClassified; } |
| 582 |
|
| 583 |
bool isKBRealised ( void ) const { return getStatus() >= kbRealised; } |
| 584 |
|
| 585 |
|
| 586 |
void setProgressMonitor ( TProgressMonitor* pMon ) |
| 587 |
{ |
| 588 |
delete pMonitor; |
| 589 |
pMonitor = pMon; |
| 590 |
if ( pTBox != nullptr ) |
| 591 |
pTBox->setProgressMonitor(pMon); |
| 592 |
} |
| 593 |
|
| 594 |
void setVerboseOutput ( bool value ) |
| 595 |
{ |
| 596 |
verboseOutput = value; |
| 597 |
if ( pTBox != nullptr ) |
| 598 |
pTBox->setVerboseOutput(value); |
| 599 |
} |
| 600 |
|
| 601 |
void setUseUndefinedNames ( bool value ) |
| 602 |
{ |
| 603 |
useUndefinedNames = value; |
| 604 |
if ( pTBox != nullptr ) |
| 605 |
pTBox->setUseUndefinedNames(value); |
| 606 |
} |
| 607 |
|
| 608 |
TaxonomyVertex *setUpCache ( const TConceptExpr *C ) |
| 609 |
{ |
| 610 |
realiseKB(); |
| 611 |
setUpCache ( C, csClassified ); |
| 612 |
return cachedVertex; |
| 613 |
} |
| 614 |
|
| 615 |
|
| 616 |
void setTopBottomRoleNames ( const char* topORoleName, const char* botORoleName, const char* topDRoleName, const char* botDRoleName ) |
| 617 |
{ |
| 618 |
TopORoleName = topORoleName; |
| 619 |
BotORoleName = botORoleName; |
| 620 |
TopDRoleName = topDRoleName; |
| 621 |
BotDRoleName = botDRoleName; |
| 622 |
|
| 623 |
Ontology.getExpressionManager()->setTopBottomRoles ( topORoleName, botORoleName,topDRoleName, botDRoleName ); |
| 624 |
} |
| 625 |
|
| 626 |
|
| 627 |
void writeReasoningResult ( std::ostream& o, float time ) |
| 628 |
{ |
| 629 |
getTBox()->clearQueryConcept(); |
| 630 |
getTBox()->writeReasoningResult ( o, time ); |
| 631 |
} |
| 632 |
|
| 633 |
|
| 634 |
void setOperationTimeout ( unsigned long value ) |
| 635 |
{ |
| 636 |
OpTimeout = value; |
| 637 |
if ( pTBox != nullptr ) |
| 638 |
pTBox->setTestTimeout(value); |
| 639 |
} |
| 640 |
|
| 641 |
void setIgnoreExprCache ( bool value ) { ignoreExprCache = value; } |
| 642 |
|
| 643 |
void setUseIncrementalReasoning ( bool value ) { useIncrementalReasoning = value; } |
| 644 |
|
| 645 |
void setSignature ( const TSignature* sig ) { if ( pET != nullptr ) pET->setSignature(sig); } |
| 646 |
|
| 647 |
void setDumpOntology ( bool value ) { dumpOntology = value; } |
| 648 |
|
| 649 |
|
| 650 |
void dumpLISP ( std::ostream& ); |
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
void needTracing ( void ) { NeedTracing = true; } |
| 658 |
|
| 659 |
const AxiomVec& getTrace ( void ) |
| 660 |
{ |
| 661 |
TraceVec.clear(); |
| 662 |
return TraceVec; |
| 663 |
} |
| 664 |
|
| 665 |
|
| 666 |
TExpressionManager* getExpressionManager ( void ) { return Ontology.getExpressionManager(); } |
| 667 |
|
| 668 |
TOntology& getOntology ( void ) { return Ontology; } |
| 669 |
|
| 670 |
const TOntology& getOntology ( void ) const { return Ontology; } |
| 671 |
|
| 672 |
|
| 673 |
void setJNICache ( TJNICache* cache ) { JNICache = cache; } |
| 674 |
|
| 675 |
TJNICache* getJNICache ( void ) const { return JNICache; } |
| 676 |
|
| 677 |
public: |
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
bool newKB ( void ) |
| 684 |
{ |
| 685 |
if ( pTBox != nullptr ) |
| 686 |
return true; |
| 687 |
|
| 688 |
pTBox = new TBox ( getOptions(), TopORoleName, BotORoleName, TopDRoleName, BotDRoleName ); |
| 689 |
pTBox->setTestTimeout(OpTimeout); |
| 690 |
pTBox->setProgressMonitor(pMonitor); |
| 691 |
pTBox->setVerboseOutput(verboseOutput); |
| 692 |
pTBox->setUseUndefinedNames(useUndefinedNames); |
| 693 |
pET = new TExpressionTranslator(*pTBox); |
| 694 |
initCacheAndFlags(); |
| 695 |
return false; |
| 696 |
} |
| 697 |
|
| 698 |
bool releaseKB ( void ) |
| 699 |
{ |
| 700 |
clearTBox(); |
| 701 |
Ontology.clear(); |
| 702 |
|
| 703 |
reasoningFailed = false; |
| 704 |
|
| 705 |
return false; |
| 706 |
} |
| 707 |
|
| 708 |
bool clearKB ( void ) |
| 709 |
{ |
| 710 |
if ( pTBox == nullptr ) |
| 711 |
return true; |
| 712 |
return releaseKB () || newKB (); |
| 713 |
} |
| 714 |
|
| 715 |
|
| 716 |
TBox* getTBox(void) |
| 717 |
{ |
| 718 |
checkTBox(); return pTBox; |
| 719 |
} |
| 720 |
|
| 721 |
const TBox* getTBox(void) const |
| 722 |
{ |
| 723 |
checkTBox(); return pTBox; |
| 724 |
} |
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
TDLAxiom* declare ( TExpr* C ) { return Ontology.add(new TDLAxiomDeclaration(C)); } |
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
TDLAxiom* impliesConcepts ( TConceptExpr* C, TConceptExpr* D ) |
| 739 |
{ return Ontology.add ( new TDLAxiomConceptInclusion ( C, D ) ); } |
| 740 |
|
| 741 |
TDLAxiom* equalConcepts ( void ) |
| 742 |
{ return Ontology.add ( new TDLAxiomEquivalentConcepts(getExpressionManager()->getArgList()) ); } |
| 743 |
|
| 744 |
TDLAxiom* disjointConcepts ( void ) |
| 745 |
{ return Ontology.add ( new TDLAxiomDisjointConcepts(getExpressionManager()->getArgList()) ); } |
| 746 |
|
| 747 |
TDLAxiom* disjointUnion ( TConceptExpr* C ) |
| 748 |
{ return Ontology.add ( new TDLAxiomDisjointUnion ( C, getExpressionManager()->getArgList() ) ); } |
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
TDLAxiom* setInverseRoles ( TORoleExpr* R, TORoleExpr* S ) |
| 755 |
{ return Ontology.add ( new TDLAxiomRoleInverse(R,S) ); } |
| 756 |
|
| 757 |
TDLAxiom* impliesORoles ( TORoleComplexExpr* R, TORoleExpr* S ) |
| 758 |
{ return Ontology.add ( new TDLAxiomORoleSubsumption ( R, S ) ); } |
| 759 |
|
| 760 |
TDLAxiom* impliesDRoles ( TDRoleExpr* R, TDRoleExpr* S ) |
| 761 |
{ return Ontology.add ( new TDLAxiomDRoleSubsumption ( R, S ) ); } |
| 762 |
|
| 763 |
TDLAxiom* equalORoles ( void ) |
| 764 |
{ return Ontology.add ( new TDLAxiomEquivalentORoles(getExpressionManager()->getArgList()) ); } |
| 765 |
|
| 766 |
TDLAxiom* equalDRoles ( void ) |
| 767 |
{ return Ontology.add ( new TDLAxiomEquivalentDRoles(getExpressionManager()->getArgList()) ); } |
| 768 |
|
| 769 |
TDLAxiom* disjointORoles ( void ) |
| 770 |
{ return Ontology.add ( new TDLAxiomDisjointORoles(getExpressionManager()->getArgList()) ); } |
| 771 |
|
| 772 |
TDLAxiom* disjointDRoles ( void ) |
| 773 |
{ return Ontology.add ( new TDLAxiomDisjointDRoles(getExpressionManager()->getArgList()) ); } |
| 774 |
|
| 775 |
|
| 776 |
TDLAxiom* setODomain ( TORoleExpr* R, TConceptExpr* C ) |
| 777 |
{ return Ontology.add ( new TDLAxiomORoleDomain ( R, C ) ); } |
| 778 |
|
| 779 |
TDLAxiom* setDDomain ( TDRoleExpr* R, TConceptExpr* C ) |
| 780 |
{ return Ontology.add ( new TDLAxiomDRoleDomain ( R, C ) ); } |
| 781 |
|
| 782 |
TDLAxiom* setORange ( TORoleExpr* R, TConceptExpr* C ) |
| 783 |
{ return Ontology.add ( new TDLAxiomORoleRange ( R, C ) ); } |
| 784 |
|
| 785 |
TDLAxiom* setDRange ( TDRoleExpr* R, TDataExpr* E ) |
| 786 |
{ return Ontology.add ( new TDLAxiomDRoleRange ( R, E ) ); } |
| 787 |
|
| 788 |
|
| 789 |
TDLAxiom* setTransitive ( TORoleExpr* R ) |
| 790 |
{ return Ontology.add ( new TDLAxiomRoleTransitive(R) ); } |
| 791 |
|
| 792 |
TDLAxiom* setReflexive ( TORoleExpr* R ) |
| 793 |
{ return Ontology.add ( new TDLAxiomRoleReflexive(R) ); } |
| 794 |
|
| 795 |
TDLAxiom* setIrreflexive ( TORoleExpr* R ) |
| 796 |
{ return Ontology.add ( new TDLAxiomRoleIrreflexive(R) ); } |
| 797 |
|
| 798 |
TDLAxiom* setSymmetric ( TORoleExpr* R ) |
| 799 |
{ return Ontology.add ( new TDLAxiomRoleSymmetric(R) ); } |
| 800 |
|
| 801 |
TDLAxiom* setAsymmetric ( TORoleExpr* R ) |
| 802 |
{ return Ontology.add ( new TDLAxiomRoleAsymmetric(R) ); } |
| 803 |
|
| 804 |
TDLAxiom* setOFunctional ( TORoleExpr* R ) |
| 805 |
{ return Ontology.add ( new TDLAxiomORoleFunctional(R) ); } |
| 806 |
|
| 807 |
TDLAxiom* setDFunctional ( TDRoleExpr* R ) |
| 808 |
{ return Ontology.add ( new TDLAxiomDRoleFunctional(R) ); } |
| 809 |
|
| 810 |
TDLAxiom* setInverseFunctional ( TORoleExpr* R ) |
| 811 |
{ return Ontology.add ( new TDLAxiomRoleInverseFunctional(R) ); } |
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
TDLAxiom* instanceOf ( TIndividualExpr* I, TConceptExpr* C ) |
| 818 |
{ return Ontology.add ( new TDLAxiomInstanceOf(I,C) ); } |
| 819 |
|
| 820 |
TDLAxiom* relatedTo ( TIndividualExpr* I, TORoleExpr* R, TIndividualExpr* J ) |
| 821 |
{ return Ontology.add ( new TDLAxiomRelatedTo(I,R,J) ); } |
| 822 |
|
| 823 |
TDLAxiom* relatedToNot ( TIndividualExpr* I, TORoleExpr* R, TIndividualExpr* J ) |
| 824 |
{ return Ontology.add ( new TDLAxiomRelatedToNot(I,R,J) ); } |
| 825 |
|
| 826 |
TDLAxiom* valueOf ( TIndividualExpr* I, TDRoleExpr* A, TDataValueExpr* V ) |
| 827 |
{ return Ontology.add ( new TDLAxiomValueOf(I,A,V) ); } |
| 828 |
|
| 829 |
TDLAxiom* valueOfNot ( TIndividualExpr* I, TDRoleExpr* A, TDataValueExpr* V ) |
| 830 |
{ return Ontology.add ( new TDLAxiomValueOfNot(I,A,V) ); } |
| 831 |
|
| 832 |
TDLAxiom* processSame ( void ) |
| 833 |
{ return Ontology.add ( new TDLAxiomSameIndividuals(getExpressionManager()->getArgList()) ); } |
| 834 |
|
| 835 |
TDLAxiom* processDifferent ( void ) |
| 836 |
{ return Ontology.add ( new TDLAxiomDifferentIndividuals(getExpressionManager()->getArgList()) ); } |
| 837 |
|
| 838 |
TDLAxiom* setFairnessConstraint ( void ) |
| 839 |
{ return Ontology.add ( new TDLAxiomFairnessConstraint(getExpressionManager()->getArgList()) ); } |
| 840 |
|
| 841 |
|
| 842 |
void retract ( TDLAxiom* axiom ) { Ontology.retract(axiom); } |
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
bool isKBConsistent ( void ) |
| 856 |
{ |
| 857 |
try { |
| 858 |
if ( getStatus() <= kbLoading ) |
| 859 |
processKB(kbCChecked); |
| 860 |
return getTBox()->isConsistent(); |
| 861 |
} |
| 862 |
catch ( const EFPPInconsistentKB& ) |
| 863 |
{ return false; } |
| 864 |
} |
| 865 |
|
| 866 |
void preprocessKB ( void ) |
| 867 |
{ |
| 868 |
if ( !isKBConsistent() ) |
| 869 |
throw EFPPInconsistentKB(); |
| 870 |
} |
| 871 |
|
| 872 |
void classifyKB ( void ) |
| 873 |
{ |
| 874 |
if ( !isKBClassified() ) |
| 875 |
processKB(kbClassified); |
| 876 |
if ( !isKBConsistent() ) |
| 877 |
throw EFPPInconsistentKB(); |
| 878 |
} |
| 879 |
|
| 880 |
void realiseKB ( void ) |
| 881 |
{ |
| 882 |
if ( !isKBRealised() ) |
| 883 |
processKB(kbRealised); |
| 884 |
if ( !isKBConsistent() ) |
| 885 |
throw EFPPInconsistentKB(); |
| 886 |
} |
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
bool isFunctional ( const TORoleExpr* R ) |
| 892 |
{ |
| 893 |
preprocessKB(); |
| 894 |
TRole* r = getRole ( R, "Role expression expected in isFunctional()" ); |
| 895 |
if ( unlikely(r->isTop()) ) |
| 896 |
return false; |
| 897 |
if ( unlikely(r->isBottom()) ) |
| 898 |
return true; |
| 899 |
|
| 900 |
return getFunctionality(r); |
| 901 |
} |
| 902 |
|
| 903 |
bool isFunctional ( const TDRoleExpr* R ) |
| 904 |
{ |
| 905 |
preprocessKB(); |
| 906 |
TRole* r = getRole ( R, "Role expression expected in isFunctional()" ); |
| 907 |
if ( unlikely(r->isTop()) ) |
| 908 |
return false; |
| 909 |
if ( unlikely(r->isBottom()) ) |
| 910 |
return true; |
| 911 |
|
| 912 |
return getFunctionality(r); |
| 913 |
} |
| 914 |
|
| 915 |
bool isInverseFunctional ( const TORoleExpr* R ) |
| 916 |
{ |
| 917 |
preprocessKB(); |
| 918 |
TRole* r = getRole ( R, "Role expression expected in isInverseFunctional()" )->inverse(); |
| 919 |
if ( unlikely(r->isTop()) ) |
| 920 |
return false; |
| 921 |
if ( unlikely(r->isBottom()) ) |
| 922 |
return true; |
| 923 |
|
| 924 |
return getFunctionality(r); |
| 925 |
} |
| 926 |
|
| 927 |
bool isTransitive ( const TORoleExpr* R ) |
| 928 |
{ |
| 929 |
preprocessKB(); |
| 930 |
TRole* r = getRole ( R, "Role expression expected in isTransitive()" ); |
| 931 |
if ( unlikely(r->isTop()) ) |
| 932 |
return true; |
| 933 |
if ( unlikely(r->isBottom()) ) |
| 934 |
return true; |
| 935 |
|
| 936 |
if ( !r->isTransitivityKnown() ) |
| 937 |
r->setTransitive(checkTransitivity(e(R))); |
| 938 |
return r->isTransitive(); |
| 939 |
} |
| 940 |
|
| 941 |
bool isSymmetric ( const TORoleExpr* R ) |
| 942 |
{ |
| 943 |
preprocessKB(); |
| 944 |
TRole* r = getRole ( R, "Role expression expected in isSymmetric()" ); |
| 945 |
if ( unlikely(r->isTop()) ) |
| 946 |
return true; |
| 947 |
if ( unlikely(r->isBottom()) ) |
| 948 |
return true; |
| 949 |
|
| 950 |
if ( !r->isSymmetryKnown() ) |
| 951 |
r->setSymmetric(checkSymmetry(e(R))); |
| 952 |
return r->isSymmetric(); |
| 953 |
} |
| 954 |
|
| 955 |
bool isAsymmetric ( const TORoleExpr* R ) |
| 956 |
{ |
| 957 |
preprocessKB(); |
| 958 |
TRole* r = getRole ( R, "Role expression expected in isAsymmetric()" ); |
| 959 |
if ( unlikely(r->isTop()) ) |
| 960 |
return false; |
| 961 |
if ( unlikely(r->isBottom()) ) |
| 962 |
return true; |
| 963 |
|
| 964 |
if ( !r->isAsymmetryKnown() ) |
| 965 |
r->setAsymmetric(getTBox()->isDisjointRoles(r,r->inverse())); |
| 966 |
return r->isAsymmetric(); |
| 967 |
} |
| 968 |
|
| 969 |
bool isReflexive ( const TORoleExpr* R ) |
| 970 |
{ |
| 971 |
preprocessKB(); |
| 972 |
TRole* r = getRole ( R, "Role expression expected in isReflexive()" ); |
| 973 |
if ( unlikely(r->isTop()) ) |
| 974 |
return true; |
| 975 |
if ( unlikely(r->isBottom()) ) |
| 976 |
return false; |
| 977 |
|
| 978 |
if ( !r->isReflexivityKnown() ) |
| 979 |
r->setReflexive(checkReflexivity(e(R))); |
| 980 |
return r->isReflexive(); |
| 981 |
} |
| 982 |
|
| 983 |
bool isIrreflexive ( const TORoleExpr* R ) |
| 984 |
{ |
| 985 |
preprocessKB(); |
| 986 |
TRole* r = getRole ( R, "Role expression expected in isIrreflexive()" ); |
| 987 |
if ( unlikely(r->isTop()) ) |
| 988 |
return false; |
| 989 |
if ( unlikely(r->isBottom()) ) |
| 990 |
return true; |
| 991 |
|
| 992 |
if ( !r->isIrreflexivityKnown() ) |
| 993 |
r->setIrreflexive(getTBox()->isIrreflexive(r)); |
| 994 |
return r->isIrreflexive(); |
| 995 |
} |
| 996 |
|
| 997 |
bool isSubRoles ( const TORoleExpr* R, const TORoleExpr* S ) |
| 998 |
{ |
| 999 |
preprocessKB(); |
| 1000 |
TRole* r = getRole ( R, "Role expression expected in isSubRoles()" ); |
| 1001 |
TRole* s = getRole ( S, "Role expression expected in isSubRoles()" ); |
| 1002 |
if ( unlikely(r->isBottom()) || unlikely(s->isTop()) ) |
| 1003 |
return true; |
| 1004 |
if ( unlikely(r->isTop()) && unlikely(s->isBottom()) ) |
| 1005 |
return false; |
| 1006 |
|
| 1007 |
|
| 1008 |
if ( likely(!r->isTop() && !s->isBottom()) ) |
| 1009 |
{ |
| 1010 |
if ( *r <= *s ) |
| 1011 |
return true; |
| 1012 |
} |
| 1013 |
|
| 1014 |
|
| 1015 |
return checkRoleSubsumption ( r, s ); |
| 1016 |
} |
| 1017 |
|
| 1018 |
bool isSubRoles ( const TDRoleExpr* R, const TDRoleExpr* S ) |
| 1019 |
{ |
| 1020 |
preprocessKB(); |
| 1021 |
TRole* r = getRole ( R, "Role expression expected in isSubRoles()" ); |
| 1022 |
TRole* s = getRole ( S, "Role expression expected in isSubRoles()" ); |
| 1023 |
if ( unlikely(r->isBottom()) || unlikely(s->isTop()) ) |
| 1024 |
return true; |
| 1025 |
if ( unlikely(r->isTop()) && unlikely(s->isBottom()) ) |
| 1026 |
return false; |
| 1027 |
|
| 1028 |
|
| 1029 |
if ( likely(!r->isTop() && !s->isBottom()) ) |
| 1030 |
{ |
| 1031 |
if ( *r <= *s ) |
| 1032 |
return true; |
| 1033 |
} |
| 1034 |
|
| 1035 |
|
| 1036 |
return checkRoleSubsumption ( r, s ); |
| 1037 |
} |
| 1038 |
|
| 1039 |
bool isDisjointRoles ( const TORoleExpr* R, const TORoleExpr* S ) |
| 1040 |
{ |
| 1041 |
preprocessKB(); |
| 1042 |
TRole* r = getRole ( R, "Role expression expected in isDisjointRoles()" ); |
| 1043 |
TRole* s = getRole ( S, "Role expression expected in isDisjointRoles()" ); |
| 1044 |
if ( unlikely(r->isTop()) || unlikely(s->isTop()) ) |
| 1045 |
return false; |
| 1046 |
if ( unlikely(r->isBottom()) || unlikely(s->isBottom()) ) |
| 1047 |
return true; |
| 1048 |
return getTBox()->isDisjointRoles ( r, s ); |
| 1049 |
} |
| 1050 |
|
| 1051 |
bool isDisjointRoles ( const TDRoleExpr* R, const TDRoleExpr* S ) |
| 1052 |
{ |
| 1053 |
preprocessKB(); |
| 1054 |
TRole* r = getRole ( R, "Role expression expected in isDisjointRoles()" ); |
| 1055 |
TRole* s = getRole ( S, "Role expression expected in isDisjointRoles()" ); |
| 1056 |
if ( unlikely(r->isTop()) || unlikely(s->isTop()) ) |
| 1057 |
return false; |
| 1058 |
if ( unlikely(r->isBottom()) || unlikely(s->isBottom()) ) |
| 1059 |
return true; |
| 1060 |
return getTBox()->isDisjointRoles ( r, s ); |
| 1061 |
} |
| 1062 |
|
| 1063 |
bool isDisjointRoles ( void ); |
| 1064 |
|
| 1065 |
bool isSubChain ( const TORoleExpr* R ) |
| 1066 |
{ |
| 1067 |
preprocessKB(); |
| 1068 |
TRole* r = getRole ( R, "Role expression expected in isSubChain()" ); |
| 1069 |
if ( unlikely(r->isTop()) ) |
| 1070 |
return true; |
| 1071 |
return checkSubChain ( getExpressionManager()->getArgList(), r ); |
| 1072 |
} |
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
bool isSatisfiable ( const TConceptExpr* C ) |
| 1078 |
{ |
| 1079 |
preprocessKB(); |
| 1080 |
try { return checkSat(C); } |
| 1081 |
catch ( const EFPPCantRegName& crn ) |
| 1082 |
{ |
| 1083 |
if ( dynamic_cast<const TDLConceptName*>(C) != nullptr ) |
| 1084 |
return true; |
| 1085 |
|
| 1086 |
throw crn; |
| 1087 |
} |
| 1088 |
} |
| 1089 |
|
| 1090 |
bool isSubsumedBy ( const TConceptExpr* C, const TConceptExpr* D ) |
| 1091 |
{ |
| 1092 |
preprocessKB(); |
| 1093 |
if ( isNameOrConst(D) && likely(isNameOrConst(C)) ) |
| 1094 |
return checkSub ( getTBox()->getCI(TreeDeleter(e(C))), getTBox()->getCI(TreeDeleter(e(D))) ); |
| 1095 |
DLTree* nD = createSNFNot(e(D)); |
| 1096 |
return !checkSatTree ( createSNFAnd (e(C), nD) ); |
| 1097 |
} |
| 1098 |
|
| 1099 |
bool isDisjoint ( const TConceptExpr* C, const TConceptExpr* D ) { return !isSatisfiable(getExpressionManager()->And(C,D)); } |
| 1100 |
|
| 1101 |
bool isEquivalent ( const TConceptExpr* C, const TConceptExpr* D ) |
| 1102 |
{ |
| 1103 |
if ( C == D ) |
| 1104 |
return true; |
| 1105 |
preprocessKB(); |
| 1106 |
if ( isKBClassified() ) |
| 1107 |
{ |
| 1108 |
if ( isNameOrConst(D) && likely(isNameOrConst(C)) ) |
| 1109 |
{ |
| 1110 |
const TaxonomyVertex* cV = getTBox()->getCI(TreeDeleter(e(C)))->getTaxVertex(); |
| 1111 |
const TaxonomyVertex* dV = getTBox()->getCI(TreeDeleter(e(D)))->getTaxVertex(); |
| 1112 |
if ( unlikely(cV == nullptr) && unlikely(dV == nullptr) ) |
| 1113 |
return false; |
| 1114 |
return cV == dV; |
| 1115 |
} |
| 1116 |
} |
| 1117 |
|
| 1118 |
return isSubsumedBy ( C, D ) && isSubsumedBy ( D, C ); |
| 1119 |
} |
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
template <typename Actor> |
| 1124 |
void getSupConcepts ( const TConceptExpr* C, bool direct, Actor& actor, bool needCurrent = false ) |
| 1125 |
{ |
| 1126 |
classifyKB(); |
| 1127 |
setUpCache ( C, csClassified ); |
| 1128 |
actor.clear(); |
| 1129 |
Taxonomy* tax = getCTaxonomy(); |
| 1130 |
if (direct) |
| 1131 |
if (needCurrent) |
| 1132 |
tax->getRelativesInfo<true, true, true>(cachedVertex, actor); |
| 1133 |
else |
| 1134 |
tax->getRelativesInfo<false, true, true>(cachedVertex, actor); |
| 1135 |
else |
| 1136 |
if (needCurrent) |
| 1137 |
tax->getRelativesInfo<true, false, true>(cachedVertex, actor); |
| 1138 |
else |
| 1139 |
tax->getRelativesInfo<false, false, true>(cachedVertex, actor); |
| 1140 |
} |
| 1141 |
|
| 1142 |
template <typename Actor> |
| 1143 |
void getSubConcepts ( const TConceptExpr* C, bool direct, Actor& actor, bool needCurrent = false) |
| 1144 |
{ |
| 1145 |
classifyKB(); |
| 1146 |
setUpCache ( C, csClassified ); |
| 1147 |
actor.clear(); |
| 1148 |
Taxonomy* tax = getCTaxonomy(); |
| 1149 |
if (direct) |
| 1150 |
if (needCurrent) |
| 1151 |
tax->getRelativesInfo<true, true, false>(cachedVertex, actor); |
| 1152 |
else |
| 1153 |
tax->getRelativesInfo<false, true, false>(cachedVertex, actor); |
| 1154 |
else |
| 1155 |
if (needCurrent) |
| 1156 |
tax->getRelativesInfo<true, false, false>(cachedVertex, actor); |
| 1157 |
else |
| 1158 |
tax->getRelativesInfo<false, false, false>(cachedVertex, actor); |
| 1159 |
} |
| 1160 |
|
| 1161 |
template <typename Actor> |
| 1162 |
void getEquivalentConcepts ( const TConceptExpr* C, Actor& actor ) |
| 1163 |
{ |
| 1164 |
classifyKB(); |
| 1165 |
setUpCache ( C, csClassified ); |
| 1166 |
actor.clear(); |
| 1167 |
actor.apply(*cachedVertex); |
| 1168 |
} |
| 1169 |
|
| 1170 |
template <typename Actor> |
| 1171 |
void getDisjointConcepts ( const TConceptExpr* C, Actor& actor ) |
| 1172 |
{ |
| 1173 |
classifyKB(); |
| 1174 |
setUpCache ( getExpressionManager()->Not(C), csClassified ); |
| 1175 |
actor.clear(); |
| 1176 |
Taxonomy* tax = getCTaxonomy(); |
| 1177 |
|
| 1178 |
tax->getRelativesInfo<true, false, false> ( cachedVertex, actor ); |
| 1179 |
} |
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
template <typename Actor> |
| 1185 |
void getSupRoles ( const TRoleExpr* r, bool direct, Actor& actor ) |
| 1186 |
{ |
| 1187 |
preprocessKB(); |
| 1188 |
TRole* R = getRole ( r, "Role expression expected in getSupRoles()" ); |
| 1189 |
actor.clear(); |
| 1190 |
Taxonomy* tax = getTaxonomy(R); |
| 1191 |
if ( direct ) |
| 1192 |
tax->getRelativesInfo<false, true, true> ( getTaxVertex(R), actor ); |
| 1193 |
else |
| 1194 |
tax->getRelativesInfo<false, false, true> ( getTaxVertex(R), actor ); |
| 1195 |
} |
| 1196 |
|
| 1197 |
template <typename Actor> |
| 1198 |
void getSubRoles ( const TRoleExpr* r, bool direct, Actor& actor ) |
| 1199 |
{ |
| 1200 |
preprocessKB(); |
| 1201 |
TRole* R = getRole ( r, "Role expression expected in getSubRoles()" ); |
| 1202 |
actor.clear(); |
| 1203 |
Taxonomy* tax = getTaxonomy(R); |
| 1204 |
if ( direct ) |
| 1205 |
tax->getRelativesInfo<false, true, false> ( getTaxVertex(R), actor ); |
| 1206 |
else |
| 1207 |
tax->getRelativesInfo<false, false, false> ( getTaxVertex(R), actor ); |
| 1208 |
} |
| 1209 |
|
| 1210 |
template <typename Actor> |
| 1211 |
void getEquivalentRoles ( const TRoleExpr* r, Actor& actor ) |
| 1212 |
{ |
| 1213 |
preprocessKB(); |
| 1214 |
TRole* R = getRole ( r, "Role expression expected in getEquivalentRoles()" ); |
| 1215 |
actor.clear(); |
| 1216 |
actor.apply(*getTaxVertex(R)); |
| 1217 |
} |
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
template <typename Actor> |
| 1223 |
void getORoleDomain ( const TORoleExpr* r, bool direct, Actor& actor ) |
| 1224 |
{ |
| 1225 |
classifyKB(); |
| 1226 |
setUpCache ( getExpressionManager()->Exists ( r, getExpressionManager()->Top() ), csClassified ); |
| 1227 |
actor.clear(); |
| 1228 |
Taxonomy* tax = getCTaxonomy(); |
| 1229 |
if ( direct ) |
| 1230 |
tax->getRelativesInfo<true, true, true> ( cachedVertex, actor ); |
| 1231 |
else |
| 1232 |
tax->getRelativesInfo<true, false, true> ( cachedVertex, actor ); |
| 1233 |
} |
| 1234 |
|
| 1235 |
template <typename Actor> |
| 1236 |
void getDRoleDomain ( const TDRoleExpr* r, bool direct, Actor& actor ) |
| 1237 |
{ |
| 1238 |
classifyKB(); |
| 1239 |
setUpCache ( getExpressionManager()->Exists ( r, getExpressionManager()->DataTop() ), csClassified ); |
| 1240 |
actor.clear(); |
| 1241 |
Taxonomy* tax = getCTaxonomy(); |
| 1242 |
if ( direct ) |
| 1243 |
tax->getRelativesInfo<true, true, true> ( cachedVertex, actor ); |
| 1244 |
else |
| 1245 |
tax->getRelativesInfo<true, false, true> ( cachedVertex, actor ); |
| 1246 |
} |
| 1247 |
|
| 1248 |
template <typename Actor> |
| 1249 |
void getRoleRange ( const TORoleExpr* r, bool direct, Actor& actor ) |
| 1250 |
{ getORoleDomain ( getExpressionManager()->Inverse(r), direct, actor ); } |
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
template <typename Actor> |
| 1256 |
void getDirectInstances ( const TConceptExpr* C, Actor& actor ) |
| 1257 |
{ |
| 1258 |
realiseKB(); |
| 1259 |
setUpCache ( C, csClassified ); |
| 1260 |
actor.clear(); |
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
if ( actor.apply(*cachedVertex) ) |
| 1266 |
return; |
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
for ( TaxonomyVertex::iterator p = cachedVertex->begin(false), |
| 1271 |
p_end = cachedVertex->end(false); p != p_end; ++p ) |
| 1272 |
actor.apply(**p); |
| 1273 |
} |
| 1274 |
|
| 1275 |
|
| 1276 |
template <typename Actor> |
| 1277 |
void getInstances ( const TConceptExpr* C, Actor& actor ) |
| 1278 |
{ |
| 1279 |
realiseKB(); |
| 1280 |
setUpCache ( C, csClassified ); |
| 1281 |
actor.clear(); |
| 1282 |
Taxonomy* tax = getCTaxonomy(); |
| 1283 |
tax->getRelativesInfo<true, false, false> ( cachedVertex, actor ); |
| 1284 |
} |
| 1285 |
|
| 1286 |
|
| 1287 |
template <typename Actor> |
| 1288 |
void getTypes ( const TIndividualExpr* I, bool direct, Actor& actor ) |
| 1289 |
{ |
| 1290 |
realiseKB(); |
| 1291 |
setUpCache ( getExpressionManager()->OneOf(I), csClassified ); |
| 1292 |
actor.clear(); |
| 1293 |
Taxonomy* tax = getCTaxonomy(); |
| 1294 |
if ( direct ) |
| 1295 |
tax->getRelativesInfo<true, true, true> ( cachedVertex, actor ); |
| 1296 |
else |
| 1297 |
tax->getRelativesInfo<true, false, true> ( cachedVertex, actor ); |
| 1298 |
} |
| 1299 |
|
| 1300 |
template <typename Actor> |
| 1301 |
void getSameAs ( const TIndividualExpr* I, Actor& actor ) |
| 1302 |
{ |
| 1303 |
realiseKB(); |
| 1304 |
getEquivalentConcepts ( getExpressionManager()->OneOf(I), actor ); |
| 1305 |
} |
| 1306 |
|
| 1307 |
bool isSameIndividuals ( const TIndividualExpr* I, const TIndividualExpr* J ) |
| 1308 |
{ |
| 1309 |
realiseKB(); |
| 1310 |
TIndividual* i = getIndividual ( I, "Only known individuals are allowed in the isSameAs()" ); |
| 1311 |
TIndividual* j = getIndividual ( J, "Only known individuals are allowed in the isSameAs()" ); |
| 1312 |
return getTBox()->isSameIndividuals(i,j); |
| 1313 |
} |
| 1314 |
|
| 1315 |
bool isInstance ( const TIndividualExpr* I, const TConceptExpr* C ) |
| 1316 |
{ |
| 1317 |
realiseKB(); |
| 1318 |
getIndividual ( I, "individual name expected in the isInstance()" ); |
| 1319 |
|
| 1320 |
return isSubsumedBy ( getExpressionManager()->OneOf(I), C ); |
| 1321 |
} |
| 1322 |
|
| 1323 |
void getRelatedRoles ( const TIndividualExpr* I, NamesVector& Rs, bool data, bool needI ); |
| 1324 |
|
| 1325 |
void getRoleFillers ( const TIndividualExpr* I, const TORoleExpr* R, IndividualSet& Result ); |
| 1326 |
const CIVec& getRoleFillers ( const TIndividualExpr* I, const TORoleExpr* R); |
| 1327 |
|
| 1328 |
bool isRelated ( const TIndividualExpr* I, const TORoleExpr* R, const TIndividualExpr* J ); |
| 1329 |
|
| 1330 |
bool isRelated ( const TIndividualExpr* I, const TDRoleExpr* A, const TDataValueExpr* V ); |
| 1331 |
|
| 1332 |
|
| 1333 |
void getDataRelatedIndividuals ( TDRoleExpr* R, TDRoleExpr* S, int op, IndividualSet& Result ); |
| 1334 |
|
| 1335 |
TDLConceptExpression* parseConcept(const std::string& name); |
| 1336 |
TDLObjectRoleExpression* parseObjectRole(const std::string& name); |
| 1337 |
TDLDataRoleExpression* parseDataRole(const std::string& name); |
| 1338 |
const TConcept* getConcept(TDLIndividualName* i_exp, TDLConceptExpression* c_exp); |
| 1339 |
const TRole* getRole(TDLObjectRoleExpression* o_exp, TDLDataRoleExpression* d_exp); |
| 1340 |
const char* getXsdType(const TDataEntry* dataValue) const; |
| 1341 |
void getTriples(const std::string& q_subj_name, const std::string& q_role_name, const std::string& q_obj_name, std::set<std::vector<std::string>>& triples); |
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
const TCGNode* buildCompletionTree ( const TConceptExpr* C ) |
| 1349 |
{ |
| 1350 |
preprocessKB(); |
| 1351 |
setUpCache ( C, csSat ); |
| 1352 |
const TCGNode* ret = getTBox()->buildCompletionTree(cachedConcept); |
| 1353 |
if ( KE == nullptr ) |
| 1354 |
KE = new KnowledgeExplorer ( getTBox(), getExpressionManager() ); |
| 1355 |
return ret; |
| 1356 |
} |
| 1357 |
|
| 1358 |
void getDataRoles ( const TCGNode* node, TCGRoleSet& Result, bool onlyDet ) { Result = KE->getDataRoles ( node, onlyDet ); } |
| 1359 |
|
| 1360 |
void getObjectRoles ( const TCGNode* node, TCGRoleSet& Result, bool onlyDet, bool needIncoming ) { Result = KE->getObjectRoles ( node, onlyDet, needIncoming ); } |
| 1361 |
|
| 1362 |
void getNeighbours ( const TCGNode* node, TRoleExpr* role, TCGNodeVec& Result ) |
| 1363 |
{ Result = KE->getNeighbours ( node, getRole ( role, "Role expression expected in getNeighbours() method" ) ); } |
| 1364 |
|
| 1365 |
void getLabel ( const TCGNode* node, TCGItemVec& Result, bool onlyDet ) { Result = KE->getLabel ( node, onlyDet ); } |
| 1366 |
|
| 1367 |
const TCGNode* getBlocker ( const TCGNode* node ) const { return KE->getBlocker(node); } |
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
size_t getAtomicDecompositionSize ( ModuleMethod moduleMethod, ModuleType moduleType ); |
| 1375 |
|
| 1376 |
const TOntologyAtom::AxiomSet& getAtomAxioms ( unsigned int index ) const; |
| 1377 |
|
| 1378 |
const TOntologyAtom::AxiomSet& getAtomModule ( unsigned int index ) const; |
| 1379 |
|
| 1380 |
const TOntologyAtom::AtomSet& getAtomDependents ( unsigned int index ) const; |
| 1381 |
|
| 1382 |
unsigned long long getLocCheckNumber ( void ) const; |
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
const AxiomVec& getModule ( ModuleMethod moduleMethod, ModuleType moduleType ); |
| 1390 |
|
| 1391 |
const AxiomVec& getNonLocal ( ModuleMethod moduleMethod, ModuleType moduleType ); |
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
bool checkSaveLoadContext ( const std::string& name ) const; |
| 1399 |
|
| 1400 |
bool setSaveLoadContext ( const std::string& name ); |
| 1401 |
|
| 1402 |
bool clearSaveLoadContext ( const std::string& name ) const; |
| 1403 |
}; |
| 1404 |
|
| 1405 |
#endif |