CreateWorkspaceOntologyWorkflow
What it is
A Workflow that creates or updates a Naas workspace ontology from YAML data, optionally uploading a Turtle (.ttl) graph as a public asset and linking it as the ontology download URL.
Public API
-
CreateWorkspaceOntologyWorkflowConfiguration(dataclass)- Purpose: Workflow configuration container.
- Fields:
naas_integration_config: NaasIntegrationConfiguration— configuration forNaasIntegration.
-
CreateWorkspaceOntologyWorkflowParameters(WorkflowParameters)- Purpose: Input schema for creating/updating an ontology.
- Fields:
yaml_data: dict— YAML-serializable ontology source content.label: str— ontology label (also used to detect existing ontology by label).level: str = "USE_CASE"— ontology level.description: Optional[str] = "Ontology description not provided."logo_url: Optional[str] = "https://naasai-public.s3.eu-west-3.amazonaws.com/abi-demo/ontology_ULO.png"ontology_id: Optional[str] = None— if not provided, the workflow searches bylabel.graph: Optional[str] = None— Turtle string; when provided, it is parsed and uploaded as an asset.
-
CreateWorkspaceOntologyWorkflow(Workflow)create_or_update_workspace_ontology(parameters) -> str- Purpose:
- If
parameters.ontology_idisNone, lists existing ontologies in the workspace and reuses the one with matchinglabelif found. - Otherwise creates a new ontology (if none exists) or updates the existing one.
- If
parameters.graphis provided, uploads it as a public asset named<label>.ttland passes its URL asdownload_url.
- If
- Returns: the ontology id (
str). - Raises:
ValueErrorif creation/update fails to produce an ontology id.
- Purpose:
as_tools() -> list[BaseTool]- Purpose: Exposes the workflow as a LangChain
StructuredToolnamedconvert_graph_to_yaml(despite performing create/update).
- Purpose: Exposes the workflow as a LangChain
as_api(...) -> None- Purpose: declared but not implemented (
pass).
- Purpose: declared but not implemented (
Configuration/Dependencies
- Depends on:
NaasIntegrationfor:list_ontologies(workspace_id)create_ontology(...)update_ontology(...)upload_asset(...)
NaasABIModule.get_instance().configurationfor:workspace_idstorage_name
yaml.dump(..., Dumper=yaml.Dumper)to serializeyaml_datainto YAML source.rdflib.Graph().parse(data=..., format="turtle")to parsegraphwhen provided.
Usage
from naas_abi_marketplace.applications.naas.workflows.CreateWorkspaceOntologyWorkflow import (
CreateWorkspaceOntologyWorkflow,
CreateWorkspaceOntologyWorkflowConfiguration,
CreateWorkspaceOntologyWorkflowParameters,
)
from naas_abi_marketplace.applications.naas.integrations.NaasIntegration import (
NaasIntegrationConfiguration,
)
cfg = CreateWorkspaceOntologyWorkflowConfiguration(
naas_integration_config=NaasIntegrationConfiguration(
# populate with required integration settings
)
)
wf = CreateWorkspaceOntologyWorkflow(cfg)
params = CreateWorkspaceOntologyWorkflowParameters(
yaml_data={"entities": [], "relations": []},
label="My Ontology",
level="USE_CASE",
# graph="... turtle content ..." # optional
)
ontology_id = wf.create_or_update_workspace_ontology(params)
print(ontology_id)
Caveats
- If
ontology_idis not provided, the workflow identifies an existing ontology only by exactlabelmatch. - When
graphis provided:- It is parsed as Turtle; invalid Turtle will raise during
rdflibparsing. - Upload failure is logged, but the ontology can still be created/updated with
download_url=None.
- It is parsed as Turtle; invalid Turtle will raise during
as_tools()exposes a tool namedconvert_graph_to_yaml, but it actually performs create/update of the workspace ontology.