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.

rdf_kg_to_csv([path_kg, path_csv])

Constructs a CSV file from an RDF Knowledge Graph (RDF/XML)

create_ontology(iri[, with_owlapi])

A convenient function

generate_ontology([graph_as_json, output_path, ...])

Generates an ontology using quadruples from a given json file.

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")
owlapy.util_owl_static_funcs.rdf_kg_to_csv(path_kg: str = None, path_csv: str = None)[source]

Constructs a CSV file from an RDF Knowledge Graph (RDF/XML)

Parameters:
  • path_kg (str) – Path to the RDF Knowledge Graph file (RDF/XML)

  • path_csv (str) – Path where the reconstructed CSV should be saved.

Raises:

AssertionError – If the provided paths are None or invalid.

Example

>>> # Assuming you previously did:
>>> # csv_to_rdf_kg("iris_dataset.csv", "iris_kg.owl", "http://example.com/iris")
>>> rdf_kg_to_csv("iris_kg.owl", "reconstructed_iris_dataset.csv")
>>> print("CSV reconstructed from RDF KG saved as reconstructed_iris_dataset.csv")
owlapy.util_owl_static_funcs.create_ontology(iri, with_owlapi=False)[source]

A convenient function

owlapy.util_owl_static_funcs.generate_ontology(graph_as_json: str = None, output_path: str = 'generated_ontology.owl', output_format: str = 'xml', namespace: str = 'http://example.org/', generate_classes: bool = True, base_url: str = None, api_key: str = None, model: str = None, context: str = '', temperature: float = 0.15)[source]

Generates an ontology using quadruples from a given json file.

Parameters:
  • graph_as_json

    Path to the json file that contains the nested data. Nested structure should look like following where a graph can have multiple quadruples and each quadruple can have multiple subject-predicate-object triples:

    {‘graph’:[
    {
    quadruples:[
    {

    “subject”: … “predicate”: … “object”: …

    },

    ],

    }

    ]}

  • output_path – Path to the output result (an ontology).

  • output_format – The format the output should be written in. Chose from [“xml”, “n3”, “turtle”, “nt”, “pretty-xml”, “trix”, “trig”, “nquads”, “json-ld”, “hext”].

  • namespace – Namespace of the ontology.

  • generate_classes – Whether you want to generate classes or not (should provide LLM arguments if True).

  • base_url – Base URL for the OpenAI client.

  • api_key – API key for the OpenAI client.

  • model – Model name to use for class generation via OpenAI client.

  • context – Additional context for the ontology. Used as assisting information during LLM prompts. Describe the ontology focus area, weak points that can help the LLM to understand the data better, including potential examples that may help identify entities better.

  • temperature – Temperature to use for the LLM during class generation.