ontolearn.knowledge_base ======================== .. py:module:: ontolearn.knowledge_base .. autoapi-nested-parse:: Knowledge Base. Attributes ---------- .. autoapisummary:: ontolearn.knowledge_base.logger Classes ------- .. autoapisummary:: ontolearn.knowledge_base.KnowledgeBase Module Contents --------------- .. py:data:: logger .. py:class:: KnowledgeBase(*, path: Optional[str] = None, reasoner_factory: Optional[Callable[[owlapy.abstracts.AbstractOWLOntology], owlapy.abstracts.AbstractOWLReasoner]] = None, ontology: Optional[owlapy.abstracts.AbstractOWLOntology] = None, reasoner: Optional[owlapy.abstracts.AbstractOWLReasoner] = None, class_hierarchy: Optional[owlapy.owl_hierarchy.ClassHierarchy] = None, load_class_hierarchy: bool = True, object_property_hierarchy: Optional[owlapy.owl_hierarchy.ObjectPropertyHierarchy] = None, data_property_hierarchy: Optional[owlapy.owl_hierarchy.DatatypePropertyHierarchy] = None, include_implicit_individuals=False) Bases: :py:obj:`ontolearn.abstracts.AbstractKnowledgeBase` Representation of an OWL knowledge base in Ontolearn. :param path: Path to an ontology file that is to be loaded. :param ontology: OWL ontology object. :param reasoner_factory: Factory that creates a reasoner to reason about the ontology. :param reasoner: reasoner Over the ontology. 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 .. py:attribute:: ind_cache :type: owlapy.utils.LRUCache[owlapy.class_expression.OWLClassExpression, FrozenSet[owlapy.owl_individual.OWLNamedIndividual]] .. py:attribute:: path :type: str .. py:attribute:: generator :type: ontolearn.concept_generator.ConceptGenerator .. py:attribute:: op_domains :type: Dict[owlapy.owl_property.OWLObjectProperty, owlapy.class_expression.OWLClassExpression] .. py:attribute:: op_ranges :type: Dict[owlapy.owl_property.OWLObjectProperty, owlapy.class_expression.OWLClassExpression] .. py:attribute:: dp_domains :type: Dict[owlapy.owl_property.OWLDataProperty, owlapy.class_expression.OWLClassExpression] .. py:attribute:: dp_ranges :type: Dict[owlapy.owl_property.OWLDataProperty, FrozenSet[owlapy.owl_data_ranges.OWLDataRange]] .. py:method:: individuals(concept: Optional[owlapy.class_expression.OWLClassExpression] = None, implicit_individuals: bool = True) -> Iterable[owlapy.owl_individual.OWLNamedIndividual] Given an OWL class expression, retrieve all individuals belonging to it. :param concept: Class expression of which to list individuals. :param implicit_individuals: No purpose for now (tbd) :returns: Individuals belonging to the given class. .. py:method:: abox(individual: Union[owlapy.owl_individual.OWLNamedIndividual, Iterable[owlapy.owl_individual.OWLNamedIndividual]] = None, mode='native') Get all the abox axioms for a given individual. If no individual is given, get all abox axioms :param individual: Individual/s to get the abox axioms from. :type individual: OWLNamedIndividual :param mode: The return format. 1) 'native' -> returns triples as tuples of owlapy objects, 2) 'iri' -> returns triples as tuples of IRIs as string, 3) 'axiom' -> triples are represented by owlapy axioms. :type mode: str Returns: Iterable of tuples or owlapy axiom, depending on the mode. .. py:method:: tbox(entities: Union[Iterable[owlapy.class_expression.OWLClass], Iterable[owlapy.owl_property.OWLDataProperty], Iterable[owlapy.owl_property.OWLObjectProperty], owlapy.class_expression.OWLClass, owlapy.owl_property.OWLDataProperty, owlapy.owl_property.OWLObjectProperty, None] = None, mode='native') Get all the tbox axioms for the given concept-s|propert-y/ies. If no concept-s|propert-y/ies are given, get all tbox axioms. :param entities: Entities to obtain tbox axioms from. This can be a single OWLClass/OWLDataProperty/OWLObjectProperty object, a list of those objects or None. If you enter a list that combines classes and properties (which we don't recommend doing), only axioms for one type will be returned, whichever comes first (classes or props). :param mode: The return format. 1) 'native' -> returns triples as tuples of owlapy objects, 2) 'iri' -> returns triples as tuples of IRIs as string, 3) 'axiom' -> triples are represented by owlapy axioms. :type mode: str Returns: Iterable of tuples or owlapy axiom, depending on the mode. .. py:method:: triples(mode='native') Get all tbox and abox axioms/triples. :param mode: The return format. 1) 'native' -> returns triples as tuples of owlapy objects, 2) 'iri' -> returns triples as tuples of IRIs as string, 3) 'axiom' -> triples are represented by owlapy axioms. :type mode: str Returns: Iterable of tuples or owlapy axiom, depending on the mode. .. py:method:: ignore_and_copy(ignored_classes: Optional[Iterable[owlapy.class_expression.OWLClass]] = None, ignored_object_properties: Optional[Iterable[owlapy.owl_property.OWLObjectProperty]] = None, ignored_data_properties: Optional[Iterable[owlapy.owl_property.OWLDataProperty]] = None) -> KnowledgeBase Makes a copy of the knowledge base while ignoring specified concepts and properties. :param ignored_classes: Classes to ignore. :param ignored_object_properties: Object properties to ignore. :param ignored_data_properties: Data properties to ignore. :returns: A new KnowledgeBase with the hierarchies restricted as requested. .. py:method:: clean() Clean all stored values (states and caches) if there is any. .. note:: 1. If you have more than one learning problem that you want to fit to the same model (i.e. to learn the concept using the same concept learner model) use this method to make sure that you have cleared every previous stored value. 2. If you store another KnowledgeBase instance using the same variable name as before, it is recommended to use this method before the initialization to avoid data mismatch. .. py:method:: individuals_count(concept: Optional[owlapy.class_expression.OWLClassExpression] = None) -> int Returns the number of all individuals belonging to the concept in the ontology. :param concept: Class expression of the individuals to count. :returns: Number of the individuals belonging to the given class. .. py:method:: individuals_set(arg: Union[Iterable[owlapy.owl_individual.OWLNamedIndividual], owlapy.owl_individual.OWLNamedIndividual, owlapy.class_expression.OWLClassExpression]) -> FrozenSet Retrieve the individuals specified in the arg as a frozenset. If `arg` is an OWLClassExpression then this method behaves as the method "individuals" but will return the final result as a frozenset. :param arg: more than one individual/ single individual/ class expression of which to list individuals. :returns: Frozenset of the individuals depending on the arg type. .. py:method:: most_general_object_properties(*, domain: owlapy.class_expression.OWLClassExpression, inverse: bool = False) -> Iterable[owlapy.owl_property.OWLObjectProperty] Find the most general object property. :param domain: Domain for which to search properties. :param inverse: Inverse order? .. py:method:: data_properties_for_domain(domain: owlapy.class_expression.OWLClassExpression, data_properties: Iterable[owlapy.owl_property.OWLDataProperty]) -> Iterable[owlapy.owl_property.OWLDataProperty] .. py:method:: least_general_named_concepts() -> Generator[owlapy.class_expression.OWLClass, None, None] Get leaf classes. @TODO: Docstring needed Returns: .. py:method:: most_general_classes() -> Generator[owlapy.class_expression.OWLClass, None, None] Get most general named concepts classes. @TODO: Docstring needed Returns: .. py:method:: are_owl_concept_disjoint(c: owlapy.class_expression.OWLClass, cc: owlapy.class_expression.OWLClass) -> bool .. py:method:: get_direct_sub_concepts(concept: owlapy.class_expression.OWLClass) -> Iterable[owlapy.class_expression.OWLClass] Direct sub-classes of atomic class. :param concept: Atomic concept. :returns: Direct sub classes of concept { x \| ( x subClassOf concept )}. .. py:method:: get_object_property_domains(prop: owlapy.owl_property.OWLObjectProperty) -> owlapy.class_expression.OWLClassExpression Get the domains of an object property. :param prop: Object property. :returns: Domains of the property. .. py:method:: get_object_property_ranges(prop: owlapy.owl_property.OWLObjectProperty) -> owlapy.class_expression.OWLClassExpression Get the ranges of an object property. :param prop: Object property. :returns: Ranges of the property. .. py:method:: get_data_property_domains(prop: owlapy.owl_property.OWLDataProperty) -> owlapy.class_expression.OWLClassExpression Get the domains of a data property. :param prop: Data property. :returns: Domains of the property. .. py:method:: get_data_property_ranges(prop: owlapy.owl_property.OWLDataProperty) -> FrozenSet[owlapy.owl_data_ranges.OWLDataRange] Get the ranges of a data property. :param prop: Data property. :returns: Ranges of the property. .. py:method:: most_general_data_properties(*, domain: owlapy.class_expression.OWLClassExpression) -> Iterable[owlapy.owl_property.OWLDataProperty] Find most general data properties that are applicable to a domain. :param domain: Domain for which to search properties. :returns: Most general data properties for the given domain. .. py:method:: most_general_boolean_data_properties(*, domain: owlapy.class_expression.OWLClassExpression) -> Iterable[owlapy.owl_property.OWLDataProperty] Find most general boolean data properties that are applicable to a domain. :param domain: Domain for which to search properties. :returns: Most general boolean data properties for the given domain. .. py:method:: most_general_numeric_data_properties(*, domain: owlapy.class_expression.OWLClassExpression) -> Iterable[owlapy.owl_property.OWLDataProperty] Find most general numeric data properties that are applicable to a domain. :param domain: Domain for which to search properties. :returns: Most general numeric data properties for the given domain. .. py:method:: most_general_time_data_properties(*, domain: owlapy.class_expression.OWLClassExpression) -> Iterable[owlapy.owl_property.OWLDataProperty] Find most general time data properties that are applicable to a domain. :param domain: Domain for which to search properties. :returns: Most general time data properties for the given domain. .. py:method:: most_general_existential_restrictions(*, domain: owlapy.class_expression.OWLClassExpression, filler: Optional[owlapy.class_expression.OWLClassExpression] = None) -> Iterable[owlapy.class_expression.OWLObjectSomeValuesFrom] Find most general existential restrictions that are applicable to a domain. :param domain: Domain for which to search properties. :param filler: Optional filler to put in the restriction (not normally used). :returns: Most general existential restrictions for the given domain. .. py:method:: most_general_universal_restrictions(*, domain: owlapy.class_expression.OWLClassExpression, filler: Optional[owlapy.class_expression.OWLClassExpression] = None) -> Iterable[owlapy.class_expression.OWLObjectAllValuesFrom] Find most general universal restrictions that are applicable to a domain. :param domain: Domain for which to search properties. :param filler: Optional filler to put in the restriction (not normally used). :returns: Most general universal restrictions for the given domain. .. py:method:: most_general_existential_restrictions_inverse(*, domain: owlapy.class_expression.OWLClassExpression, filler: Optional[owlapy.class_expression.OWLClassExpression] = None) -> Iterable[owlapy.class_expression.OWLObjectSomeValuesFrom] Find most general inverse existential restrictions that are applicable to a domain. :param domain: Domain for which to search properties. :param filler: Optional filler to put in the restriction (not normally used). :returns: Most general existential restrictions over inverse property. .. py:method:: most_general_universal_restrictions_inverse(*, domain: owlapy.class_expression.OWLClassExpression, filler: Optional[owlapy.class_expression.OWLClassExpression] = None) -> Iterable[owlapy.class_expression.OWLObjectAllValuesFrom] Find most general inverse universal restrictions that are applicable to a domain. :param domain: Domain for which to search properties. :param filler: Optional filler to put in the restriction (not normally used). :returns: Most general universal restrictions over inverse property. .. py:method:: get_direct_parents(concept: owlapy.class_expression.OWLClassExpression) -> Iterable[owlapy.class_expression.OWLClass] Direct parent concepts. :param concept: Concept to find super concepts of. :returns: Direct parent concepts. .. py:method:: get_all_direct_sub_concepts(concept: owlapy.class_expression.OWLClassExpression) -> Iterable[owlapy.class_expression.OWLClassExpression] All direct sub concepts of a concept. :param concept: Parent concept for which to get sub concepts. :returns: Direct sub concepts. .. py:method:: get_all_sub_concepts(concept: owlapy.class_expression.OWLClassExpression) -> Iterable[owlapy.class_expression.OWLClassExpression] All sub concepts of a concept. :param concept: Parent concept for which to get sub concepts. :returns: Sub concepts. .. py:method:: get_concepts() -> Iterable[owlapy.class_expression.OWLClass] Get all concepts of this concept generator. :returns: Concepts. .. py:property:: concepts :type: Iterable[owlapy.class_expression.OWLClass] Get all concepts of this concept generator. :returns: Concepts. .. py:property:: object_properties :type: Iterable[owlapy.owl_property.OWLObjectProperty] Get all object properties of this concept generator. :returns: Object properties. .. py:property:: data_properties :type: Iterable[owlapy.owl_property.OWLDataProperty] Get all data properties of this concept generator. :returns: Data properties for the given range. .. py:method:: get_object_properties() -> Iterable[owlapy.owl_property.OWLObjectProperty] Get all object properties of this concept generator. :returns: Object properties. .. py:method:: get_data_properties(ranges: Set[owlapy.owl_datatype.OWLDatatype] = None) -> Iterable[owlapy.owl_property.OWLDataProperty] Get all data properties of this concept generator for the given ranges. :param ranges: Ranges for which to extract the data properties. :returns: Data properties for the given range. .. py:method:: get_boolean_data_properties() -> Iterable[owlapy.owl_property.OWLDataProperty] Get all boolean data properties of this concept generator. :returns: Boolean data properties. .. py:method:: get_numeric_data_properties() -> Iterable[owlapy.owl_property.OWLDataProperty] Get all numeric data properties of this concept generator. :returns: Numeric data properties. .. py:method:: get_double_data_properties() -> Iterable[owlapy.owl_property.OWLDataProperty] Get all numeric data properties of this concept generator. :returns: Numeric data properties. .. py:method:: get_time_data_properties() -> Iterable[owlapy.owl_property.OWLDataProperty] Get all time data properties of this concept generator. :returns: Time data properties. .. py:method:: get_types(ind: owlapy.owl_individual.OWLNamedIndividual, direct: bool = False) -> Iterable[owlapy.class_expression.OWLClass] Get the named classes which are (direct) types of the specified individual. :param ind: Individual. :param direct: Whether to consider direct types. :returns: Types of the given individual. .. py:method:: get_object_properties_for_ind(ind: owlapy.owl_individual.OWLNamedIndividual, direct: bool = True) -> Iterable[owlapy.owl_property.OWLObjectProperty] Get the object properties for the given individual. :param ind: Individual :param direct: Whether only direct properties should be considered (True), or if also indirect properties should be considered (False). Indirect properties would be super properties super_p of properties p with ObjectPropertyAssertion(p ind obj). :returns: Object properties. .. py:method:: get_data_properties_for_ind(ind: owlapy.owl_individual.OWLNamedIndividual, direct: bool = True) -> Iterable[owlapy.owl_property.OWLDataProperty] Get the data properties for the given individual :param ind: Individual :param direct: Whether only direct properties should be considered (True), or if also indirect properties should be considered (False). Indirect properties would be super properties super_p of properties p with ObjectPropertyAssertion(p ind obj). :returns: Data properties. .. py:method:: get_object_property_values(ind: owlapy.owl_individual.OWLNamedIndividual, property_: owlapy.owl_property.OWLObjectPropertyExpression, direct: bool = True) -> Iterable[owlapy.owl_individual.OWLNamedIndividual] Get the object property values for the given individual and property. :param ind: Individual. :param property_: Object property. :param direct: Whether only the property property_ should be considered (True), or if also the values of sub properties of property_ should be considered (False). :returns: Individuals. .. py:method:: get_data_property_values(ind: owlapy.owl_individual.OWLNamedIndividual, property_: owlapy.owl_property.OWLDataPropertyExpression, direct: bool = True) -> Iterable[owlapy.owl_literal.OWLLiteral] Get the data property values for the given individual and property. :param ind: Individual. :param property_: Data property. :param direct: Whether only the property property_ should be considered (True), or if also the values of sub properties of property_ should be considered (False). :returns: Literals. .. py:method:: contains_class(concept: owlapy.class_expression.OWLClassExpression) -> bool Check if an atomic class is contained within this concept generator. :param concept: Atomic class. :returns: Whether the class is contained in the concept generator. .. py:method:: __repr__()