ConvertOntologytoYamlWorkflow
What it is
A naas_abi_core.workflow.Workflow implementation that:
- Parses a Turtle (
.ttl) ontology (plus optional imported ontologies), - Extracts OWL classes, relationships, and OWL named individuals,
- Writes a YAML file with two sections:
classesandentities, - Optionally publishes the resulting YAML ontology to a Naas workspace via
CreateWorkspaceOntologyWorkflow.
Public API
Constants
GROUP_TO_STYLE: dict- Maps high-level ontology “groups” (e.g.,
WHO,WHAT) to visualization style fields used in YAML entity entries.
- Maps high-level ontology “groups” (e.g.,
Configuration
ConvertOntologytoYamlWorkflowConfiguration(WorkflowConfiguration)create_workspace_ontology_config: CreateWorkspaceOntologyWorkflowConfiguration(required)default_output_dir: Optional[str](optional fallback output directory)
Parameters
ConvertOntologytoYamlWorkflowParameters(WorkflowParameters)turtle_path: str— path to.ttlfile (must exist)output_dir: Optional[str]— output directory; if omitted usesdefault_output_dirthen TTL’s directoryimported_ontologies: Optional[List[str]]— additional ontology paths/URLs to loadpublish_to_workspace: bool— ifTrue, publishes YAML data to workspaceontology_name: str— label used when publishing to workspacedisplay_individuals_classes: bool— ifTrue, includesowl:Classentries inentitiessection
Workflow
ConvertOntologytoYamlWorkflow(Workflow)convert_ontology_to_yaml(parameters: ConvertOntologytoYamlWorkflowParameters) -> str- Produces
<ttl_stem>.yamlin the chosen output directory. - Returns the generated YAML file path as a string.
- Produces
as_tools() -> list[BaseTool]- Exposes a LangChain
StructuredToolnamedconvert_ontology_to_yaml_and_publish_to_workspace.
- Exposes a LangChain
as_api(...) -> None- No API routes are registered (currently returns
None).
- No API routes are registered (currently returns
Configuration/Dependencies
- Python packages:
PyYAML(yaml) for YAML outputrdflibfor RDF/OWL parsing and queryingfastapi(only for typeAPIRouter; API not implemented here)langchain_coretools (BaseTool,StructuredTool)
- Internal dependencies:
CreateWorkspaceOntologyWorkflowfor workspace publishingnaas_abi_marketplace.domains.ontology_engineer.utils.graph:parse_turtle_ontology,get_rdfs_label,get_short_name,get_class_id_prefix,get_group_from_class_hierarchy,get_inverse_property
- Output YAML structure:
classes: list of class dictionaries (id/name/description/examples/class/relations/style)entities: list of entity dictionaries (classes optionally + named individuals)
Usage
Minimal conversion to YAML (no publishing)
from naas_abi_marketplace.domains.ontology_engineer.workflows.ConvertOntologytoYamlWorkflow import (
ConvertOntologytoYamlWorkflow,
ConvertOntologytoYamlWorkflowConfiguration,
ConvertOntologytoYamlWorkflowParameters,
)
from naas_abi_marketplace.applications.naas.workflows.CreateWorkspaceOntologyWorkflow import (
CreateWorkspaceOntologyWorkflowConfiguration,
)
from naas_abi_marketplace.applications.naas.integrations.NaasIntegration import (
NaasIntegrationConfiguration,
)
config = ConvertOntologytoYamlWorkflowConfiguration(
create_workspace_ontology_config=CreateWorkspaceOntologyWorkflowConfiguration(
naas_integration_config=NaasIntegrationConfiguration(
api_key="NAAS_API_KEY",
workspace_id="WORKSPACE_ID",
storage_name="STORAGE_NAME",
)
),
default_output_dir=None,
)
workflow = ConvertOntologytoYamlWorkflow(config)
yaml_path = workflow.convert_ontology_to_yaml(
ConvertOntologytoYamlWorkflowParameters(
turtle_path="path/to/ontology.ttl",
imported_ontologies=None,
output_dir=None,
publish_to_workspace=False,
display_individuals_classes=True,
)
)
print(yaml_path)
Publishing to workspace
Set publish_to_workspace=True and provide ontology_name:
params = ConvertOntologytoYamlWorkflowParameters(
turtle_path="path/to/ontology.ttl",
publish_to_workspace=True,
ontology_name="My Ontology",
)
workflow.convert_ontology_to_yaml(params)
Caveats
- The input TTL path must exist; otherwise
FileNotFoundErroris raised. - If
PyYAMLis unavailable, conversion fails with anImportError. - Relationship deduplication for
owl:NamedIndividualentities attempts to skip inverse duplicates usingowl:inverseOf(viaget_inverse_property). as_api()is a stub; no FastAPI endpoints are created by this workflow.