Skip to content

Commit ba15bbf

Browse files
authored
Merge pull request #345 from dice-group/general_adjustments
tbox ,abox, triples methods and some general adjustments
2 parents 0481c3d + 97b4f70 commit ba15bbf

File tree

10 files changed

+556
-43
lines changed

10 files changed

+556
-43
lines changed

docs/usage/04_knowledge_base.md

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,43 @@ You can now:
253253
print(evaluated_concept.ic) # 3
254254
```
255255

256+
## Obtaining axioms
257+
258+
You can retrieve Tbox and Abox axioms by using `tbox` and `abox` methods respectively.
259+
Let us take them one at a time. The `tbox` method has 2 parameters, `entities` and `mode`.
260+
`entities` specifies the owl entity from which we want to obtain the Tbox axioms. It can be
261+
a single entity, a `Iterable` of entities, or `None`.
262+
263+
The allowed types of entities are:
264+
- OWLClass
265+
- OWLObjectProperty
266+
- OWLDataProperty
267+
268+
Only the Tbox axioms related to the given entit-y/ies will be returned. If no entities are
269+
passed, then it returns all the Tbox axioms.
270+
The second parameter `mode` _(str)_ sets the return format type. It can have the
271+
following values:
272+
1) `'native'` -> triples are represented as tuples of owlapy objects.
273+
2) `'iri'` -> triples are represented as tuples of IRIs as strings.
274+
3) `'axiom'` -> triples are represented as owlapy axioms.
275+
276+
For the `abox` method the idea is similar. Instead of the parameter `entities`, there is the parameter
277+
`individuals` which accepts an object of type OWLNamedIndividuals or Iterable[OWLNamedIndividuals].
278+
279+
If you want to obtain all the axioms (Tbox + Abox) of the knowledge base, you can use the method `triples`. It
280+
requires only the `mode` parameter.
281+
282+
> **NOTE**: The results of these methods are limited only to named and direct entities.
283+
> That means that especially the axioms that contain anonymous owl objects (objects that don't have an IRI)
284+
> will not be part of the result set. For example, if there is a Tbox T={ C ⊑ (A ⊓ B), C ⊑ D },
285+
> only the latter subsumption axiom will be returned.
286+
287+
256288
-----------------------------------------------------------------------------------------------------
257289

258-
See [KnowledgeBase API documentation](ontolearn.knowledge_base.KnowledgeBase)
259-
to check all the methods that this class has to offer. You will find methods to
260-
access the class/property hierarchy, convenient methods that use the reasoner indirectly and
290+
Since we cannot cover everything here in details, see [KnowledgeBase API documentation](ontolearn.knowledge_base.KnowledgeBase)
291+
to check all the methods that this class has to offer. You will find convenient methods to
292+
access the class/property hierarchy, methods that use the reasoner indirectly and
261293
a lot more.
262294

263295
Speaking of the reasoner, it is important that an ontology

main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def get_default_arguments(description=None):
1818
default='NCESData/family/embeddings/ConEx_entity_embeddings.csv',
1919
help="Path to knowledge base embeddings. Some models like NCES require this,"
2020
"e.g. 'some/path/kb_embeddings.csv'")
21+
parser.add_argument("--save", action="store_true", help="save the hypothesis?")
2122
# Common model arguments
2223
parser.add_argument("--path_learning_problem", type=str, default='examples/uncle_lp2.json',
2324
help="Path to a .json file that contains 2 properties 'positive_examples' and "

ontolearn/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,3 @@
1616
# from .metrics import *
1717
# from .search import *
1818
__all__ = ['knowledge_base', 'abstracts', 'base_concept_learner', 'metrics', 'search']
19-
20-
from .learners import Drill

ontolearn/base/fast_instance_checker.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
from functools import singledispatchmethod, reduce
77
from itertools import repeat, chain
88
from types import MappingProxyType, FunctionType
9-
from typing import DefaultDict, Iterable, Dict, Mapping, Set, Type, TypeVar, Optional, FrozenSet
9+
from typing import DefaultDict, Iterable, Dict, Mapping, Set, Type, TypeVar, Optional, FrozenSet, cast
1010

11+
from ontolearn.base import OWLReasoner_Owlready2
1112
from ontolearn.base.ext import OWLReasonerEx
1213
from owlapy.model import OWLDataRange, OWLObjectOneOf, OWLOntology, OWLNamedIndividual, OWLClass, \
1314
OWLObjectProperty, OWLDataProperty, OWLObjectUnionOf, OWLObjectIntersectionOf, OWLObjectSomeValuesFrom, \
@@ -187,6 +188,12 @@ def disjoint_data_properties(self, dp: OWLDataProperty) -> Iterable[OWLDataPrope
187188
def sub_data_properties(self, dp: OWLDataProperty, direct: bool = False) -> Iterable[OWLDataProperty]:
188189
yield from self._base_reasoner.sub_data_properties(dp=dp, direct=direct)
189190

191+
def super_data_properties(self, dp: OWLDataProperty, direct: bool = False) -> Iterable[OWLDataProperty]:
192+
yield from self._base_reasoner.super_data_properties(dp=dp, direct=direct)
193+
194+
def super_object_properties(self, op: OWLObjectProperty, direct: bool = False) -> Iterable[OWLDataProperty]:
195+
yield from self._base_reasoner.super_object_properties(op=op, direct=direct)
196+
190197
def sub_object_properties(self, op: OWLObjectPropertyExpression, direct: bool = False) \
191198
-> Iterable[OWLObjectPropertyExpression]:
192199
yield from self._base_reasoner.sub_object_properties(op=op, direct=direct)

0 commit comments

Comments
 (0)