From e48c25df19bb72aea5f78137f6451cec05dfbac9 Mon Sep 17 00:00:00 2001 From: Alkid Date: Mon, 9 Sep 2024 15:06:16 +0200 Subject: [PATCH] removed optional arguments from abstract methods of OWLReasoner --- owlapy/abstracts/abstract_owl_reasoner.py | 37 +++++++++-------------- owlapy/owl_reasoner.py | 14 +++------ 2 files changed, 20 insertions(+), 31 deletions(-) diff --git a/owlapy/abstracts/abstract_owl_reasoner.py b/owlapy/abstracts/abstract_owl_reasoner.py index 8b7bcd0..c70ca21 100644 --- a/owlapy/abstracts/abstract_owl_reasoner.py +++ b/owlapy/abstracts/abstract_owl_reasoner.py @@ -1,7 +1,7 @@ """OWL Reasoner""" from abc import ABCMeta, abstractmethod from typing import Iterable - +import logging from owlapy.class_expression import OWLClassExpression from owlapy.class_expression import OWLClass @@ -12,6 +12,8 @@ from owlapy.owl_individual import OWLNamedIndividual from owlapy.owl_literal import OWLLiteral +logger = logging.getLogger(__name__) + class OWLReasoner(metaclass=ABCMeta): """An OWLReasoner reasons over a set of axioms (the set of reasoner axioms) that is based on the imports closure of @@ -79,13 +81,12 @@ def object_property_ranges(self, pe: OWLObjectProperty, direct: bool = False) -> pass @abstractmethod - def equivalent_classes(self, ce: OWLClassExpression, only_named: bool = True) -> Iterable[OWLClassExpression]: + def equivalent_classes(self, ce: OWLClassExpression) -> Iterable[OWLClassExpression]: """Gets the class expressions that are equivalent to the specified class expression with respect to the set of reasoner axioms. Args: ce: The class expression whose equivalent classes are to be retrieved. - only_named: Whether to only retrieve named equivalent classes or also complex class expressions. Returns: All class expressions C where the root ontology imports closure entails EquivalentClasses(ce C). If ce is @@ -96,13 +97,12 @@ def equivalent_classes(self, ce: OWLClassExpression, only_named: bool = True) -> pass @abstractmethod - def disjoint_classes(self, ce: OWLClassExpression, only_named: bool = True) -> Iterable[OWLClassExpression]: + def disjoint_classes(self, ce: OWLClassExpression) -> Iterable[OWLClassExpression]: """Gets the class expressions that are disjoint with specified class expression with respect to the set of reasoner axioms. Args: ce: The class expression whose disjoint classes are to be retrieved. - only_named: Whether to only retrieve named disjoint classes or also complex class expressions. Returns: All class expressions D where the set of reasoner axioms entails EquivalentClasses(D ObjectComplementOf(ce)) @@ -167,15 +167,13 @@ def equivalent_data_properties(self, dp: OWLDataProperty) -> Iterable[OWLDataPro pass @abstractmethod - def data_property_values(self, e: OWLEntity, pe: OWLDataProperty, direct: bool = True) \ + def data_property_values(self, e: OWLEntity, pe: OWLDataProperty) \ -> Iterable['OWLLiteral']: """Gets the data property values for the specified entity and data property expression. Args: e: The owl entity (usually an individual) that is the subject of the data property values. pe: The data property expression whose values are to be retrieved for the specified entity. - direct: Specifies if the direct values should be retrieved (True), or if all values should be retrieved - (False), so that sub properties are taken into account. Note: Can be used to get values, for example, of 'label' property of owl entities such as classes and properties too (not only individuals). @@ -187,15 +185,13 @@ def data_property_values(self, e: OWLEntity, pe: OWLDataProperty, direct: bool = pass @abstractmethod - def object_property_values(self, ind: OWLNamedIndividual, pe: OWLObjectPropertyExpression, direct: bool = True) \ + def object_property_values(self, ind: OWLNamedIndividual, pe: OWLObjectPropertyExpression) \ -> Iterable[OWLNamedIndividual]: """Gets the object property values for the specified individual and object property expression. Args: ind: The individual that is the subject of the object property values. pe: The object property expression whose values are to be retrieved for the specified individual. - direct: Specifies if the direct values should be retrieved (True), or if all values should be retrieved - (False), so that sub properties are taken into account. Returns: The named individuals such that for each individual j, the set of reasoner axioms entails @@ -221,7 +217,7 @@ def instances(self, ce: OWLClassExpression, direct: bool = False) -> Iterable[OW pass @abstractmethod - def sub_classes(self, ce: OWLClassExpression, direct: bool = False, only_named: bool = True) \ + def sub_classes(self, ce: OWLClassExpression, direct: bool = False) \ -> Iterable[OWLClassExpression]: """Gets the set of named classes that are the strict (potentially direct) subclasses of the specified class expression with respect to the reasoner axioms. @@ -230,7 +226,6 @@ def sub_classes(self, ce: OWLClassExpression, direct: bool = False, only_named: ce: The class expression whose strict (direct) subclasses are to be retrieved. direct: Specifies if the direct subclasses should be retrieved (True) or if the all subclasses (descendant) classes should be retrieved (False). - only_named: Whether to only retrieve named sub-classes or also complex class expressions. Returns: If direct is True, each class C where reasoner axioms entails DirectSubClassOf(C, ce). If direct is False, @@ -363,7 +358,7 @@ def get_root_ontology(self) -> OWLOntology: pass @abstractmethod - def super_classes(self, ce: OWLClassExpression, direct: bool = False, only_named: bool = True) \ + def super_classes(self, ce: OWLClassExpression, direct: bool = False) \ -> Iterable[OWLClassExpression]: """Gets the stream of named classes that are the strict (potentially direct) super classes of the specified class expression with respect to the imports closure of the root ontology. @@ -372,7 +367,6 @@ class expression with respect to the imports closure of the root ontology. ce: The class expression whose strict (direct) super classes are to be retrieved. direct: Specifies if the direct super classes should be retrieved (True) or if the all super classes (ancestors) classes should be retrieved (False). - only_named: Whether to only retrieve named super classes or also complex class expressions. Returns: If direct is True, each class C where the set of reasoner axioms entails DirectSubClassOf(ce, C). @@ -380,6 +374,8 @@ class expression with respect to the imports closure of the root ontology. If ce is equivalent to owl:Thing then nothing will be returned. """ pass + + class OWLReasonerEx(OWLReasoner, metaclass=ABCMeta): """Extra convenience methods for OWL Reasoners""" @@ -399,16 +395,13 @@ def data_property_ranges(self, pe: OWLDataProperty, direct: bool = False) -> Ite yield ax.get_range() if not direct: logger.warning("indirect not implemented") - # TODO: # default - def all_data_property_values(self, pe: OWLDataProperty, direct: bool = True) -> Iterable[OWLLiteral]: + def all_data_property_values(self, pe: OWLDataProperty) -> Iterable[OWLLiteral]: """Gets all values for the given data property expression that appear in the knowledge base. Args: pe: The data property expression whose values are to be retrieved - direct: Specifies if only the direct values of the data property pe should be retrieved (True), or if - the values of sub properties of pe should be taken into account (False). Returns: A set of OWLLiterals containing literals such that for each literal l in the set, the set of reasoner @@ -416,7 +409,7 @@ def all_data_property_values(self, pe: OWLDataProperty, direct: bool = True) -> """ onto = self.get_root_ontology() for ind in onto.individuals_in_signature(): - for lit in self.data_property_values(ind, pe, direct): + for lit in self.data_property_values(ind, pe): yield lit # default @@ -456,7 +449,7 @@ def ind_object_properties(self, ind: OWLNamedIndividual, direct: bool = True) -> onto = self.get_root_ontology() for op in onto.object_properties_in_signature(): try: - next(iter(self.object_property_values(ind, op, direct))) + next(iter(self.object_property_values(ind, op))) yield op except StopIteration: - pass \ No newline at end of file + pass diff --git a/owlapy/owl_reasoner.py b/owlapy/owl_reasoner.py index 9c2b708..be190f7 100644 --- a/owlapy/owl_reasoner.py +++ b/owlapy/owl_reasoner.py @@ -33,11 +33,6 @@ _P = TypeVar('_P', bound=OWLPropertyExpression) -# TODO:CD:The name of the classes defined with metaclass=ABCMeta should reflect that -# TODO:CD: An instance cannot be created from those classes. -# TODO:CD: We should move those Abstract Base Classes into a respective package, e.g. -# TODO:CD: owlapy/abstract_owl_reasoner/abstract_owl_reasoner.py should contain OWLReasoner and OWLReasonerEx - class OntologyReasoner(OWLReasonerEx): __slots__ = '_ontology', '_world' @@ -1149,7 +1144,7 @@ def _retrieve_triples(self, pe: OWLPropertyExpression) -> Iterable: yield from relations -class SyncReasoner: +class SyncReasoner(OWLReasonerEx): def __init__(self, ontology: Union[SyncOntology, str], reasoner="HermiT"): """ @@ -1633,9 +1628,10 @@ def infer_axioms_and_save(self, output_path: str = None, output_format: str = No def generate_and_save_inferred_class_assertion_axioms(self, output="temp.ttl", output_format: str = None): """ - Generates inferred class assertion axioms for the ontology managed by this instance's reasoner and saves them to a file. - This function uses the OWL API to generate inferred class assertion axioms based on the ontology and reasoner - associated with this instance. The inferred axioms are saved to the specified output file in the desired format. + Generates inferred class assertion axioms for the ontology managed by this instance's reasoner and saves them + to a file. This function uses the OWL API to generate inferred class assertion axioms based on the ontology + and reasoner associated with this instance. The inferred axioms are saved to the specified output file in + the desired format. Parameters: ----------- output : str, optional