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

concept_len(ce[, length_metric, length_metric_factory])

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

compute_f1_score_from_confusion_matrix(→ float)

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)

get_file_base_name(→ str)

Extract the base name of a file from a given file path, excluding its extension.

prepare_output_path(→ str)

Create the output directory if it doesn't exist and return the full path for an output file.

assert_class_expression_type(→ bool)

Check whether the given object is a valid OWL class expression.

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.concept_len(ce: owlapy.class_expression.OWLClassExpression, length_metric: owlapy.utils.OWLClassExpressionLengthMetric | None = None, length_metric_factory: Callable[[], owlapy.utils.OWLClassExpressionLengthMetric] | None = None)[source]
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.compute_f1_score_from_confusion_matrix(confusion_matrix: dict) float[source]
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]
ontolearn.utils.static_funcs.get_file_base_name(file_path: str) str[source]

Extract the base name of a file from a given file path, excluding its extension.

Parameters:

file_path (str) – The full path to the file.

Returns:

The base name of the file without its extension.

Return type:

str

Example

>>> get_file_base_name("/path/to/file.txt")
'file'
ontolearn.utils.static_funcs.prepare_output_path(base_name: str, output_dir: str = 'results', extension: str = '.csv') str[source]

Create the output directory if it doesn’t exist and return the full path for an output file.

Parameters:
  • base_name (str) – The base name of the output file (without extension).

  • output_dir (str, optional) – Directory where the output file will be saved. Defaults to “results”.

  • extension (str, optional) – File extension to use. Defaults to “.csv”.

Returns:

The full path to the output file.

Return type:

str

Example

>>> prepare_output_path("summary")
'results/summary.csv'
ontolearn.utils.static_funcs.assert_class_expression_type(class_expr: Any) bool[source]

Check whether the given object is a valid OWL class expression.

This function verifies if the input object is an instance of any recognized OWL class expression types (e.g., union, intersection, cardinality restrictions, value restrictions, etc.).

Parameters:

class_expr (Any) – The object to check.

Returns:

True if the object is a valid OWL class expression; False otherwise.

Return type:

bool

Example

>>> assert_class_expression_type(some_owl_expression)
True