Ontology Reasoning
OntologyReasoner(onto, reasoner_type)
Ontology reasoner class that extends from the Java library OWLAPI.
Attributes:
Name | Type | Description |
---|---|---|
onto |
Ontology
|
The input |
owl_reasoner_factory |
OWLReasonerFactory
|
A reasoner factory for creating a reasoner. |
owl_reasoner |
OWLReasoner
|
The created reasoner. |
owl_data_factory |
OWLDataFactory
|
A data factory (inherited from |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
onto |
Ontology
|
The input ontology to conduct reasoning on. |
required |
reasoner_type |
str
|
The type of reasoner used. Options are |
required |
Source code in src/deeponto/onto/ontology.py
628 629 630 631 632 633 634 635 636 637 638 639 640 |
|
load_reasoner(reasoner_type)
Load a new reaonser and dispose the old one if existed.
Source code in src/deeponto/onto/ontology.py
642 643 644 645 646 647 648 649 650 651 652 653 654 655 |
|
get_entity_type(entity, is_singular=False)
staticmethod
A handy method to get the type of an entity (OWLObject
).
NOTE: This method is inherited from the Ontology Class.
Source code in src/deeponto/onto/ontology.py
657 658 659 660 661 662 663 |
|
has_iri(entity)
staticmethod
Check if an entity has an IRI.
Source code in src/deeponto/onto/ontology.py
665 666 667 668 669 670 671 672 |
|
get_inferred_super_entities(entity, direct=False)
Return the IRIs of named super-entities of a given OWLObject
according to the reasoner.
A mixture of getSuperClasses
, getSuperObjectProperties
, getSuperDataProperties
functions imported from the OWLAPI reasoner. The type of input entity will be
automatically determined. The top entity such as owl:Thing
is ignored.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entity |
OWLObject
|
An |
required |
direct |
bool
|
Return parents ( |
False
|
Returns:
Type | Description |
---|---|
list[str]
|
A list of IRIs of the super-entities of the given |
Source code in src/deeponto/onto/ontology.py
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 |
|
get_inferred_sub_entities(entity, direct=False)
Return the IRIs of named sub-entities of a given OWLObject
according to the reasoner.
A mixture of getSubClasses
, getSubObjectProperties
, getSubDataProperties
functions imported from the OWLAPI reasoner. The type of input entity will be
automatically determined. The bottom entity such as owl:Nothing
is ignored.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entity |
OWLObject
|
An |
required |
direct |
bool
|
Return parents ( |
False
|
Returns:
Type | Description |
---|---|
list[str]
|
A list of IRIs of the sub-entities of the given |
Source code in src/deeponto/onto/ontology.py
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 |
|
check_subsumption(sub_entity, super_entity)
Check if the first entity is subsumed by the second entity according to the reasoner.
Source code in src/deeponto/onto/ontology.py
725 726 727 728 729 730 731 732 |
|
check_disjoint(entity1, entity2)
Check if two entities are disjoint according to the reasoner.
Source code in src/deeponto/onto/ontology.py
734 735 736 737 738 739 740 741 |
|
check_common_descendants(entity1, entity2)
Check if two entities have a common decendant.
Entities can be OWL class or property expressions, and can be either atomic
or complex. It takes longer computation time for the complex ones. Complex
entities do not have an IRI. This method is optimised in the way that if
there exists an atomic entity A
, we compute descendants for A
and
compare them against the other entity which could be complex.
Source code in src/deeponto/onto/ontology.py
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 |
|
get_instances(owl_class, direct=False)
Return the list of named individuals that are instances of a given OWL class expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
owl_class |
OWLClassExpression
|
An ontology class of interest. |
required |
direct |
bool
|
Return direct instances ( |
False
|
Returns:
Type | Description |
---|---|
list[OWLIndividual]
|
A list of named individuals that are instances of |
Source code in src/deeponto/onto/ontology.py
772 773 774 775 776 777 778 779 780 781 782 783 |
|
check_instance(owl_instance, owl_class)
Check if a named individual is an instance of an OWL class.
Source code in src/deeponto/onto/ontology.py
785 786 787 788 |
|
check_common_instances(owl_class1, owl_class2)
Check if two OWL class expressions have a common instance.
Class expressions can be atomic or complex, and it takes longer computation time
for the complex ones. Complex classes do not have an IRI. This method is optimised
in the way that if there exists an atomic class A
, we compute instances for A
and
compare them against the other class which could be complex.
Difference with check_common_descendants
The inputs of this function are restricted to OWL class expressions. This is because
descendant
is related to hierarchy and both class and property expressions have a hierarchy,
but instance
is restricted to classes.
Source code in src/deeponto/onto/ontology.py
790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 |
|
check_assumed_disjoint(owl_class1, owl_class2)
Check if two OWL class expressions satisfy the Assumed Disjointness.
Citation
The definition of Assumed Disjointness comes from the paper: Language Model Analysis for Ontology Subsumption Inference.
Assumed Disjointness (Definition)
Two class expressions \(C\) and \(D\) are assumed to be disjoint if they meet the followings:
- By adding the disjointness axiom of them into the ontology, \(C\) and \(D\) are still satisfiable.
- \(C\) and \(D\) do not have a common descendant (otherwise \(C\) and \(D\) can be satisfiable but their common descendants become the bottom \(\bot\).)
Note that the special case where \(C\) and \(D\) are already disjoint is covered by the first check.
The paper also proposed a practical alternative to decide Assumed Disjointness.
See check_assumed_disjoint_alternative
.
Examples:
Suppose pre-load an ontology onto
from the disease ontology file doid.owl
.
>>> c1 = onto.get_owl_object("http://purl.obolibrary.org/obo/DOID_4058")
>>> c2 = onto.get_owl_object("http://purl.obolibrary.org/obo/DOID_0001816")
>>> onto.reasoner.check_assumed_disjoint(c1, c2)
[SUCCESSFULLY] Adding the axiom DisjointClasses(<http://purl.obolibrary.org/obo/DOID_0001816> <http://purl.obolibrary.org/obo/DOID_4058>) into the ontology.
[CHECK1 True] input classes are still satisfiable;
[SUCCESSFULLY] Removing the axiom from the ontology.
[CHECK2 False] input classes have NO common descendant.
[PASSED False] assumed disjointness check done.
False
Source code in src/deeponto/onto/ontology.py
820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 |
|
check_assumed_disjoint_alternative(owl_class1, owl_class2, verbose=False)
Check if two OWL class expressions satisfy the Assumed Disjointness.
Paper
The definition of Assumed Disjointness comes from the paper: Language Model Analysis for Ontology Subsumption Inference.
The practical alternative version of check_assumed_disjoint
with following conditions:
Assumed Disjointness (Practical Alternative)
Two class expressions \(C\) and \(D\) are assumed to be disjoint if they
- do not have a subsumption relationship between them,
- do not have a common descendant (in TBox),
- do not have a common instance (in ABox).
If all the conditions have been met, then we assume class1
and class2
as disjoint.
Examples:
Suppose pre-load an ontology onto
from the disease ontology file doid.owl
.
>>> c1 = onto.get_owl_object("http://purl.obolibrary.org/obo/DOID_4058")
>>> c2 = onto.get_owl_object("http://purl.obolibrary.org/obo/DOID_0001816")
>>> onto.reasoner.check_assumed_disjoint(c1, c2, verbose=True)
[CHECK1 True] input classes have NO subsumption relationship;
[CHECK2 False] input classes have NO common descendant;
Failed the `common descendant check`, skip the `common instance` check.
[PASSED False] assumed disjointness check done.
False
Source code in src/deeponto/onto/ontology.py
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 |
|
Created: April 18, 2023