CreateClassOntologyYamlWorkflow
What it is
A workflow that:
- Builds an RDF graph from all triples of individuals of a given RDF class (by
class_uri), - Enriches the graph with labels/types for ABI URIs found as objects,
- Delegates conversion of that graph to YAML (and push to Naas workspace) to
ConvertOntologyGraphToYamlWorkflow.
It also includes a trigger hook to automatically run for specific class URIs on triple-store insert events.
Public API
Classes
-
CreateClassOntologyYamlWorkflowConfiguration(WorkflowConfiguration)- Holds dependencies:
triple_store: ITripleStoreServiceconvert_ontology_graph_config: ConvertOntologyGraphToYamlWorkflowConfiguration
- Holds dependencies:
-
CreateClassOntologyYamlWorkflowParameters(WorkflowParameters)- Parameters:
class_uri: str— URI of the RDF class to convert to YAML.
- Parameters:
-
CreateClassOntologyYamlWorkflow(Workflow)__init__(configuration: CreateClassOntologyYamlWorkflowConfiguration)- Wires the triple store SPARQL utilities and the downstream conversion workflow.
trigger(event: OntologyEvent, triple: tuple[Any, Any, Any]) -> str | None- On
OntologyEvent.INSERT, attempts to derive a class URI from the inserted subject (treated as an individual URI). - Only triggers YAML creation for a fixed allowlist of class URIs:
https://www.commoncoreontologies.org/ont00001262(Person)https://www.commoncoreontologies.org/ont00000443(Commercial Organization)
- Returns an ontology id (string) on success, otherwise
None.
- On
graph_to_yaml(parameters: CreateClassOntologyYamlWorkflowParameters) -> str- Queries the triple store to:
- Fetch
rdfs:labelandskos:definitionforclass_uri(used as label/description). - Fetch all triples
?subject a <class_uri> ; ?predicate ?objectand add them to an RDFLibGraph. - For any object that is a string starting with
http://ontology.naas.ai/abi/, treat it as a URI and additionally query for itsrdfs:labelandrdf:type, adding those to the graph (plusowl:NamedIndividual).
- Fetch
- Serializes the graph to Turtle and calls
ConvertOntologyGraphToYamlWorkflow.graph_to_yaml(...). - Returns the resulting ontology id.
- Queries the triple store to:
as_tools() -> list[BaseTool]- Exposes a LangChain
StructuredTool:- Name:
ontology_create_class_yaml - Args schema:
CreateClassOntologyYamlWorkflowParameters - Calls
graph_to_yaml(...).
- Name:
- Exposes a LangChain
as_api(...) -> None- Currently a no-op; returns
Noneimmediately and does not register routes.
- Currently a no-op; returns
Configuration/Dependencies
- Requires a triple store implementation:
ITripleStoreService(must support.query(query: str)).
- Requires configuration for downstream conversion:
ConvertOntologyGraphToYamlWorkflowConfiguration
- Uses:
SPARQLUtils(forget_class_uri_from_individual_uriand results conversion),rdflib(Graph,URIRef,Literal, RDF/RDFS/OWL constants),langchain_core.tools.StructuredTool.
Usage
Run conversion for a class URI
from naas_abi_marketplace.applications.naas.workflows.CreateClassOntologyYamlWorkflow import (
CreateClassOntologyYamlWorkflow,
CreateClassOntologyYamlWorkflowConfiguration,
CreateClassOntologyYamlWorkflowParameters,
)
# Provide concrete implementations/configs from your environment:
triple_store = ... # ITripleStoreService
convert_cfg = ... # ConvertOntologyGraphToYamlWorkflowConfiguration
wf = CreateClassOntologyYamlWorkflow(
CreateClassOntologyYamlWorkflowConfiguration(
triple_store=triple_store,
convert_ontology_graph_config=convert_cfg,
)
)
ontology_id = wf.graph_to_yaml(
CreateClassOntologyYamlWorkflowParameters(
class_uri="https://www.commoncoreontologies.org/ont00001262"
)
)
print(ontology_id)
Use as a LangChain tool
tool = wf.as_tools()[0]
result = tool.run({"class_uri": "https://www.commoncoreontologies.org/ont00001262"})
print(result)
Caveats
trigger(...)only runs onOntologyEvent.INSERTand only for two hard-coded class URIs (Person, Commercial Organization).- Objects are treated as ABI URIs only if they are
strand start withhttp://ontology.naas.ai/abi/; everything else is stored as an RDF literal. as_api(...)does nothing (earlyreturn None), so no HTTP endpoints are exposed from this module.