ontolearn.utils

Ontolearn utils.

Submodules

Attributes

Factory

DEFAULT_FMT

flag_for_performance

Functions

setup_logging([config_file])

Setup logging.

compute_f1_score(→ float)

Compute F1-score of a concept

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

jaccard_similarity(→ float)

Compute Jaccard Similarity

parametrized_performance_debugger([fmt])

performance_debugger(func_name)

create_experiment_folder([folder_name])

serializer(*, object_, path, serialized_name)

deserializer(*, path, serialized_name)

apply_TSNE_on_df(→ None)

balanced_sets(→ Tuple[Set, Set])

Balance given two sets through sampling without replacement.

read_csv(→ Union[None, pandas.DataFrame])

Path leads a folder containing embeddings in csv format.

assertion_path_isfile(→ bool)

sanity_checking_args(args)

read_individuals_file(...)

Read a text file containing IRIs of Named Individuals (one per line) and return the content as a set of OWL

read_named_classes_file(...)

Read a text file containing IRIs of OWL Named Classes (one per line) and return the content as a set of OWL

Package Contents

ontolearn.utils.setup_logging(config_file='ontolearn/logging.conf')[source]

Setup logging.

Parameters:

config_file (str) – Filepath for logs.

ontolearn.utils.compute_f1_score(individuals, pos, neg) float[source]

Compute F1-score of a concept

ontolearn.utils.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.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.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.Factory
ontolearn.utils.DEFAULT_FMT = 'Func:{name} took {elapsed:0.8f}s'
ontolearn.utils.flag_for_performance = False
ontolearn.utils.jaccard_similarity(y: Set[str], yhat: Set[str]) float[source]

Compute Jaccard Similarity :param y: A set of URIs :param yhat: A set of URIs :return:

ontolearn.utils.parametrized_performance_debugger(fmt=DEFAULT_FMT)[source]
ontolearn.utils.performance_debugger(func_name)[source]
ontolearn.utils.create_experiment_folder(folder_name='Log')[source]
ontolearn.utils.serializer(*, object_: object, path: str, serialized_name: str)[source]
ontolearn.utils.deserializer(*, path: str, serialized_name: str)[source]
ontolearn.utils.apply_TSNE_on_df(df) None[source]
ontolearn.utils.balanced_sets(a: set, b: set) Tuple[Set, Set][source]

Balance given two sets through sampling without replacement. Returned sets have the same length. @param a: @param b: @return:

ontolearn.utils.read_csv(path) None | pandas.DataFrame[source]

Path leads a folder containing embeddings in csv format. indexes correspond subjects or predicates or objects in n-triple. @param path: @return:

ontolearn.utils.assertion_path_isfile(path) bool[source]
ontolearn.utils.sanity_checking_args(args)[source]
ontolearn.utils.read_individuals_file(file: str) Set[owlapy.owl_individual.OWLNamedIndividual][source]

Read a text file containing IRIs of Named Individuals (one per line) and return the content as a set of OWL Named Individuals

Parameters:

file – path to the text file with the IRIs of the named individuals

Returns:

set of OWLNamedIndividual with these IRIs

ontolearn.utils.read_named_classes_file(file: str) Set[owlapy.class_expression.OWLClass][source]

Read a text file containing IRIs of OWL Named Classes (one per line) and return the content as a set of OWL Classes

Parameters:

file – path to the text file with the IRIs of the classes

Returns:

set of OWLNamedIndividual with these IRIs