ontolearn.utils.static_funcs

Functions

f1_set_similarity(→ float)

Compute F1 score for two set

concept_reducer(concepts, opt)

Reduces a set of concepts by applying a binary operation to each pair of concepts.

concept_reducer_properties(...)

Map a set of owl concepts and a set of properties into OWL Restrictions

make_iterable_verbose(→ Iterable)

init_length_metric([length_metric, length_metric_factory])

Initialize the technique on computing length of a concept

init_hierarchy_instances(...)

Initialize class, object property, and data property hierarchies

init_named_individuals(individuals_cache_size)

init_individuals_from_concepts([...])

compute_tp_fn_fp_tn(individuals, pos, neg)

compute_f1_score(→ float)

Compute F1-score of a concept

plot_umap_reduced_embeddings(→ None)

plot_decision_tree_of_expressions(→ None)

Plot the built CART Decision Tree and feature importance.

plot_topk_feature_importance(→ None)

Plot the feature importance of the CART Decision Tree.

save_owl_class_expressions(→ None)

verbalize(predictions_file_path)

Module Contents

ontolearn.utils.static_funcs.f1_set_similarity(y: Set[str], yhat: Set[str]) float[source]

Compute F1 score for two set :param y: A set of URIs :param yhat: A set of URIs :return:

ontolearn.utils.static_funcs.concept_reducer(concepts, opt)[source]

Reduces a set of concepts by applying a binary operation to each pair of concepts.

Parameters:
  • concepts (set) – A set of concepts to be reduced.

  • opt (function) – A binary function that takes a pair of concepts and returns a single concept.

Returns:

A set containing the results of applying the binary operation to each pair of concepts.

Return type:

set

Example

>>> concepts = {1, 2, 3}
>>> opt = lambda x: x[0] + x[1]
>>> concept_reducer(concepts, opt)
{2, 3, 4, 5, 6}

Note

The operation opt should be commutative and associative to ensure meaningful reduction in the context of set operations.

ontolearn.utils.static_funcs.concept_reducer_properties(concepts: Set, properties, cls: Callable = None, cardinality: int = 2) Set[owlapy.class_expression.OWLQuantifiedObjectRestriction | owlapy.class_expression.OWLObjectCardinalityRestriction][source]

Map a set of owl concepts and a set of properties into OWL Restrictions

Parameters:
  • concepts

  • properties

  • cls (Callable) – An owl Restriction class

  • cardinality – A positive Integer

Returns: List of OWL Restrictions

ontolearn.utils.static_funcs.make_iterable_verbose(iterable_object, verbose, desc='Default', position=None, leave=True) Iterable[source]
ontolearn.utils.static_funcs.init_length_metric(length_metric: owlapy.utils.OWLClassExpressionLengthMetric | None = None, length_metric_factory: Callable[[], owlapy.utils.OWLClassExpressionLengthMetric] | None = None)[source]

Initialize the technique on computing length of a concept

ontolearn.utils.static_funcs.init_hierarchy_instances(reasoner, class_hierarchy, object_property_hierarchy, data_property_hierarchy) Tuple[owlapy.owl_hierarchy.ClassHierarchy, owlapy.owl_hierarchy.ObjectPropertyHierarchy, owlapy.owl_hierarchy.DatatypePropertyHierarchy][source]

Initialize class, object property, and data property hierarchies

ontolearn.utils.static_funcs.init_named_individuals(individuals_cache_size)[source]
ontolearn.utils.static_funcs.init_individuals_from_concepts(include_implicit_individuals: bool = None, reasoner=None, ontology=None, individuals_per_concept=None)[source]
ontolearn.utils.static_funcs.compute_tp_fn_fp_tn(individuals, pos, neg)[source]
ontolearn.utils.static_funcs.compute_f1_score(individuals, pos, neg) float[source]

Compute F1-score of a concept

ontolearn.utils.static_funcs.plot_umap_reduced_embeddings(X: pandas.DataFrame, y: List[float], name: str = 'umap_visualization.pdf') None[source]
ontolearn.utils.static_funcs.plot_decision_tree_of_expressions(feature_names, cart_tree) None[source]

Plot the built CART Decision Tree and feature importance.

Parameters:
  • feature_names (list) – A list of feature names used in the decision tree.

  • cart_tree – The trained CART Decision Tree model.

Returns:

None

Notes

This function plots the decision tree using matplotlib and saves it to a PDF file named ‘cart_decision_tree.pdf’. It also displays the plot.

ontolearn.utils.static_funcs.plot_topk_feature_importance(feature_names, cart_tree, topk: int = 10) None[source]

Plot the feature importance of the CART Decision Tree.

Parameters:
  • feature_names (list) – A list of feature names used in the decision tree.

  • cart_tree – The trained CART Decision Tree model.

  • topk (int, optional) – The number of top features to display. Defaults to 10.

Returns:

None

Notes

This function plots a bar chart showing the importance of each feature in the decision tree, with the top k features displayed. The importance is measured by the normalized total reduction. The plot is displayed using matplotlib.

ontolearn.utils.static_funcs.save_owl_class_expressions(expressions: owlapy.class_expression.OWLClassExpression | List[owlapy.class_expression.OWLClassExpression], path: str = './Predictions', rdf_format: str = 'rdfxml') None[source]
ontolearn.utils.static_funcs.verbalize(predictions_file_path: str)[source]