owlapy.util_owl_static_funcs

Functions

save_owl_class_expressions(→ None)

Saves a set of OWL class expressions to an ontology file in RDF/XML format.

csv_to_rdf_kg([path_csv, path_kg, namespace])

Transfroms a CSV file to an RDF Knowledge Graph in RDF/XML format.

Module Contents

owlapy.util_owl_static_funcs.save_owl_class_expressions(expressions: owlapy.class_expression.OWLClassExpression | List[owlapy.class_expression.OWLClassExpression], path: str = 'predictions', rdf_format: str = 'rdfxml', namespace: str = None) None[source]

Saves a set of OWL class expressions to an ontology file in RDF/XML format.

This function takes one or more OWL class expressions, creates an ontology, and saves the expressions as OWL equivalent class axioms in the specified RDF format. By default, it saves the file to the specified path using the ‘rdfxml’ format.

Parameters:
  • expressions (OWLClassExpression | List[OWLClassExpression]) – A single or a list of OWL class expressions to be saved as equivalent class axioms.

  • path (str, optional) – The file path where the ontology will be saved. Defaults to ‘predictions’.

  • rdf_format (str, optional) – RDF serialization format for saving the ontology. Currently only supports ‘rdfxml’. Defaults to ‘rdfxml’.

  • namespace (str, optional) – The namespace URI used for the ontology. If None, defaults to ‘https://dice-research.org/predictions#’. Must end with ‘#’.

Raises:
  • AssertionError – If expressions is neither an OWLClassExpression nor a list of OWLClassExpression.

  • AssertionError – If rdf_format is not ‘rdfxml’.

  • AssertionError – If namespace does not end with a ‘#’.

Example

>>> from some_module import OWLClassExpression
>>> expr1 = OWLClassExpression("SomeExpression1")
>>> expr2 = OWLClassExpression("SomeExpression2")
>>> save_owl_class_expressions([expr1, expr2], path="my_ontology.owl", rdf_format="rdfxml")
owlapy.util_owl_static_funcs.csv_to_rdf_kg(path_csv: str = None, path_kg: str = None, namespace: str = None)[source]

Transfroms a CSV file to an RDF Knowledge Graph in RDF/XML format.

Parameters:
  • path_csv (str) – X

  • path_kg (str) – X

  • namespace (str) – X

Raises:

AssertionError

Example

>>> from sklearn.datasets import load_iris
>>> import pandas as pd
# Load the dataset
>>> data = load_iris()
# Convert to DataFrame
>>> df = pd.DataFrame(data.data, columns=data.feature_names)
>>> df['target'] = data.target
# Save as CSV
>>> df.to_csv("iris_dataset.csv", index=False)
>>> print("Dataset saved as iris_dataset.csv")
>>> csv_to_rdf_kg("iris_dataset.csv")