:py:mod:`ontolearn.tentris` =========================== .. py:module:: ontolearn.tentris .. autoapi-nested-parse:: Tentris representations. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: ontolearn.tentris.EncodedPosNegLPStandardTentris ontolearn.tentris.TentrisOntology ontolearn.tentris.TentrisReasoner ontolearn.tentris.EvaluatedConceptTentris ontolearn.tentris.TentrisKnowledgeBase Attributes ~~~~~~~~~~ .. autoapisummary:: ontolearn.tentris.logger .. py:data:: logger .. py:class:: EncodedPosNegLPStandardTentris(id) Bases: :py:obj:`ontolearn.abstracts.EncodedPosNegLPStandardKind` Encoded Abstract learning problem following pos-neg lp standard. .. py:attribute:: __slots__ :value: 'id' .. py:method:: __repr__() Return repr(self). .. py:class:: TentrisOntology(path: str, endpoint_url: str, timeout: float) Bases: :py:obj:`owlapy.owl_ontology.OWLOntology` Represents an OWL 2 Ontology in the OWL 2 specification. An OWLOntology consists of a possibly empty set of OWLAxioms and a possibly empty set of OWLAnnotations. An ontology can have an ontology IRI which can be used to identify the ontology. If it has an ontology IRI then it may also have an ontology version IRI. Since OWL 2, an ontology need not have an ontology IRI. (See the OWL 2 Structural Specification). An ontology cannot be modified directly. Changes must be applied via its OWLOntologyManager. .. py:attribute:: __slots__ :value: ('_path', '_endpoint_url', '_backing_mgr', '_backing_onto', '_endpoint_timeout') .. py:method:: classes_in_signature() -> Iterable[owlapy.class_expression.OWLClass] Gets the classes in the signature of this object. :returns: Classes in the signature of this object. .. py:method:: data_properties_in_signature() -> Iterable[owlapy.owl_property.OWLDataProperty] Get the data properties that are in the signature of this object. :returns: Data properties that are in the signature of this object. .. py:method:: object_properties_in_signature() -> Iterable[owlapy.owl_property.OWLObjectProperty] A convenience method that obtains the object properties that are in the signature of this object. :returns: Object properties that are in the signature of this object. .. py:method:: individuals_in_signature() -> Iterable[owlapy.owl_individual.OWLNamedIndividual] A convenience method that obtains the individuals that are in the signature of this object. :returns: Individuals that are in the signature of this object. .. py:method:: data_property_range_axioms(property: owlapy.owl_property.OWLDataProperty) -> Iterable[owlapy.owl_axiom.OWLDataPropertyRangeAxiom] :abstractmethod: Gets the OWLDataPropertyRangeAxiom objects where the property is equal to the specified property. :param property: The property which is equal to the property of the retrieved axioms. :returns: The axioms matching the search. .. py:method:: data_property_domain_axioms(property: owlapy.owl_property.OWLDataProperty) -> Iterable[owlapy.owl_axiom.OWLDataPropertyDomainAxiom] Gets the OWLDataPropertyDomainAxiom objects where the property is equal to the specified property. :param property: The property which is equal to the property of the retrieved axioms. :returns: The axioms matching the search. .. py:method:: object_property_domain_axioms(property: owlapy.owl_property.OWLObjectProperty) -> Iterable[owlapy.owl_axiom.OWLObjectPropertyDomainAxiom] Gets the OWLObjectPropertyDomainAxiom objects where the property is equal to the specified property. :param property: The property which is equal to the property of the retrieved axioms. :returns: The axioms matching the search. .. py:method:: object_property_range_axioms(property: owlapy.owl_property.OWLObjectProperty) -> Iterable[owlapy.owl_axiom.OWLObjectPropertyRangeAxiom] Gets the OWLObjectPropertyRangeAxiom objects where the property is equal to the specified property. :param property: The property which is equal to the property of the retrieved axioms. :returns: The axioms matching the search. .. py:method:: get_owl_ontology_manager() -> owlapy.owl_ontology._M :abstractmethod: Gets the manager that manages this ontology. .. py:method:: get_ontology_id() -> owlapy.owl_ontology.OWLOntologyID :abstractmethod: Gets the OWLOntologyID belonging to this object. :returns: The OWLOntologyID. .. py:method:: __eq__(other) Return self==value. .. py:method:: __hash__() Return hash(self). .. py:method:: __repr__() Return repr(self). .. py:class:: TentrisReasoner(ontology: TentrisOntology) Bases: :py:obj:`ontolearn.base.ext.OWLReasonerEx` Extra convenience methods for OWL Reasoners (Not part of OWLAPI) .. py:attribute:: __slots__ :value: ('_ontology', '_backing_reasoner') .. py:method:: data_property_domains(pe: owlapy.owl_property.OWLDataProperty, direct: bool = False) -> Iterable[owlapy.class_expression.OWLClass] :abstractmethod: Gets the class expressions that are the direct or indirect domains of this property with respect to the imports closure of the root ontology. :param pe: The property expression whose domains are to be retrieved. :param direct: Specifies if the direct domains should be retrieved (True), or if all domains should be retrieved (False). :returns: Let N = equivalent_classes(DataSomeValuesFrom(pe rdfs:Literal)). If direct is True: then if N is not empty then the return value is N, else the return value is the result of super_classes(DataSomeValuesFrom(pe rdfs:Literal), true). If direct is False: then the result of super_classes(DataSomeValuesFrom(pe rdfs:Literal), false) together with N if N is non-empty. (Note, rdfs:Literal is the top datatype). .. py:method:: object_property_domains(pe: owlapy.owl_property.OWLObjectProperty, direct: bool = False) -> Iterable[owlapy.class_expression.OWLClass] Gets the class expressions that are the direct or indirect domains of this property with respect to the imports closure of the root ontology. :param pe: The property expression whose domains are to be retrieved. :param direct: Specifies if the direct domains should be retrieved (True), or if all domains should be retrieved (False). :returns: Let N = equivalent_classes(ObjectSomeValuesFrom(pe owl:Thing)). If direct is True: then if N is not empty then the return value is N, else the return value is the result of super_classes(ObjectSomeValuesFrom(pe owl:Thing), true). If direct is False: then the result of super_classes(ObjectSomeValuesFrom(pe owl:Thing), false) together with N if N is non-empty. .. py:method:: object_property_ranges(pe: owlapy.owl_property.OWLObjectProperty, direct: bool = False) -> Iterable[owlapy.class_expression.OWLClass] Gets the class expressions that are the direct or indirect ranges of this property with respect to the imports closure of the root ontology. :param pe: The property expression whose ranges are to be retrieved. :param direct: Specifies if the direct ranges should be retrieved (True), or if all ranges should be retrieved (False). :returns: Let N = equivalent_classes(ObjectSomeValuesFrom(ObjectInverseOf(pe) owl:Thing)). If direct is True: then if N is not empty then the return value is N, else the return value is the result of super_classes(ObjectSomeValuesFrom(ObjectInverseOf(pe) owl:Thing), true). If direct is False: then the result of super_classes(ObjectSomeValuesFrom(ObjectInverseOf(pe) owl:Thing), false) together with N if N is non-empty. .. py:method:: equivalent_classes(ce: owlapy.class_expression.OWLClassExpression, only_named: bool = True) -> Iterable[owlapy.class_expression.OWLClassExpression] :abstractmethod: Gets the class expressions that are equivalent to the specified class expression with respect to the set of reasoner axioms. :param ce: The class expression whose equivalent classes are to be retrieved. :param 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 not a class name (i.e. it is an anonymous class expression) and there are no such classes C then there will be no result. If ce is unsatisfiable with respect to the set of reasoner axioms then owl:Nothing, i.e. the bottom node, will be returned. .. py:method:: data_property_values(ind: owlapy.owl_individual.OWLNamedIndividual, pe: owlapy.owl_property.OWLDataProperty) -> Iterable[owlapy.owl_literal.OWLLiteral] :abstractmethod: Gets the data property values for the specified individual and data property expression. :param ind: The individual that is the subject of the data property values. :param pe: The data property expression whose values are to be retrieved for the specified individual. :param 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: A set of OWLLiterals containing literals such that for each literal l in the set, the set of reasoner axioms entails DataPropertyAssertion(pe ind l). .. py:method:: object_property_values(ind: owlapy.owl_individual.OWLNamedIndividual, pe: owlapy.owl_property.OWLObjectPropertyExpression) -> Iterable[owlapy.owl_individual.OWLNamedIndividual] :abstractmethod: Gets the object property values for the specified individual and object property expression. :param ind: The individual that is the subject of the object property values. :param pe: The object property expression whose values are to be retrieved for the specified individual. :param 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 ObjectPropertyAssertion(pe ind j). .. py:method:: flush() -> None :abstractmethod: Flushes any changes stored in the buffer, which causes the reasoner to take into consideration the changes the current root ontology specified by the changes. .. py:method:: instances(ce: owlapy.class_expression.OWLClassExpression, direct: bool = False) -> Iterable[owlapy.owl_individual.OWLNamedIndividual] Gets the individuals which are instances of the specified class expression. :param ce: The class expression whose instances are to be retrieved. :param direct: Specifies if the direct instances should be retrieved (True), or if all instances should be retrieved (False). :returns: If direct is True, each named individual j where the set of reasoner axioms entails DirectClassAssertion(ce, j). If direct is False, each named individual j where the set of reasoner axioms entails ClassAssertion(ce, j). If ce is unsatisfiable with respect to the set of reasoner axioms then nothing returned. .. py:method:: sub_classes(ce: owlapy.class_expression.OWLClassExpression, direct: bool = False, only_named: bool = True) -> Iterable[owlapy.class_expression.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. :param ce: The class expression whose strict (direct) subclasses are to be retrieved. :param direct: Specifies if the direct subclasses should be retrieved (True) or if the all subclasses (descendant) classes should be retrieved (False). :param 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, each class C where reasoner axioms entails StrictSubClassOf(C, ce). If ce is equivalent to owl:Nothing then nothing will be returned. .. py:method:: sub_data_properties(dp: owlapy.owl_property.OWLDataProperty, direct: bool = False) -> Iterable[owlapy.owl_property.OWLDataProperty] Gets the set of named data properties that are the strict (potentially direct) subproperties of the specified data property expression with respect to the imports closure of the root ontology. :param dp: The data property whose strict (direct) subproperties are to be retrieved. :param direct: Specifies if the direct subproperties should be retrieved (True) or if the all subproperties (descendants) should be retrieved (False). :returns: If direct is True, each property P where the set of reasoner axioms entails DirectSubDataPropertyOf(P, pe). If direct is False, each property P where the set of reasoner axioms entails StrictSubDataPropertyOf(P, pe). If pe is equivalent to owl:bottomDataProperty then nothing will be returned. .. py:method:: sub_object_properties(op: owlapy.owl_property.OWLObjectPropertyExpression, direct: bool = False) -> Iterable[owlapy.owl_property.OWLObjectPropertyExpression] Gets the stream of simplified object property expressions that are the strict (potentially direct) subproperties of the specified object property expression with respect to the imports closure of the root ontology. :param op: The object property expression whose strict (direct) subproperties are to be retrieved. :param direct: Specifies if the direct subproperties should be retrieved (True) or if the all subproperties (descendants) should be retrieved (False). :returns: If direct is True, simplified object property expressions, such that for each simplified object property expression, P, the set of reasoner axioms entails DirectSubObjectPropertyOf(P, pe). If direct is False, simplified object property expressions, such that for each simplified object property expression, P, the set of reasoner axioms entails StrictSubObjectPropertyOf(P, pe). If pe is equivalent to owl:bottomObjectProperty then nothing will be returned. .. py:method:: types(ind: owlapy.owl_individual.OWLNamedIndividual, direct: bool = False) -> Iterable[owlapy.class_expression.OWLClass] :abstractmethod: Gets the named classes which are (potentially direct) types of the specified named individual. :param ind: The individual whose types are to be retrieved. :param direct: Specifies if the direct types should be retrieved (True), or if all types should be retrieved (False). :returns: If direct is True, each named class C where the set of reasoner axioms entails DirectClassAssertion(C, ind). If direct is False, each named class C where the set of reasoner axioms entails ClassAssertion(C, ind). .. py:method:: get_root_ontology() -> TentrisOntology Gets the "root" ontology that is loaded into this reasoner. The reasoner takes into account the axioms in this ontology and its import's closure. .. py:method:: super_classes(ce: owlapy.class_expression.OWLClassExpression, direct: bool = False, only_named: bool = True) -> Iterable[owlapy.class_expression.OWLClassExpression] :abstractmethod: 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. :param ce: The class expression whose strict (direct) super classes are to be retrieved. :param direct: Specifies if the direct super classes should be retrieved (True) or if the all super classes (ancestors) classes should be retrieved (False). :param 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). If direct is False, each class C where set of reasoner axioms entails StrictSubClassOf(ce, C). If ce is equivalent to owl:Thing then nothing will be returned. .. py:class:: EvaluatedConceptTentris Bases: :py:obj:`ontolearn.search.EvaluatedConcept` Explicitly declare the attributes that should be returned by the evaluate_concept method of a KnowledgeBase. This way, Python uses a more efficient way to store the instance attributes, which can significantly reduce the memory usage. .. py:property:: inds .. py:attribute:: __slots__ :value: () .. py:class:: TentrisKnowledgeBase(path: str, *, length_metric_factory: Optional[ontolearn.utils.Factory[[], ontolearn.base.owl.utils.OWLClassExpressionLengthMetric]] = None, length_metric: Optional[ontolearn.base.owl.utils.OWLClassExpressionLengthMetric] = None, individuals_cache_size=128) Bases: :py:obj:`ontolearn.knowledge_base.KnowledgeBase` Representation of an OWL knowledge base in Ontolearn. :param path: Path to an ontology file that is to be loaded. :param ontologymanager_factory: Factory that creates an ontology manager to be used to load the file. :param ontology: OWL ontology object. :param reasoner_factory: Factory that creates a reasoner to reason about the ontology. :param reasoner: reasoner Over the ontology. :param length_metric_factory: See :attr:`length_metric`. :param length_metric: Length metric that is used in calculation of class expression lengths. :param individuals_cache_size: How many individuals of class expressions to cache. :param backend_store: Whether to sync the world to backend store. reasoner of this object, if you enter a reasoner using :arg:`reasoner_factory` or :arg:`reasoner` argument it will override this setting. :param include_implicit_individuals: Whether to identify and consider instances which are not set as OWL Named Individuals (does not contain this type) as individuals. .. attribute:: generator Instance of concept generator. :type: ConceptGenerator .. attribute:: path Path of the ontology file. :type: str .. attribute:: use_individuals_cache Whether to use individuals cache to store individuals for method efficiency. :type: bool .. py:attribute:: __slots__ :value: ('endpoint_url', 'endpoint_timeout', 'async_client', 'tasks', '_total_req', '_current_req') .. py:attribute:: endpoint_url :type: str .. py:attribute:: endpoint_timeout :type: float .. py:method:: encode_learning_problem(lp: ontolearn.abstracts.AbstractLearningProblem) :abstractmethod: @TODO: A learning problem (DL concept learning problem) should not be a part of a knowledge base Provides the encoded learning problem (lp), i.e. the class containing the set of OWLNamedIndividuals as follows: kb_pos --> the positive examples set, kb_neg --> the negative examples set, kb_all --> all lp individuals / all individuals set, kb_diff --> kb_all - (kb_pos + kb_neg). .. note:: Simple access of the learning problem individuals divided in respective sets. You will need the encoded learning problem to use the method evaluate_concept of this class. :param lp: The learning problem. :type lp: PosNegLPStandard :returns: The encoded learning problem. :rtype: EncodedPosNegLPStandard .. py:method:: evaluate_concept(concept: owlapy.class_expression.OWLClassExpression, quality_func: ontolearn.abstracts.AbstractScorer, encoded_learning_problem: EncodedPosNegLPStandardTentris) -> ontolearn.search.EvaluatedConcept Evaluates a concept by using the encoded learning problem examples, in terms of Accuracy or F1-score. @ TODO: A knowledge base is a data structure and the context of "evaluating" a concept seems to be unrelated .. note:: This method is useful to tell the quality (e.q) of a generated concept by the concept learners, to get the set of individuals (e.inds) that are classified by this concept and the amount of them (e.ic). :param concept: The concept to be evaluated. :param quality_func: Quality measurement in terms of Accuracy or F1-score. :param encoded_learning_problem: The encoded learning problem. :returns: The evaluated concept. .. py:method:: evaluate_concept_async(concept: owlapy.class_expression.OWLClassExpression, quality_func: ontolearn.abstracts.AbstractScorer, encoded_learning_problem: EncodedPosNegLPStandardTentris) -> ontolearn.search.EvaluatedConcept :async: