ontolearn.model_adapter

Model adapters.

Module Contents

Classes

Trainer

Functions

transform_string(input_string)

Used to turn camelCase arguments to snake_case

compute_quality(KB, solution, pos, neg[, qulaity_func])

ModelAdapter(*args, **kwargs)

Instantiate a model through the model adapter.

execute(args)

Attributes

logger

metrics

models

heuristics

ontolearn.model_adapter.logger
ontolearn.model_adapter.metrics
ontolearn.model_adapter.models
ontolearn.model_adapter.heuristics
ontolearn.model_adapter.transform_string(input_string)[source]

Used to turn camelCase arguments to snake_case

ontolearn.model_adapter.compute_quality(KB, solution, pos, neg, qulaity_func='f1')[source]
ontolearn.model_adapter.ModelAdapter(*args, **kwargs)[source]

Instantiate a model through the model adapter.

Warning

You should not specify both: the _type and the object. For example, you should not give both ‘reasoner’ and ‘reasoner_type’ because the ModelAdapter cant decide which one to use, the reasoner object or create a new reasoner instance using ‘reasoner_type’.

Note

If you give _type for an argument you can pass further arguments to construct the instance of that class. The model adapter will arrange every argument automatically and use them to construct an object for that certain class type.

Parameters:
  • knowledge_base (AbstractKnowledgeBase) – A knowledge base.

  • knowledge_base_type – A knowledge base type.

  • ... – Knowledge base arguments.

  • reasoner – A reasoner.

  • reasoner_type – A reasoner type.

  • ... – Reasoner constructor arguments.

  • refinement_operator_type – A refinement operator type.

  • ... – Refinement operator arguments.

  • quality_type – An Abstract Scorer type.

  • ... – Quality arguments.

  • heuristic_func (AbstractHeuristic) – A heuristic.

  • heuristic_type – An Abstract Heuristic type.

  • ... – arguments For the heuristic type.

  • learner_type – A Base Concept Learner type.

  • ... – Arguments for the learning algorithm.

class ontolearn.model_adapter.Trainer(learner: BaseConceptLearner, reasoner: owlapy.owl_reasoner.OWLReasoner)[source]
fit(*args, **kwargs)[source]

Run the concept learning algorithm according to its configuration.

Once finished, the results can be queried with the best_hypotheses function.

best_hypotheses(n)[source]

Get the current best found hypotheses according to the quality.

Parameters:

n – Maximum number of results.

Returns:

Iterable with hypotheses in form of search tree nodes.

predict(individuals: List[owlapy.owl_individual.OWLNamedIndividual], hypotheses: List[_N | owlapy.class_expression.OWLClassExpression] | None = None, axioms: List[owlapy.owl_axiom.OWLAxiom] | None = None, n: int = 10)[source]
Creates a binary data frame showing for each individual whether it is entailed in the given hypotheses

(class expressions). The individuals do not have to be in the ontology/knowledge base yet. In that case, axioms describing these individuals must be provided.

The state of the knowledge base/ontology is not changed, any provided axioms will be removed again.

Parameters:
  • individuals – A list of individuals/instances.

  • hypotheses – (Optional) A list of search tree nodes or class expressions. If not provided, the current BaseConceptLearner.best_hypothesis() of the concept learner are used.

  • axioms – (Optional) A list of axioms that are not in the current knowledge base/ontology. If the individual list contains individuals that are not in the ontology yet, axioms describing these individuals must be provided. The argument can also be used to add arbitrary axioms to the ontology for the prediction.

  • n – Integer denoting number of ALC concepts to extract from search tree if hypotheses=None.

Returns:

Pandas data frame with dimensions |individuals|*|hypotheses| indicating for each individual and each hypothesis whether the individual is entailed in the hypothesis.

save_best_hypothesis(n: int = 10, path: str = 'Predictions', rdf_format: str = 'rdfxml') None[source]

Serialise the best hypotheses to a file.

Parameters:
  • n – Maximum number of hypotheses to save.

  • path – Filename base (extension will be added automatically).

  • rdf_format – Serialisation format. currently supported: “rdfxml”.

ontolearn.model_adapter.execute(args)[source]