| 1 | /* This file is part of the FaCT++ DL reasoner |
| 2 | Copyright (C) 2011-2015 Dmitry Tsarkov and The University of Manchester |
| 3 | Copyright (C) 2015-2017 Dmitry Tsarkov |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | This library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with this library; if not, write to the Free Software |
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | // inform interface that we are building library here |
| 21 | #define FPP_BUILD_SHARED |
| 22 | |
| 23 | #include "fact.h" |
| 24 | #include "Kernel.h" |
| 25 | #include "Actor.h" |
| 26 | |
| 27 | /// class for acting with a taxonomy at a C level |
| 28 | class CActor: public Actor |
| 29 | { |
| 30 | protected: // methods |
| 31 | /// build the NULL-terminated array of names of entries |
| 32 | const char** buildArray ( const Array1D& vec ) const |
| 33 | { |
| 34 | const char** ret = new const char*[vec.size()+1]; |
| 35 | for ( size_t i = 0; i < vec.size(); ++i ) |
| 36 | ret[i] = vec[i]->getName(); |
| 37 | ret[vec.size()] = nullptr; |
| 38 | return ret; |
| 39 | } |
| 40 | |
| 41 | public: // interface |
| 42 | /// empty c'tor |
| 43 | CActor() = default; |
| 44 | |
| 45 | // return values |
| 46 | /// get 1-d NULL-terminated array of synonyms of the 1st entry(necessary for Equivalents, for example) |
| 47 | const char** getSynonyms ( void ) const |
| 48 | { |
| 49 | if ( found.empty() ) |
| 50 | return buildArray(Array1D()); |
| 51 | Array2D acc; |
| 52 | getFoundData(acc); |
| 53 | return buildArray(acc[0]); |
| 54 | } |
| 55 | /// get NULL-terminated 2D array of all required elements of the taxonomy |
| 56 | const char*** getElements2D ( void ) const |
| 57 | { |
| 58 | Array2D acc; |
| 59 | getFoundData(acc); |
| 60 | const char*** ret = new const char**[acc.size()+1]; |
| 61 | for ( size_t i = 0; i < acc.size(); ++i ) |
| 62 | ret[i] = buildArray(acc[i]); |
| 63 | ret[acc.size()] = nullptr; |
| 64 | return ret; |
| 65 | } |
| 66 | /// get NULL-terminated 1D array of all required elements of the taxonomy |
| 67 | const char** getElements1D ( void ) const |
| 68 | { |
| 69 | Array1D vec; |
| 70 | getFoundData(vec); |
| 71 | return buildArray(vec); |
| 72 | } |
| 73 | }; // CActor |
| 74 | |
| 75 | // type declarations |
| 76 | |
| 77 | #define DECLARE_STRUCT(name,type) \ |
| 78 | struct name ## _st { type* p; explicit name ## _st(type* q) : p(q) {} } |
| 79 | // FaCT++ kernel |
| 80 | DECLARE_STRUCT(fact_reasoning_kernel,ReasoningKernel); |
| 81 | // progress monitor |
| 82 | DECLARE_STRUCT(fact_progress_monitor,TProgressMonitor); |
| 83 | // axiom |
| 84 | DECLARE_STRUCT(fact_axiom,TDLAxiom); |
| 85 | // expression |
| 86 | DECLARE_STRUCT(fact_expression,ReasoningKernel::TExpr); |
| 87 | // concept expression |
| 88 | DECLARE_STRUCT(fact_concept_expression,ReasoningKernel::TConceptExpr); |
| 89 | // data- or object-role expression |
| 90 | DECLARE_STRUCT(fact_role_expression,ReasoningKernel::TRoleExpr); |
| 91 | // object role expression |
| 92 | DECLARE_STRUCT(fact_o_role_expression,ReasoningKernel::TORoleExpr); |
| 93 | // complex object role expression |
| 94 | DECLARE_STRUCT(fact_o_role_complex_expression,ReasoningKernel::TORoleComplexExpr); |
| 95 | // data role expression |
| 96 | DECLARE_STRUCT(fact_d_role_expression,ReasoningKernel::TDRoleExpr); |
| 97 | // individual expression |
| 98 | DECLARE_STRUCT(fact_individual_expression,ReasoningKernel::TIndividualExpr); |
| 99 | // general data expression |
| 100 | DECLARE_STRUCT(fact_data_expression,ReasoningKernel::TDataExpr); |
| 101 | // data type expression |
| 102 | DECLARE_STRUCT(fact_data_type_expression,ReasoningKernel::TDataTypeExpr); |
| 103 | // data value expression |
| 104 | DECLARE_STRUCT(fact_data_value_expression,ReasoningKernel::TDataValueExpr); |
| 105 | // facet expression |
| 106 | DECLARE_STRUCT(fact_facet_expression,ReasoningKernel::TFacetExpr); |
| 107 | // actor to traverse taxonomy |
| 108 | DECLARE_STRUCT(fact_actor,CActor); |
| 109 | |
| 110 | const char *fact_get_version () |
| 111 | { |
| 112 | return ReasoningKernel::getVersion(); |
| 113 | } |
| 114 | |
| 115 | fact_reasoning_kernel *fact_reasoning_kernel_new () |
| 116 | { |
| 117 | fact_reasoning_kernel *ret = new fact_reasoning_kernel_st(new ReasoningKernel()); |
| 118 | /* need this to work properly with top/bot roles */ |
| 119 | ret->p->setTopBottomRoleNames("*UROLE*","*EROLE*","*UDROLE*","*EDROLE*"); |
| 120 | return ret; |
| 121 | } |
| 122 | void fact_reasoning_kernel_free (fact_reasoning_kernel *k) |
| 123 | { |
| 124 | delete k->p; |
| 125 | delete k; |
| 126 | } |
| 127 | |
| 128 | /* |
| 129 | ifOptionSet* getOptions ( ); |
| 130 | const ifOptionSet* getOptions ( ); |
| 131 | */ |
| 132 | |
| 133 | int fact_is_kb_preprocessed (fact_reasoning_kernel *k) |
| 134 | { |
| 135 | return k->p->isKBPreprocessed(); |
| 136 | } |
| 137 | int fact_is_kb_classified (fact_reasoning_kernel *k) |
| 138 | { |
| 139 | return k->p->isKBRealised(); |
| 140 | } |
| 141 | int fact_is_kb_realised (fact_reasoning_kernel *k) |
| 142 | { |
| 143 | return k->p->isKBRealised(); |
| 144 | } |
| 145 | void fact_set_progress_monitor (fact_reasoning_kernel *k, fact_progress_monitor *m) |
| 146 | { |
| 147 | return k->p->setProgressMonitor(m->p); |
| 148 | } |
| 149 | |
| 150 | void fact_set_verbose_output (fact_reasoning_kernel *k, int value) |
| 151 | { |
| 152 | k->p->setVerboseOutput(value); |
| 153 | } |
| 154 | |
| 155 | void fact_set_top_bottom_role_names (fact_reasoning_kernel *k, |
| 156 | const char *top_o_role_name, |
| 157 | const char *bot_o_role_name, |
| 158 | const char *top_d_role_name, |
| 159 | const char *bot_d_role_name) |
| 160 | { |
| 161 | k->p->setTopBottomRoleNames(top_o_role_name,bot_o_role_name,top_d_role_name,bot_d_role_name); |
| 162 | } |
| 163 | |
| 164 | void fact_set_operation_timeout (fact_reasoning_kernel *k, |
| 165 | unsigned long timeout) |
| 166 | { |
| 167 | k->p->setOperationTimeout(timeout); |
| 168 | } |
| 169 | |
| 170 | int fact_new_kb (fact_reasoning_kernel *k) |
| 171 | { |
| 172 | return k->p->newKB(); |
| 173 | } |
| 174 | int fact_release_kb (fact_reasoning_kernel *k) |
| 175 | { |
| 176 | return k->p->releaseKB(); |
| 177 | } |
| 178 | int fact_clear_kb (fact_reasoning_kernel *k) |
| 179 | { |
| 180 | return k->p->clearKB(); |
| 181 | } |
| 182 | |
| 183 | fact_axiom *fact_declare (fact_reasoning_kernel *k, fact_expression *c) |
| 184 | { |
| 185 | return new fact_axiom_st(k->p->declare(c->p)); |
| 186 | } |
| 187 | fact_axiom *fact_implies_concepts (fact_reasoning_kernel *k, |
| 188 | fact_concept_expression *c, |
| 189 | fact_concept_expression *d) |
| 190 | { |
| 191 | return new fact_axiom_st(k->p->impliesConcepts(c->p,d->p)); |
| 192 | } |
| 193 | fact_axiom *fact_equal_concepts (fact_reasoning_kernel *k) |
| 194 | { |
| 195 | return new fact_axiom_st(k->p->equalConcepts()); |
| 196 | } |
| 197 | fact_axiom *fact_disjoint_concepts (fact_reasoning_kernel *k) |
| 198 | { |
| 199 | return new fact_axiom_st(k->p->disjointConcepts()); |
| 200 | } |
| 201 | fact_axiom *fact_disjoint_union (fact_reasoning_kernel *k, |
| 202 | fact_concept_expression *C) |
| 203 | { |
| 204 | return new fact_axiom_st(k->p->disjointUnion(C->p)); |
| 205 | } |
| 206 | |
| 207 | |
| 208 | fact_axiom *fact_set_inverse_roles (fact_reasoning_kernel *k, |
| 209 | fact_o_role_expression *r, |
| 210 | fact_o_role_expression *s) |
| 211 | { |
| 212 | return new fact_axiom_st(k->p->setInverseRoles(r->p,s->p)); |
| 213 | } |
| 214 | fact_axiom *fact_implies_o_roles (fact_reasoning_kernel *k, |
| 215 | fact_o_role_complex_expression *r, |
| 216 | fact_o_role_expression *s) |
| 217 | { |
| 218 | return new fact_axiom_st(k->p->impliesORoles(r->p,s->p)); |
| 219 | } |
| 220 | fact_axiom *fact_implies_d_roles (fact_reasoning_kernel *k, |
| 221 | fact_d_role_expression *r, |
| 222 | fact_d_role_expression *s) |
| 223 | { |
| 224 | return new fact_axiom_st(k->p->impliesDRoles(r->p,s->p)); |
| 225 | } |
| 226 | fact_axiom *fact_equal_o_roles (fact_reasoning_kernel *k) |
| 227 | { |
| 228 | return new fact_axiom_st(k->p->equalORoles()); |
| 229 | } |
| 230 | fact_axiom *fact_equal_d_roles (fact_reasoning_kernel *k) |
| 231 | { |
| 232 | return new fact_axiom_st(k->p->equalDRoles()); |
| 233 | } |
| 234 | fact_axiom *fact_disjoint_o_roles (fact_reasoning_kernel *k) |
| 235 | { |
| 236 | return new fact_axiom_st(k->p->disjointORoles()); |
| 237 | } |
| 238 | fact_axiom *fact_disjoint_d_roles (fact_reasoning_kernel *k) |
| 239 | { |
| 240 | return new fact_axiom_st(k->p->disjointDRoles()); |
| 241 | } |
| 242 | |
| 243 | fact_axiom* fact_set_o_domain (fact_reasoning_kernel *k, |
| 244 | fact_o_role_expression *r, |
| 245 | fact_concept_expression *c) |
| 246 | { |
| 247 | return new fact_axiom_st(k->p->setODomain(r->p,c->p)); |
| 248 | } |
| 249 | fact_axiom *fact_set_d_domain (fact_reasoning_kernel *k, |
| 250 | fact_d_role_expression *r, |
| 251 | fact_concept_expression *c) |
| 252 | { |
| 253 | return new fact_axiom_st(k->p->setDDomain(r->p,c->p)); |
| 254 | } |
| 255 | fact_axiom *fact_set_o_range (fact_reasoning_kernel *k, |
| 256 | fact_o_role_expression *r, |
| 257 | fact_concept_expression *c) |
| 258 | { |
| 259 | return new fact_axiom_st(k->p->setORange(r->p,c->p)); |
| 260 | } |
| 261 | fact_axiom *fact_set_d_range (fact_reasoning_kernel *k, |
| 262 | fact_d_role_expression *r, |
| 263 | fact_data_expression *e) |
| 264 | { |
| 265 | return new fact_axiom_st(k->p->setDRange(r->p,e->p)); |
| 266 | } |
| 267 | |
| 268 | fact_axiom *fact_set_transitive (fact_reasoning_kernel *k, |
| 269 | fact_o_role_expression *r) |
| 270 | { |
| 271 | return new fact_axiom_st(k->p->setTransitive(r->p)); |
| 272 | } |
| 273 | fact_axiom *fact_set_reflexive (fact_reasoning_kernel *k, |
| 274 | fact_o_role_expression *r) |
| 275 | { |
| 276 | return new fact_axiom_st(k->p->setReflexive(r->p)); |
| 277 | } |
| 278 | fact_axiom *fact_set_irreflexive (fact_reasoning_kernel *k, |
| 279 | fact_o_role_expression *r) |
| 280 | { |
| 281 | return new fact_axiom_st(k->p->setIrreflexive(r->p)); |
| 282 | } |
| 283 | fact_axiom *fact_set_symmetric (fact_reasoning_kernel *k, |
| 284 | fact_o_role_expression *r) |
| 285 | { |
| 286 | return new fact_axiom_st(k->p->setSymmetric(r->p)); |
| 287 | } |
| 288 | fact_axiom *fact_set_asymmetric (fact_reasoning_kernel *k, |
| 289 | fact_o_role_expression *r) |
| 290 | { |
| 291 | return new fact_axiom_st(k->p->setAsymmetric(r->p)); |
| 292 | } |
| 293 | fact_axiom *fact_set_o_functional (fact_reasoning_kernel *k, |
| 294 | fact_o_role_expression *r) |
| 295 | { |
| 296 | return new fact_axiom_st(k->p->setOFunctional(r->p)); |
| 297 | } |
| 298 | fact_axiom *fact_set_d_functional (fact_reasoning_kernel *k, |
| 299 | fact_d_role_expression *r) |
| 300 | { |
| 301 | return new fact_axiom_st(k->p->setDFunctional(r->p)); |
| 302 | } |
| 303 | fact_axiom *fact_set_inverse_functional (fact_reasoning_kernel *k, |
| 304 | fact_o_role_expression *r) |
| 305 | { |
| 306 | return new fact_axiom_st(k->p->setInverseFunctional(r->p)); |
| 307 | } |
| 308 | |
| 309 | fact_axiom *fact_instance_of (fact_reasoning_kernel *k, |
| 310 | fact_individual_expression *i, |
| 311 | fact_concept_expression *c) |
| 312 | { |
| 313 | return new fact_axiom_st(k->p->instanceOf(i->p,c->p)); |
| 314 | } |
| 315 | fact_axiom *fact_related_to (fact_reasoning_kernel *k, |
| 316 | fact_individual_expression *i, |
| 317 | fact_o_role_expression *r, |
| 318 | fact_individual_expression *j) |
| 319 | { |
| 320 | return new fact_axiom_st(k->p->relatedTo(i->p,r->p,j->p)); |
| 321 | } |
| 322 | fact_axiom *fact_related_to_not (fact_reasoning_kernel *k, |
| 323 | fact_individual_expression *i, |
| 324 | fact_o_role_expression *r, |
| 325 | fact_individual_expression *j) |
| 326 | { |
| 327 | return new fact_axiom_st(k->p->relatedToNot(i->p,r->p,j->p)); |
| 328 | } |
| 329 | fact_axiom *fact_value_of (fact_reasoning_kernel *k, |
| 330 | fact_individual_expression *i, |
| 331 | fact_d_role_expression *a, |
| 332 | fact_data_value_expression *v) |
| 333 | { |
| 334 | return new fact_axiom_st(k->p->valueOf(i->p,a->p,v->p)); |
| 335 | } |
| 336 | fact_axiom *fact_value_of_not (fact_reasoning_kernel *k, |
| 337 | fact_individual_expression *i, |
| 338 | fact_d_role_expression *a, |
| 339 | fact_data_value_expression *v) |
| 340 | { |
| 341 | return new fact_axiom_st(k->p->valueOfNot(i->p,a->p,v->p)); |
| 342 | } |
| 343 | fact_axiom *fact_process_same (fact_reasoning_kernel *k) |
| 344 | { |
| 345 | return new fact_axiom_st(k->p->processSame()); |
| 346 | } |
| 347 | fact_axiom *fact_process_different (fact_reasoning_kernel *k) |
| 348 | { |
| 349 | return new fact_axiom_st(k->p->processDifferent()); |
| 350 | } |
| 351 | fact_axiom *fact_set_fairness_constraint (fact_reasoning_kernel *k) |
| 352 | { |
| 353 | return new fact_axiom_st(k->p->setFairnessConstraint()); |
| 354 | } |
| 355 | |
| 356 | void fact_retract (fact_reasoning_kernel *k, fact_axiom *axiom) |
| 357 | { |
| 358 | k->p->retract(axiom->p); |
| 359 | } |
| 360 | |
| 361 | int fact_is_kb_consistent (fact_reasoning_kernel *k) |
| 362 | { |
| 363 | return k->p->isKBConsistent(); |
| 364 | } |
| 365 | void fact_preprocess_kb (fact_reasoning_kernel *k) |
| 366 | { |
| 367 | k->p->preprocessKB(); |
| 368 | } |
| 369 | void fact_classify_kb (fact_reasoning_kernel *k) |
| 370 | { |
| 371 | k->p->classifyKB(); |
| 372 | } |
| 373 | void fact_realise_kb (fact_reasoning_kernel *k) |
| 374 | { |
| 375 | k->p->realiseKB(); |
| 376 | } |
| 377 | |
| 378 | int fact_is_o_functional (fact_reasoning_kernel *k, fact_o_role_expression *r) |
| 379 | { |
| 380 | return k->p->isFunctional(r->p); |
| 381 | } |
| 382 | int fact_is_d_functional (fact_reasoning_kernel *k, |
| 383 | fact_d_role_expression *r) |
| 384 | { |
| 385 | return k->p->isFunctional(r->p); |
| 386 | } |
| 387 | int fact_is_inverse_functional (fact_reasoning_kernel *k, |
| 388 | fact_o_role_expression *r) |
| 389 | { |
| 390 | return k->p->isInverseFunctional(r->p); |
| 391 | } |
| 392 | int fact_is_transitive (fact_reasoning_kernel *k, fact_o_role_expression *r) |
| 393 | { |
| 394 | return k->p->isTransitive(r->p); |
| 395 | } |
| 396 | int fact_is_symmetric (fact_reasoning_kernel *k, fact_o_role_expression *r) |
| 397 | { |
| 398 | return k->p->isSymmetric(r->p); |
| 399 | } |
| 400 | int fact_is_asymmetric (fact_reasoning_kernel *k, fact_o_role_expression *r) |
| 401 | { |
| 402 | return k->p->isAsymmetric(r->p); |
| 403 | } |
| 404 | int fact_is_reflexive (fact_reasoning_kernel *k, fact_o_role_expression *r) |
| 405 | { |
| 406 | return k->p->isReflexive(r->p); |
| 407 | } |
| 408 | int fact_is_irreflexive (fact_reasoning_kernel *k, fact_o_role_expression *r) |
| 409 | { |
| 410 | return k->p->isIrreflexive(r->p); |
| 411 | } |
| 412 | int fact_is_sub_o_roles (fact_reasoning_kernel *k, fact_o_role_expression *r, |
| 413 | fact_o_role_expression *s) |
| 414 | { |
| 415 | return k->p->isSubRoles(r->p,s->p); |
| 416 | } |
| 417 | int fact_is_sub_d_roles (fact_reasoning_kernel *k, fact_d_role_expression *r, |
| 418 | fact_d_role_expression *s) |
| 419 | { |
| 420 | return k->p->isSubRoles(r->p,s->p); |
| 421 | } |
| 422 | int fact_is_disjoint_o_roles (fact_reasoning_kernel *k, |
| 423 | fact_o_role_expression *r, |
| 424 | fact_o_role_expression *s) |
| 425 | { |
| 426 | return k->p->isDisjointRoles(r->p,s->p); |
| 427 | } |
| 428 | int fact_is_disjoint_d_roles (fact_reasoning_kernel *k, |
| 429 | fact_d_role_expression *r, |
| 430 | fact_d_role_expression *s) |
| 431 | { |
| 432 | return k->p->isDisjointRoles(r->p,s->p); |
| 433 | } |
| 434 | int fact_is_disjoint_roles (fact_reasoning_kernel *k) |
| 435 | { |
| 436 | return k->p->isDisjointRoles(); |
| 437 | } |
| 438 | int fact_is_sub_chain (fact_reasoning_kernel *k, fact_o_role_expression *r) |
| 439 | { |
| 440 | return k->p->isSubChain(r->p); |
| 441 | } |
| 442 | |
| 443 | int fact_is_satisfiable (fact_reasoning_kernel *k, fact_concept_expression *c) |
| 444 | { |
| 445 | return k->p->isSatisfiable(c->p); |
| 446 | } |
| 447 | int fact_is_subsumed_by (fact_reasoning_kernel *k, fact_concept_expression *c, |
| 448 | fact_concept_expression *d) |
| 449 | { |
| 450 | return k->p->isSubsumedBy(c->p,d->p); |
| 451 | } |
| 452 | int fact_is_disjoint (fact_reasoning_kernel *k, fact_concept_expression *c, |
| 453 | fact_concept_expression *d) |
| 454 | { |
| 455 | return k->p->isDisjoint(c->p,d->p); |
| 456 | } |
| 457 | int fact_is_equivalent (fact_reasoning_kernel *k, fact_concept_expression *c, |
| 458 | fact_concept_expression *d) |
| 459 | { |
| 460 | return k->p->isEquivalent(c->p,d->p); |
| 461 | } |
| 462 | |
| 463 | void fact_get_sup_concepts (fact_reasoning_kernel *k, fact_concept_expression *c, |
| 464 | int direct, fact_actor **actor) |
| 465 | { |
| 466 | k->p->getSupConcepts(c->p,direct,*(*actor)->p); |
| 467 | } |
| 468 | void fact_get_sub_concepts (fact_reasoning_kernel *k, fact_concept_expression *c, |
| 469 | int direct, fact_actor **actor) |
| 470 | { |
| 471 | k->p->getSubConcepts(c->p,direct,*(*actor)->p); |
| 472 | } |
| 473 | void fact_get_equivalent_concepts (fact_reasoning_kernel *k, |
| 474 | fact_concept_expression *c, |
| 475 | fact_actor **actor) |
| 476 | { |
| 477 | k->p->getEquivalentConcepts(c->p,*(*actor)->p); |
| 478 | } |
| 479 | void fact_get_disjoint_concepts (fact_reasoning_kernel *k, |
| 480 | fact_concept_expression *c, |
| 481 | fact_actor **actor) |
| 482 | { |
| 483 | k->p->getDisjointConcepts(c->p,*(*actor)->p); |
| 484 | } |
| 485 | |
| 486 | void fact_get_sup_roles (fact_reasoning_kernel *k, fact_role_expression *r, |
| 487 | int direct, |
| 488 | fact_actor **actor) |
| 489 | { |
| 490 | k->p->getSupRoles(r->p,direct,*(*actor)->p); |
| 491 | } |
| 492 | void fact_get_sub_roles (fact_reasoning_kernel *k, fact_role_expression *r, |
| 493 | int direct, fact_actor **actor) |
| 494 | { |
| 495 | k->p->getSubRoles(r->p,direct,*(*actor)->p); |
| 496 | } |
| 497 | void fact_get_equivalent_roles (fact_reasoning_kernel *k, fact_role_expression *r, |
| 498 | fact_actor **actor) |
| 499 | { |
| 500 | k->p->getEquivalentRoles(r->p,*(*actor)->p); |
| 501 | } |
| 502 | void fact_get_o_role_domain (fact_reasoning_kernel *k, fact_o_role_expression *r, |
| 503 | int direct, fact_actor **actor) |
| 504 | { |
| 505 | k->p->getORoleDomain(r->p,direct,*(*actor)->p); |
| 506 | } |
| 507 | void fact_get_d_role_domain (fact_reasoning_kernel *k, fact_d_role_expression *r, |
| 508 | int direct, fact_actor **actor) |
| 509 | { |
| 510 | k->p->getDRoleDomain(r->p,direct,*(*actor)->p); |
| 511 | } |
| 512 | void fact_get_role_range (fact_reasoning_kernel *k, fact_o_role_expression *r, |
| 513 | int direct, fact_actor **actor) |
| 514 | { |
| 515 | k->p->getRoleRange(r->p,direct,*(*actor)->p); |
| 516 | } |
| 517 | void fact_get_direct_instances (fact_reasoning_kernel *k, |
| 518 | fact_concept_expression *c, fact_actor **actor) |
| 519 | { |
| 520 | k->p->getDirectInstances(c->p,*(*actor)->p); |
| 521 | } |
| 522 | void fact_get_instances (fact_reasoning_kernel *k, fact_concept_expression *c, |
| 523 | fact_actor **actor) |
| 524 | { |
| 525 | k->p->getInstances(c->p,*(*actor)->p); |
| 526 | } |
| 527 | void fact_get_types (fact_reasoning_kernel *k, fact_individual_expression *i, |
| 528 | int direct, fact_actor **actor) |
| 529 | { |
| 530 | k->p->getTypes(i->p,direct,*(*actor)->p); |
| 531 | } |
| 532 | void fact_get_same_as (fact_reasoning_kernel *k, |
| 533 | fact_individual_expression *i, fact_actor **actor) |
| 534 | { |
| 535 | k->p->getSameAs(i->p,*(*actor)->p); |
| 536 | } |
| 537 | |
| 538 | int fact_is_same_individuals (fact_reasoning_kernel *k, |
| 539 | fact_individual_expression *i, |
| 540 | fact_individual_expression *j) |
| 541 | { |
| 542 | return k->p->isSameIndividuals(i->p,j->p); |
| 543 | } |
| 544 | int fact_is_instance (fact_reasoning_kernel *k, |
| 545 | fact_individual_expression *i, |
| 546 | fact_concept_expression *c) |
| 547 | { |
| 548 | return k->p->isInstance(i->p,c->p); |
| 549 | } |
| 550 | int fact_is_related (fact_reasoning_kernel *k, |
| 551 | fact_individual_expression *i, |
| 552 | fact_o_role_expression *r, |
| 553 | fact_individual_expression *j) |
| 554 | { |
| 555 | return k->p->isRelated(i->p,r->p,j->p); |
| 556 | } |
| 557 | fact_actor* fact_concept_actor_new() |
| 558 | { |
| 559 | fact_actor* ret = new fact_actor(new CActor()); |
| 560 | ret->p->needConcepts(); |
| 561 | return ret; |
| 562 | } |
| 563 | fact_actor* fact_individual_actor_new() |
| 564 | { |
| 565 | fact_actor* ret = new fact_actor(new CActor()); |
| 566 | ret->p->needIndividuals(); |
| 567 | return ret; |
| 568 | } |
| 569 | fact_actor* fact_o_role_actor_new() |
| 570 | { |
| 571 | fact_actor* ret = new fact_actor(new CActor()); |
| 572 | ret->p->needObjectRoles(); |
| 573 | return ret; |
| 574 | } |
| 575 | fact_actor* fact_d_role_actor_new() |
| 576 | { |
| 577 | fact_actor* ret = new fact_actor(new CActor()); |
| 578 | ret->p->needDataRoles(); |
| 579 | return ret; |
| 580 | } |
| 581 | void fact_actor_free ( fact_actor* actor ) |
| 582 | { |
| 583 | delete actor->p; |
| 584 | delete actor; |
| 585 | } |
| 586 | /// get 1-d NULL-terminated array of synonyms of the 1st entry(necessary for Equivalents, for example) |
| 587 | const char** fact_get_synonyms ( fact_actor* actor ) |
| 588 | { |
| 589 | return actor->p->getSynonyms(); |
| 590 | } |
| 591 | /// get NULL-terminated 2D array of all required elements of the taxonomy |
| 592 | const char*** fact_get_elements_2d ( fact_actor* actor ) |
| 593 | { |
| 594 | return actor->p->getElements2D(); |
| 595 | } |
| 596 | /// get NULL-terminated 1D array of all required elements of the taxonomy |
| 597 | const char** fact_get_elements_1d ( fact_actor* actor ) |
| 598 | { |
| 599 | return actor->p->getElements1D(); |
| 600 | } |
| 601 | |
| 602 | /// opens new argument list |
| 603 | void fact_new_arg_list ( fact_reasoning_kernel *k ) |
| 604 | { |
| 605 | k->p->getExpressionManager()->newArgList(); |
| 606 | } |
| 607 | /// add argument E to the current argument list |
| 608 | void fact_add_arg ( fact_reasoning_kernel *k,fact_expression* e ) |
| 609 | { |
| 610 | k->p->getExpressionManager()->addArg(e->p); |
| 611 | } |
| 612 | |
| 613 | // create expressions methods |
| 614 | |
| 615 | // concepts |
| 616 | |
| 617 | /// get TOP concept |
| 618 | fact_concept_expression* fact_top ( fact_reasoning_kernel *k ) |
| 619 | { |
| 620 | return new fact_concept_expression(k->p->getExpressionManager()->Top()); |
| 621 | } |
| 622 | /// get BOTTOM concept |
| 623 | fact_concept_expression* fact_bottom ( fact_reasoning_kernel *k ) |
| 624 | { |
| 625 | return new fact_concept_expression(k->p->getExpressionManager()->Bottom()); |
| 626 | } |
| 627 | /// get named concept |
| 628 | fact_concept_expression* fact_concept ( fact_reasoning_kernel *k,const char* name ) |
| 629 | { |
| 630 | return new fact_concept_expression(k->p->getExpressionManager()->Concept(name)); |
| 631 | } |
| 632 | /// get negation of a concept c |
| 633 | fact_concept_expression* fact_not ( fact_reasoning_kernel *k,fact_concept_expression* c ) |
| 634 | { |
| 635 | return new fact_concept_expression(k->p->getExpressionManager()->Not(c->p)); |
| 636 | } |
| 637 | /// get an n-ary conjunction expression; take the arguments from the last argument list |
| 638 | fact_concept_expression* fact_and ( fact_reasoning_kernel *k ) |
| 639 | { |
| 640 | return new fact_concept_expression(k->p->getExpressionManager()->And()); |
| 641 | } |
| 642 | /// get an n-ary disjunction expression; take the arguments from the last argument list |
| 643 | fact_concept_expression* fact_or ( fact_reasoning_kernel *k ) |
| 644 | { |
| 645 | return new fact_concept_expression(k->p->getExpressionManager()->Or()); |
| 646 | } |
| 647 | /// get an n-ary one-of expression; take the arguments from the last argument list |
| 648 | fact_concept_expression* fact_one_of ( fact_reasoning_kernel *k ) |
| 649 | { |
| 650 | return new fact_concept_expression(k->p->getExpressionManager()->OneOf()); |
| 651 | } |
| 652 | |
| 653 | /// get self-reference restriction of an object role r |
| 654 | fact_concept_expression* fact_self_reference ( fact_reasoning_kernel *k,fact_o_role_expression* r ) |
| 655 | { |
| 656 | return new fact_concept_expression(k->p->getExpressionManager()->SelfReference(r->p)); |
| 657 | } |
| 658 | /// get value restriction wrt an object role r and an individual i |
| 659 | fact_concept_expression* fact_o_value ( fact_reasoning_kernel *k,fact_o_role_expression* r, fact_individual_expression* i ) |
| 660 | { |
| 661 | return new fact_concept_expression(k->p->getExpressionManager()->Value(r->p,i->p)); |
| 662 | } |
| 663 | /// get existential restriction wrt an object role r and a concept c |
| 664 | fact_concept_expression* fact_o_exists ( fact_reasoning_kernel *k,fact_o_role_expression* r, fact_concept_expression* c ) |
| 665 | { |
| 666 | return new fact_concept_expression(k->p->getExpressionManager()->Exists(r->p,c->p)); |
| 667 | } |
| 668 | /// get universal restriction wrt an object role r and a concept c |
| 669 | fact_concept_expression* fact_o_forall ( fact_reasoning_kernel *k,fact_o_role_expression* r, fact_concept_expression* c ) |
| 670 | { |
| 671 | return new fact_concept_expression(k->p->getExpressionManager()->Forall(r->p,c->p)); |
| 672 | } |
| 673 | /// get min cardinality restriction wrt number _n, an object role r and a concept c |
| 674 | fact_concept_expression* fact_o_min_cardinality ( fact_reasoning_kernel *k,unsigned int n, fact_o_role_expression* r, fact_concept_expression* c ) |
| 675 | { |
| 676 | return new fact_concept_expression(k->p->getExpressionManager()->MinCardinality(n,r->p,c->p)); |
| 677 | } |
| 678 | /// get max cardinality restriction wrt number _n, an object role r and a concept c |
| 679 | fact_concept_expression* fact_o_max_cardinality ( fact_reasoning_kernel *k,unsigned int n, fact_o_role_expression* r, fact_concept_expression* c ) |
| 680 | { |
| 681 | return new fact_concept_expression(k->p->getExpressionManager()->MaxCardinality(n,r->p,c->p)); |
| 682 | } |
| 683 | /// get exact cardinality restriction wrt number _n, an object role r and a concept c |
| 684 | fact_concept_expression* fact_o_cardinality ( fact_reasoning_kernel *k,unsigned int n, fact_o_role_expression* r, fact_concept_expression* c ) |
| 685 | { |
| 686 | return new fact_concept_expression(k->p->getExpressionManager()->Cardinality(n,r->p,c->p)); |
| 687 | } |
| 688 | |
| 689 | /// get value restriction wrt a data role r and a data value v |
| 690 | fact_concept_expression* fact_d_value ( fact_reasoning_kernel *k,fact_d_role_expression* r, fact_data_value_expression* v ) |
| 691 | { |
| 692 | return new fact_concept_expression(k->p->getExpressionManager()->Value(r->p,v->p)); |
| 693 | } |
| 694 | /// get existential restriction wrt a data role r and a data expression e |
| 695 | fact_concept_expression* fact_d_exists ( fact_reasoning_kernel *k,fact_d_role_expression* r, fact_data_expression* e ) |
| 696 | { |
| 697 | return new fact_concept_expression(k->p->getExpressionManager()->Exists(r->p,e->p)); |
| 698 | } |
| 699 | /// get universal restriction wrt a data role r and a data expression e |
| 700 | fact_concept_expression* fact_d_forall ( fact_reasoning_kernel *k,fact_d_role_expression* r, fact_data_expression* e ) |
| 701 | { |
| 702 | return new fact_concept_expression(k->p->getExpressionManager()->Forall(r->p,e->p)); |
| 703 | } |
| 704 | /// get min cardinality restriction wrt number _n, a data role r and a data expression e |
| 705 | fact_concept_expression* fact_d_min_cardinality ( fact_reasoning_kernel *k,unsigned int n, fact_d_role_expression* r, fact_data_expression* e ) |
| 706 | { |
| 707 | return new fact_concept_expression(k->p->getExpressionManager()->MinCardinality(n,r->p,e->p)); |
| 708 | } |
| 709 | /// get max cardinality restriction wrt number _n, a data role r and a data expression e |
| 710 | fact_concept_expression* fact_d_max_cardinality ( fact_reasoning_kernel *k,unsigned int n, fact_d_role_expression* r, fact_data_expression* e ) |
| 711 | { |
| 712 | return new fact_concept_expression(k->p->getExpressionManager()->MaxCardinality(n,r->p,e->p)); |
| 713 | } |
| 714 | /// get exact cardinality restriction wrt number _n, a data role r and a data expression e |
| 715 | fact_concept_expression* fact_d_cardinality ( fact_reasoning_kernel *k,unsigned int n, fact_d_role_expression* r, fact_data_expression* e ) |
| 716 | { |
| 717 | return new fact_concept_expression(k->p->getExpressionManager()->Cardinality(n,r->p,e->p)); |
| 718 | } |
| 719 | |
| 720 | // individuals |
| 721 | |
| 722 | /// get named individual |
| 723 | fact_individual_expression* fact_individual ( fact_reasoning_kernel *k,const char* name ) |
| 724 | { |
| 725 | return new fact_individual_expression(k->p->getExpressionManager()->Individual(name)); |
| 726 | } |
| 727 | |
| 728 | // object roles |
| 729 | |
| 730 | /// get TOP object role |
| 731 | fact_o_role_expression* fact_object_role_top ( fact_reasoning_kernel *k ) |
| 732 | { |
| 733 | return new fact_o_role_expression(k->p->getExpressionManager()->ObjectRoleTop()); |
| 734 | } |
| 735 | /// get BOTTOM object role |
| 736 | fact_o_role_expression* fact_object_role_bottom ( fact_reasoning_kernel *k ) |
| 737 | { |
| 738 | return new fact_o_role_expression(k->p->getExpressionManager()->ObjectRoleBottom()); |
| 739 | } |
| 740 | /// get named object role |
| 741 | fact_o_role_expression* fact_object_role ( fact_reasoning_kernel *k,const char* name ) |
| 742 | { |
| 743 | return new fact_o_role_expression(k->p->getExpressionManager()->ObjectRole(name)); |
| 744 | } |
| 745 | /// get an inverse of a given object role expression r |
| 746 | fact_o_role_expression* fact_inverse ( fact_reasoning_kernel *k,fact_o_role_expression* r ) |
| 747 | { |
| 748 | return new fact_o_role_expression(k->p->getExpressionManager()->Inverse(r->p)); |
| 749 | } |
| 750 | /// get a role chain corresponding to _r1 o ... o _rn; take the arguments from the last argument list |
| 751 | fact_o_role_complex_expression* fact_compose ( fact_reasoning_kernel *k ) |
| 752 | { |
| 753 | return new fact_o_role_complex_expression(k->p->getExpressionManager()->Compose()); |
| 754 | } |
| 755 | /// get a expression corresponding to r projected from c |
| 756 | fact_o_role_complex_expression* fact_project_from ( fact_reasoning_kernel *k,fact_o_role_expression* r, fact_concept_expression* c ) |
| 757 | { |
| 758 | return new fact_o_role_complex_expression(k->p->getExpressionManager()->ProjectFrom(r->p,c->p)); |
| 759 | } |
| 760 | /// get a expression corresponding to r projected into c |
| 761 | fact_o_role_complex_expression* fact_project_into ( fact_reasoning_kernel *k,fact_o_role_expression* r, fact_concept_expression* c ) |
| 762 | { |
| 763 | return new fact_o_role_complex_expression(k->p->getExpressionManager()->ProjectInto(r->p,c->p)); |
| 764 | } |
| 765 | |
| 766 | // data roles |
| 767 | |
| 768 | /// get TOP data role |
| 769 | fact_d_role_expression* fact_data_role_top ( fact_reasoning_kernel *k ) |
| 770 | { |
| 771 | return new fact_d_role_expression(k->p->getExpressionManager()->DataRoleTop()); |
| 772 | } |
| 773 | /// get BOTTOM data role |
| 774 | fact_d_role_expression* fact_data_role_bottom ( fact_reasoning_kernel *k ) |
| 775 | { |
| 776 | return new fact_d_role_expression(k->p->getExpressionManager()->DataRoleBottom()); |
| 777 | } |
| 778 | /// get named data role |
| 779 | fact_d_role_expression* fact_data_role ( fact_reasoning_kernel *k,const char* name ) |
| 780 | { |
| 781 | return new fact_d_role_expression(k->p->getExpressionManager()->DataRole(name)); |
| 782 | } |
| 783 | |
| 784 | // data expressions |
| 785 | |
| 786 | /// get TOP data element |
| 787 | fact_data_expression* fact_data_top ( fact_reasoning_kernel *k ) |
| 788 | { |
| 789 | return new fact_data_expression(k->p->getExpressionManager()->DataTop()); |
| 790 | } |
| 791 | /// get BOTTOM data element |
| 792 | fact_data_expression* fact_data_bottom ( fact_reasoning_kernel *k ) |
| 793 | { |
| 794 | return new fact_data_expression(k->p->getExpressionManager()->DataBottom()); |
| 795 | } |
| 796 | |
| 797 | /// get named data type |
| 798 | fact_data_type_expression* fact_data_type ( fact_reasoning_kernel *k,const char* name ) |
| 799 | { |
| 800 | return new fact_data_type_expression(k->p->getExpressionManager()->DataType(name)); |
| 801 | } |
| 802 | /// get basic string data type |
| 803 | fact_data_type_expression* fact_get_str_data_type ( fact_reasoning_kernel *k ) |
| 804 | { |
| 805 | return new fact_data_type_expression(k->p->getExpressionManager()->getStrDataType()); |
| 806 | } |
| 807 | /// get basic integer data type |
| 808 | fact_data_type_expression* fact_get_int_data_type ( fact_reasoning_kernel *k ) |
| 809 | { |
| 810 | return new fact_data_type_expression(k->p->getExpressionManager()->getIntDataType()); |
| 811 | } |
| 812 | /// get basic floating point data type |
| 813 | fact_data_type_expression* fact_get_real_data_type ( fact_reasoning_kernel *k ) |
| 814 | { |
| 815 | return new fact_data_type_expression(k->p->getExpressionManager()->getRealDataType()); |
| 816 | } |
| 817 | /// get basic boolean data type |
| 818 | fact_data_type_expression* fact_get_bool_data_type ( fact_reasoning_kernel *k ) |
| 819 | { |
| 820 | return new fact_data_type_expression(k->p->getExpressionManager()->getBoolDataType()); |
| 821 | } |
| 822 | /// get basic date-time data type |
| 823 | fact_data_type_expression* fact_get_time_data_type ( fact_reasoning_kernel *k ) |
| 824 | { |
| 825 | return new fact_data_type_expression(k->p->getExpressionManager()->getTimeDataType()); |
| 826 | } |
| 827 | |
| 828 | /// get basic boolean data type |
| 829 | fact_data_type_expression* fact_restricted_type ( fact_reasoning_kernel *k,fact_data_type_expression* type, fact_facet_expression* facet ) |
| 830 | { |
| 831 | return new fact_data_type_expression(k->p->getExpressionManager()->RestrictedType(type->p,facet->p)); |
| 832 | } |
| 833 | |
| 834 | /// get data value with given VALUE and TYPE; |
| 835 | fact_data_value_expression* fact_data_value ( fact_reasoning_kernel *k,const char* value, fact_data_type_expression* type ) |
| 836 | { |
| 837 | return new fact_data_value_expression(k->p->getExpressionManager()->DataValue(value,type->p)); |
| 838 | } |
| 839 | /// get negation of a data expression e |
| 840 | fact_data_expression* fact_data_not ( fact_reasoning_kernel *k,fact_data_expression* e ) |
| 841 | { |
| 842 | return new fact_data_expression(k->p->getExpressionManager()->DataNot(e->p)); |
| 843 | } |
| 844 | /// get an n-ary data conjunction expression; take the arguments from the last argument list |
| 845 | fact_data_expression* fact_data_and ( fact_reasoning_kernel *k ) |
| 846 | { |
| 847 | return new fact_data_expression(k->p->getExpressionManager()->DataAnd()); |
| 848 | } |
| 849 | /// get an n-ary data disjunction expression; take the arguments from the last argument list |
| 850 | fact_data_expression* fact_data_or ( fact_reasoning_kernel *k ) |
| 851 | { |
| 852 | return new fact_data_expression(k->p->getExpressionManager()->DataOr()); |
| 853 | } |
| 854 | /// get an n-ary data one-of expression; take the arguments from the last argument list |
| 855 | fact_data_expression* fact_data_one_of ( fact_reasoning_kernel *k ) |
| 856 | { |
| 857 | return new fact_data_expression(k->p->getExpressionManager()->DataOneOf()); |
| 858 | } |
| 859 | /// get min_inclusive facet with a given _v |
| 860 | fact_facet_expression* fact_facet_min_inclusive ( fact_reasoning_kernel *k,fact_data_value_expression* v ) |
| 861 | { |
| 862 | return new fact_facet_expression(k->p->getExpressionManager()->FacetMinInclusive(v->p)); |
| 863 | } |
| 864 | /// get min_exclusive facet with a given _v |
| 865 | fact_facet_expression* fact_facet_min_exclusive ( fact_reasoning_kernel *k,fact_data_value_expression* v ) |
| 866 | { |
| 867 | return new fact_facet_expression(k->p->getExpressionManager()->FacetMinExclusive(v->p)); |
| 868 | } |
| 869 | /// get max_inclusive facet with a given _v |
| 870 | fact_facet_expression* fact_facet_max_inclusive ( fact_reasoning_kernel *k,fact_data_value_expression* v ) |
| 871 | { |
| 872 | return new fact_facet_expression(k->p->getExpressionManager()->FacetMaxInclusive(v->p)); |
| 873 | } |
| 874 | /// get max_exclusive facet with a given _v |
| 875 | fact_facet_expression* fact_facet_max_exclusive ( fact_reasoning_kernel *k,fact_data_value_expression* v ) |
| 876 | { |
| 877 | return new fact_facet_expression(k->p->getExpressionManager()->FacetMaxExclusive(v->p)); |
| 878 | } |
| 879 | void fact_kb_set_tracing(fact_reasoning_kernel *k) |
| 880 | { |
| 881 | k->p->needTracing(); |
| 882 | } |
| 883 | |
| 884 | void fact_kb_set_dump(fact_reasoning_kernel *k) |
| 885 | { |
| 886 | k->p->setDumpOntology(true); |
| 887 | } |
| 888 | const char **fact_get_role_fillers(fact_reasoning_kernel *k, fact_individual_expression *i, fact_o_role_expression *r) { |
| 889 | ReasoningKernel::IndividualSet s = ReasoningKernel::IndividualSet(); |
| 890 | k->p->getRoleFillers(i->p, r->p, s); |
| 891 | |
| 892 | const char** result = new const char*[s.size() + 1]; |
| 893 | for (size_t i = 0; i < s.size(); ++i) |
| 894 | result[i] = s[i]->getName(); |
| 895 | result[s.size()] = NULL; |
| 896 | return result; |
| 897 | } |