Ontology
Python classes in this page are strongly dependent on the OWLAPI library.
The base class Ontology
extends several features
including convenient access to specially defined entities (e.g., owl:Thing
and owl:Nothing
),
indexing of entities in the signature with their IRIs as keys, and some other customised functions
for specific ontology engineering purposes. Ontology
also has an
OntologyReasoner
attribute which provides reasoning facilities
such as classifying entities, checking entailment, and so on. Users who are familiar with the OWLAPI
should feel relatively easy to extend the Python classes here.
Ontology(owl_path, reasoner_type='hermit')
Ontology class that extends from the Java library OWLAPI.
Typing from OWLAPI
Types with OWL
prefix are mostly imported from the OWLAPI library by, for example,
from org.semanticweb.owlapi.model import OWLObject
.
Attributes:
Name | Type | Description |
---|---|---|
owl_path |
str
|
The path to the OWL ontology file. |
owl_manager |
OWLOntologyManager
|
A ontology manager for creating |
owl_onto |
OWLOntology
|
An |
owl_iri |
str
|
The IRI of the |
owl_classes |
dict[str, OWLClass]
|
A dictionary that stores the |
owl_object_properties |
dict[str, OWLObjectProperty]
|
A dictionary that stores the |
owl_data_properties |
dict[str, OWLDataProperty]
|
A dictionary that stores the |
owl_annotation_properties |
dict[str, OWLAnnotationProperty]
|
A dictionary that stores the |
owl_individuals |
dict[str, OWLIndividual]
|
A dictionary that stores the |
owl_data_factory |
OWLDataFactory
|
A data factory for manipulating axioms. |
reasoner_type |
str
|
The type of reasoner used. Defaults to |
reasoner |
OntologyReasoner
|
A reasoner for ontology inference. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
owl_path |
str
|
The path to the OWL ontology file. |
required |
reasoner_type |
str
|
The type of reasoner used. Defaults to |
'hermit'
|
Source code in src/deeponto/onto/ontology.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
name
property
Return the name of the ontology file.
OWLThing
property
Return OWLThing
.
OWLNothing
property
Return OWLNoThing
.
OWLTopObjectProperty
property
Return OWLTopObjectProperty
.
OWLBottomObjectProperty
property
Return OWLBottomObjectProperty
.
OWLTopDataProperty
property
Return OWLTopDataProperty
.
OWLBottomDataProperty
property
Return OWLBottomDataProperty
.
sibling_class_groups: list[list[str]]
property
Return grouped sibling classes (with a common direct parent);
NOTE that only groups with size > 1 will be considered
get_entity_type(entity, return_singular=False)
staticmethod
A handy method to get the type
of an OWLObject
entity.
Source code in src/deeponto/onto/ontology.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
|
get_max_jvm_memory()
staticmethod
Get the maximum heap size assigned to the JVM.
Source code in src/deeponto/onto/ontology.py
210 211 212 213 214 215 216 |
|
get_owl_object(iri)
Get an OWLObject
given its IRI.
Source code in src/deeponto/onto/ontology.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
|
get_iri(owl_object)
Get the IRI of an OWLObject
. Raises an exception if there is no associated IRI.
Source code in src/deeponto/onto/ontology.py
248 249 250 251 252 253 |
|
get_axiom_type(axiom)
staticmethod
Get the axiom type (in str
) for the given axiom.
Check full list at: http://owlcs.github.io/owlapi/apidocs_5/org/semanticweb/owlapi/model/AxiomType.html.
Source code in src/deeponto/onto/ontology.py
255 256 257 258 259 260 261 |
|
get_all_axioms()
Return all axioms (in a list) asserted in the ontology.
Source code in src/deeponto/onto/ontology.py
263 264 265 |
|
get_subsumption_axioms(entity_type='Classes')
Return subsumption axioms (subject to input entity type) asserted in the ontology.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entity_type |
str
|
The entity type to be considered. Defaults to |
'Classes'
|
Returns:
Type | Description |
---|---|
List[OWLAxiom]
|
A list of equivalence axioms subject to input entity type. |
Source code in src/deeponto/onto/ontology.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
|
get_equivalence_axioms(entity_type='Classes')
Return equivalence axioms (subject to input entity type) asserted in the ontology.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entity_type |
str
|
The entity type to be considered. Defaults to |
'Classes'
|
Returns:
Type | Description |
---|---|
list[OWLAxiom]
|
A list of equivalence axioms subject to input entity type. |
Source code in src/deeponto/onto/ontology.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
|
get_assertion_axioms(entity_type='Classes')
Return assertion (ABox) axioms (subject to input entity type) asserted in the ontology.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entity_type |
str
|
The entity type to be considered. Defaults to |
'Classes'
|
Returns:
Type | Description |
---|---|
list[OWLAxiom]
|
A list of assertion axioms subject to input entity type. |
Source code in src/deeponto/onto/ontology.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
|
get_asserted_parents(owl_object, named_only=False)
Get all the asserted parents of a given owl object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
owl_object |
OWLObject
|
An owl object that could have a parent. |
required |
named_only |
bool
|
If |
False
|
Returns:
Type | Description |
---|---|
set[OWLObject]
|
The parent set of the given owl object. |
Source code in src/deeponto/onto/ontology.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
|
get_asserted_children(owl_object, named_only=False)
Get all the asserted children of a given owl object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
owl_object |
OWLObject
|
An owl object that could have a child. |
required |
named_only |
bool
|
If |
False
|
Returns:
Type | Description |
---|---|
set[OWLObject]
|
The children set of the given owl object. |
Source code in src/deeponto/onto/ontology.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
|
get_asserted_complex_classes(gci_only=False)
Get complex classes that occur in at least one of the ontology axioms.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gci_only |
bool
|
If |
False
|
Returns:
Type | Description |
---|---|
set[OWLClassExpression]
|
A set of complex classes. |
Source code in src/deeponto/onto/ontology.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
|
get_annotations(owl_object, annotation_property_iri=None, annotation_language_tag=None, apply_lowercasing=False, normalise_identifiers=False)
Get the annotation literals of the given OWLObject
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
owl_object |
Union[OWLObject, str]
|
An |
required |
annotation_property_iri |
str
|
Any particular annotation property IRI of interest. Defaults to |
None
|
annotation_language_tag |
str
|
Any particular annotation language tag of interest; NOTE that not every
annotation has a language tag, in this case assume it is in English.
Defaults to |
None
|
apply_lowercasing |
bool
|
Whether or not to apply lowercasing to annotation literals.
Defaults to |
False
|
normalise_identifiers |
bool
|
Whether to normalise annotation text that is in the Java identifier format.
Defaults to |
False
|
Returns:
Type | Description |
---|---|
set[str]
|
A set of annotation literals of the given |
Source code in src/deeponto/onto/ontology.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 |
|
check_consistency()
Check if the ontology is consistent according to the pre-loaded reasoner.
Source code in src/deeponto/onto/ontology.py
460 461 462 463 |
|
check_named_entity(owl_object)
Check if the input entity is a named atomic entity. That is, it is not a complex entity, \(\top\), or \(\bot\).
Source code in src/deeponto/onto/ontology.py
465 466 467 468 469 470 471 472 473 474 475 476 |
|
check_deprecated(owl_object)
Check if the given OWL object is marked as deprecated according to \(\texttt{owl:deprecated}\).
NOTE: the string literal indicating deprecation is either 'true'
or 'True'
. Also, if \(\texttt{owl:deprecated}\)
is not defined in this ontology, return False
by default.
Source code in src/deeponto/onto/ontology.py
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 |
|
save_onto(save_path)
Save the ontology file to the given path.
Source code in src/deeponto/onto/ontology.py
524 525 526 |
|
build_annotation_index(annotation_property_iris=[RDFS_LABEL], entity_type='Classes', apply_lowercasing=False, normalise_identifiers=False)
Build an annotation index for a given type of entities.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
annotation_property_iris |
list[str]
|
A list of annotation property IRIs (it is possible
that not every annotation property IRI is in use); if not provided, the built-in
|
[RDFS_LABEL]
|
entity_type |
str
|
The entity type to be considered. Defaults to |
'Classes'
|
apply_lowercasing |
bool
|
Whether or not to apply lowercasing to annotation literals.
Defaults to |
False
|
normalise_identifiers |
bool
|
Whether to normalise annotation text that is in the Java identifier format.
Defaults to |
False
|
Returns:
Type | Description |
---|---|
Tuple[dict, list[str]]
|
The built annotation index, and the list of annotation property IRIs that are in use. |
Source code in src/deeponto/onto/ontology.py
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 |
|
build_inverted_annotation_index(annotation_index, tokenizer)
staticmethod
Build an inverted annotation index given an annotation index and a tokenizer.
Source code in src/deeponto/onto/ontology.py
577 578 579 580 |
|
add_axiom(owl_axiom, return_undo=True)
Add an axiom into the current ontology.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
owl_axiom |
OWLAxiom
|
An axiom to be added. |
required |
return_undo |
bool
|
Returning the undo operation or not. Defaults to |
True
|
Source code in src/deeponto/onto/ontology.py
582 583 584 585 586 587 588 589 590 591 592 593 |
|
remove_axiom(owl_axiom, return_undo=True)
Remove an axiom from the current ontology.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
owl_axiom |
OWLAxiom
|
An axiom to be removed. |
required |
return_undo |
bool
|
Returning the undo operation or not. Defaults to |
True
|
Source code in src/deeponto/onto/ontology.py
595 596 597 598 599 600 601 602 603 604 605 606 |
|
replace_entity(owl_object, entity_iri, replacement_iri)
Replace an entity in a class expression with another entity.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
owl_object |
OWLObject
|
An |
required |
entity_iri |
str
|
IRI of the entity to be replaced. |
required |
replacement_iri |
str
|
IRI of the entity to replace. |
required |
Returns:
Type | Description |
---|---|
OWLObject
|
The changed |
Source code in src/deeponto/onto/ontology.py
608 609 610 611 612 613 614 615 616 617 618 619 620 621 |
|
Created: January 13, 2023