naas-abi 1.0.7__py3-none-any.whl → 1.0.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. naas_abi/__init__.py +16 -4
  2. naas_abi/agents/AbiAgent.py +18 -14
  3. naas_abi/agents/EntitytoSPARQLAgent.py +22 -17
  4. naas_abi/agents/KnowledgeGraphBuilderAgent.py +17 -15
  5. naas_abi/agents/OntologyEngineerAgent.py +4 -15
  6. naas_abi/apps/oxigraph_admin/main.py +7 -4
  7. naas_abi/apps/sparql_terminal/main.py +7 -4
  8. naas_abi/pipelines/AIAgentOntologyGenerationPipeline_test.py +4 -3
  9. naas_abi/pipelines/AddIndividualPipeline_test.py +10 -7
  10. naas_abi/pipelines/InsertDataSPARQLPipeline.py +6 -4
  11. naas_abi/pipelines/InsertDataSPARQLPipeline_test.py +9 -6
  12. naas_abi/pipelines/MergeIndividualsPipeline.py +6 -2
  13. naas_abi/pipelines/MergeIndividualsPipeline_test.py +10 -9
  14. naas_abi/pipelines/RemoveIndividualPipeline.py +6 -2
  15. naas_abi/pipelines/RemoveIndividualPipeline_test.py +8 -8
  16. naas_abi/pipelines/UpdateDataPropertyPipeline.py +6 -2
  17. naas_abi/workflows/GetObjectPropertiesFromClassWorkflow.py +10 -3
  18. naas_abi/workflows/GetObjectPropertiesFromClassWorkflow_test.py +7 -2
  19. naas_abi/workflows/GetSubjectGraphWorkflow_test.py +8 -3
  20. naas_abi/workflows/SearchIndividualWorkflow_test.py +6 -6
  21. {naas_abi-1.0.7.dist-info → naas_abi-1.0.9.dist-info}/METADATA +2 -2
  22. naas_abi-1.0.9.dist-info/RECORD +49 -0
  23. naas_abi/apps/terminal_agent/main.py +0 -553
  24. naas_abi/apps/terminal_agent/terminal_style.py +0 -175
  25. naas_abi/mappings.py +0 -83
  26. naas_abi/triggers.py +0 -131
  27. naas_abi/workflows/ConvertOntologyGraphToYamlWorkflow.py +0 -210
  28. naas_abi/workflows/ConvertOntologyGraphToYamlWorkflow_test.py +0 -78
  29. naas_abi/workflows/CreateClassOntologyYamlWorkflow.py +0 -214
  30. naas_abi/workflows/CreateClassOntologyYamlWorkflow_test.py +0 -65
  31. naas_abi/workflows/CreateIndividualOntologyYamlWorkflow.py +0 -183
  32. naas_abi/workflows/CreateIndividualOntologyYamlWorkflow_test.py +0 -86
  33. naas_abi/workflows/ExportGraphInstancesToExcelWorkflow.py +0 -450
  34. naas_abi/workflows/ExportGraphInstancesToExcelWorkflow_test.py +0 -33
  35. naas_abi-1.0.7.dist-info/RECORD +0 -61
  36. {naas_abi-1.0.7.dist-info → naas_abi-1.0.9.dist-info}/WHEEL +0 -0
  37. {naas_abi-1.0.7.dist-info → naas_abi-1.0.9.dist-info}/top_level.txt +0 -0
@@ -1,214 +0,0 @@
1
- from dataclasses import dataclass
2
- from enum import Enum
3
- from typing import Annotated, Any, Union
4
-
5
- from langchain_core.tools import BaseTool, StructuredTool
6
- from naas_abi.workflows.ConvertOntologyGraphToYamlWorkflow import (
7
- ConvertOntologyGraphToYamlWorkflow,
8
- ConvertOntologyGraphToYamlWorkflowConfiguration,
9
- ConvertOntologyGraphToYamlWorkflowParameters,
10
- )
11
- from naas_abi_core import logger, services
12
- from naas_abi_core.services.triple_store.TripleStorePorts import (
13
- ITripleStoreService,
14
- OntologyEvent,
15
- )
16
- from naas_abi_core.utils.Expose import APIRouter
17
- from naas_abi_core.utils.SPARQL import (
18
- get_class_uri_from_individual_uri,
19
- results_to_list,
20
- )
21
- from naas_abi_core.workflow import Workflow, WorkflowConfiguration
22
- from naas_abi_core.workflow.workflow import WorkflowParameters
23
- from pydantic import Field
24
- from rdflib import OWL, RDF, RDFS, Graph, Literal, URIRef
25
-
26
-
27
- @dataclass
28
- class CreateClassOntologyYamlWorkflowConfiguration(WorkflowConfiguration):
29
- """Configuration for CreateOntologyYAML workflow.
30
-
31
- Attributes:
32
- naas_integration_config (NaasIntegrationConfiguration): Configuration for the Naas integration
33
- """
34
-
35
- triple_store: ITripleStoreService
36
- convert_ontology_graph_config: ConvertOntologyGraphToYamlWorkflowConfiguration
37
-
38
-
39
- class CreateClassOntologyYamlWorkflowParameters(WorkflowParameters):
40
- """Parameters for CreateOntologyYAML workflow execution.
41
-
42
- Attributes:
43
- ontology_name (str): The name of the ontology store to use
44
- label (str): The label of the ontology
45
- description (str): The description of the ontology
46
- logo_url (str): The URL of the ontology logo
47
- level (str): The level of the ontology (e.g., 'TOP_LEVEL', 'MID_LEVEL', 'DOMAIN', 'USE_CASE')
48
- display_relations_names (bool): Whether to display relation names in the visualization
49
- """
50
-
51
- class_uri: Annotated[
52
- str, Field(..., description="The URI of the class to convert to YAML")
53
- ]
54
-
55
-
56
- class CreateClassOntologyYamlWorkflow(Workflow):
57
- """Workflow for converting ontology files to YAML and pushing them to a Naas workspace."""
58
-
59
- __configuration: CreateClassOntologyYamlWorkflowConfiguration
60
-
61
- def __init__(self, configuration: CreateClassOntologyYamlWorkflowConfiguration):
62
- self.__configuration = configuration
63
- self.__convert_ontology_graph_workflow = ConvertOntologyGraphToYamlWorkflow(
64
- self.__configuration.convert_ontology_graph_config
65
- )
66
-
67
- def trigger(
68
- self, event: OntologyEvent, triple: tuple[Any, Any, Any]
69
- ) -> Union[str, None]:
70
- s, p, o = triple
71
- # logger.debug(f"==> Triggering Create Class Ontology YAML Workflow: {s} {p} {o}")
72
- if (
73
- str(event) != str(OntologyEvent.INSERT)
74
- or not str(o).startswith("http")
75
- or str(o) == "http://www.w3.org/2002/07/owl#NamedIndividual"
76
- ):
77
- # logger.debug(f"==> Skipping class ontology YAML creation for {s} {p} {o}")
78
- return None
79
-
80
- # Get class type from URI
81
- class_uri = get_class_uri_from_individual_uri(s)
82
- class_uri_triggers = [
83
- "https://www.commoncoreontologies.org/ont00001262", # Person
84
- "https://www.commoncoreontologies.org/ont00000443", # Commercial Organization
85
- ]
86
- if class_uri in class_uri_triggers:
87
- logger.debug(
88
- f"==> Creating class ontology YAML for {class_uri} ({s} {p} {o})"
89
- )
90
- return self.graph_to_yaml(
91
- CreateClassOntologyYamlWorkflowParameters(class_uri=class_uri)
92
- )
93
- return None
94
-
95
- def graph_to_yaml(
96
- self, parameters: CreateClassOntologyYamlWorkflowParameters
97
- ) -> str:
98
- # Initialize graph
99
- graph = Graph()
100
- graph.bind("abi", "http://ontology.naas.ai/abi/")
101
-
102
- # Get label and description from class uri
103
- query = f"""
104
- PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
105
- PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
106
- SELECT ?label ?definition
107
- WHERE {{
108
- <{parameters.class_uri}> rdfs:label ?label .
109
- <{parameters.class_uri}> skos:definition ?definition .
110
- }}
111
- """
112
- results = services.triple_store_service.query(query)
113
- result_list = results_to_list(results)
114
- if result_list:
115
- ontology_label = result_list[0]["label"]
116
- ontology_description = result_list[0]["definition"]
117
- else:
118
- ontology_label = ""
119
- ontology_description = ""
120
-
121
- # Get triples from class uri
122
- query = f"""
123
- PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
124
-
125
- SELECT DISTINCT ?subject ?predicate ?object
126
- WHERE {{
127
- ?subject a <{parameters.class_uri}> .
128
- ?subject ?predicate ?object .
129
- }}
130
- ORDER BY ?subject ?predicate
131
- """
132
- results = services.triple_store_service.query(query)
133
- list_uri = []
134
- # Add triples to graph
135
- for row in results:
136
- subject = URIRef(row.get("subject"))
137
- predicate = URIRef(row.get("predicate"))
138
- obj = row.get("object")
139
-
140
- # Add triple to graph
141
- if isinstance(obj, str) and obj.startswith("http://ontology.naas.ai/abi/"):
142
- obj = URIRef(obj)
143
- list_uri.append(obj)
144
- else:
145
- obj = Literal(obj)
146
- graph.add((subject, predicate, obj))
147
-
148
- # Get all object properties label and type
149
- if len(list_uri) > 0:
150
- # Filter only ABI URIs
151
- uri_filter = (
152
- "(" + " || ".join([f"?object = <{uri}>" for uri in list_uri]) + ")"
153
- )
154
- query = f"""
155
- PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
156
-
157
- SELECT DISTINCT ?object ?label ?type
158
- WHERE {{
159
- ?object rdfs:label ?label .
160
- ?object rdf:type ?type .
161
- FILTER {uri_filter}
162
- }}
163
- ORDER BY ?object
164
- """
165
- results = services.triple_store_service.query(query)
166
-
167
- # Add object properties to graph
168
- for row in results:
169
- graph.add(
170
- (URIRef(row.get("object")), RDF.type, URIRef(row.get("type")))
171
- )
172
- graph.add((URIRef(row.get("object")), RDF.type, OWL.NamedIndividual))
173
- graph.add(
174
- (URIRef(row.get("object")), RDFS.label, Literal(row.get("label")))
175
- )
176
-
177
- # Convert graph to YAML & push to Naas workspace
178
- ontology_id = self.__convert_ontology_graph_workflow.graph_to_yaml(
179
- ConvertOntologyGraphToYamlWorkflowParameters(
180
- graph=graph.serialize(format="turtle"),
181
- label=ontology_label,
182
- description=ontology_description,
183
- )
184
- )
185
- return ontology_id
186
-
187
- def as_tools(self) -> list[BaseTool]:
188
- """Returns a list of LangChain tools for this workflow."""
189
- return [
190
- StructuredTool(
191
- name="ontology_create_class_yaml",
192
- description="Create an ontology class YAML and push it to Naas workspace.",
193
- func=lambda **kwargs: self.graph_to_yaml(
194
- CreateClassOntologyYamlWorkflowParameters(**kwargs)
195
- ),
196
- args_schema=CreateClassOntologyYamlWorkflowParameters,
197
- )
198
- ]
199
-
200
- def as_api(
201
- self,
202
- router: APIRouter,
203
- route_name: str = "",
204
- name: str = "",
205
- description: str = "",
206
- description_stream: str = "",
207
- tags: list[str | Enum] | None = None,
208
- ) -> None:
209
- if tags is None:
210
- tags = []
211
- return None
212
- if tags is None:
213
- tags = []
214
- return None
@@ -1,65 +0,0 @@
1
- import pytest
2
- from naas_abi import secret, services
3
- from naas_abi.workflows.ConvertOntologyGraphToYamlWorkflow import (
4
- ConvertOntologyGraphToYamlWorkflowConfiguration,
5
- )
6
- from naas_abi.workflows.CreateClassOntologyYamlWorkflow import (
7
- CreateClassOntologyYamlWorkflow,
8
- CreateClassOntologyYamlWorkflowConfiguration,
9
- CreateClassOntologyYamlWorkflowParameters,
10
- )
11
- from naas_abi_marketplace.applications.naas.integrations.NaasIntegration import (
12
- NaasIntegrationConfiguration,
13
- )
14
-
15
-
16
- @pytest.fixture
17
- def workflow() -> CreateClassOntologyYamlWorkflow:
18
- return CreateClassOntologyYamlWorkflow(
19
- CreateClassOntologyYamlWorkflowConfiguration(
20
- services.triple_store_service,
21
- ConvertOntologyGraphToYamlWorkflowConfiguration(
22
- NaasIntegrationConfiguration(api_key=secret.get("NAAS_API_KEY"))
23
- ),
24
- )
25
- )
26
-
27
-
28
- def test_create_class_ontology_yaml_workflow(workflow: CreateClassOntologyYamlWorkflow):
29
- import time
30
- from uuid import uuid4
31
-
32
- from naas_abi import services
33
- from rdflib import OWL, RDF, RDFS, Graph, Literal, Namespace, URIRef
34
-
35
- ABI = Namespace("http://ontology.naas.ai/abi/")
36
-
37
- graph = Graph()
38
- uri = ABI[str(uuid4())]
39
- graph.add(
40
- (uri, RDF.type, URIRef("https://www.commoncoreontologies.org/ont00000443"))
41
- )
42
- graph.add((uri, RDF.type, OWL.NamedIndividual))
43
- graph.add((uri, RDFS.label, Literal("Naas.ai")))
44
- graph.add(
45
- (
46
- uri,
47
- ABI.logo,
48
- Literal(
49
- "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ9gXMaBLQZ39W6Pk53PRuzFjUvv_6lLRWPoQ&s"
50
- ),
51
- )
52
- )
53
- services.triple_store_service.insert(graph)
54
- time.sleep(3)
55
-
56
- # Parameters
57
- class_uri = "https://www.commoncoreontologies.org/ont00001262"
58
-
59
- # Run workflow
60
- ontology_id = workflow.graph_to_yaml(
61
- CreateClassOntologyYamlWorkflowParameters(class_uri=class_uri)
62
- )
63
- assert ontology_id is not None, ontology_id
64
- assert ontology_id != "", ontology_id
65
- assert isinstance(ontology_id, str), ontology_id
@@ -1,183 +0,0 @@
1
- from dataclasses import dataclass
2
- from enum import Enum
3
- from typing import Annotated, Any, Union
4
-
5
- from langchain_core.tools import BaseTool, StructuredTool
6
- from naas_abi import ABIModule
7
- from naas_abi.workflows.ConvertOntologyGraphToYamlWorkflow import (
8
- ConvertOntologyGraphToYamlWorkflow,
9
- ConvertOntologyGraphToYamlWorkflowConfiguration,
10
- ConvertOntologyGraphToYamlWorkflowParameters,
11
- )
12
- from naas_abi_core.services.triple_store.TripleStorePorts import (
13
- ITripleStoreService,
14
- OntologyEvent,
15
- )
16
- from naas_abi_core.utils.Expose import APIRouter
17
- from naas_abi_core.utils.Graph import URI_REGEX
18
- from naas_abi_core.utils.SPARQL import SPARQLUtils
19
- from naas_abi_core.workflow import Workflow, WorkflowConfiguration
20
- from naas_abi_core.workflow.workflow import WorkflowParameters
21
- from pydantic import Field
22
- from rdflib import RDFS, Graph, Literal, URIRef
23
-
24
-
25
- @dataclass
26
- class CreateIndividualOntologyYamlWorkflowConfiguration(WorkflowConfiguration):
27
- """Configuration for CreateOntologyYAML workflow.
28
-
29
- Attributes:
30
- naas_integration_config (NaasIntegrationConfiguration): Configuration for the Naas integration
31
- """
32
-
33
- triple_store: ITripleStoreService
34
- convert_ontology_graph_config: ConvertOntologyGraphToYamlWorkflowConfiguration
35
-
36
-
37
- class CreateIndividualOntologyYamlWorkflowParameters(WorkflowParameters):
38
- """Parameters for CreateOntologyYAML workflow execution.
39
-
40
- Attributes:
41
- ontology_name (str): The name of the ontology store to use
42
- label (str): The label of the ontology
43
- description (str): The description of the ontology
44
- logo_url (str): The URL of the ontology logo
45
- level (str): The level of the ontology (e.g., 'TOP_LEVEL', 'MID_LEVEL', 'DOMAIN', 'USE_CASE')
46
- display_relations_names (bool): Whether to display relation names in the visualization
47
- """
48
-
49
- individual_uri: Annotated[
50
- str,
51
- Field(
52
- ...,
53
- description="The URI of the individual to convert to YAML",
54
- pattern=URI_REGEX,
55
- ),
56
- ]
57
- depth: Annotated[
58
- int,
59
- Field(
60
- description="The depth of the subject graph to get. 1 means the individual and its direct properties, 2 means the individual and its direct properties and the properties of the properties, etc."
61
- ),
62
- ] = 2
63
-
64
-
65
- class CreateIndividualOntologyYamlWorkflow(Workflow):
66
- """Workflow for converting ontology files to YAML and pushing them to a Naas workspace."""
67
-
68
- __configuration: CreateIndividualOntologyYamlWorkflowConfiguration
69
- __sparql_utils: SPARQLUtils
70
-
71
- def __init__(
72
- self, configuration: CreateIndividualOntologyYamlWorkflowConfiguration
73
- ):
74
- self.__configuration = configuration
75
- self.__convert_ontology_graph_workflow = ConvertOntologyGraphToYamlWorkflow(
76
- self.__configuration.convert_ontology_graph_config
77
- )
78
- self.__sparql_utils: SPARQLUtils = SPARQLUtils(
79
- ABIModule.get_instance().engine.services.triple_store
80
- )
81
-
82
- def trigger(
83
- self, event: OntologyEvent, triple: tuple[Any, Any, Any]
84
- ) -> Union[str, None]:
85
- s, p, o = triple
86
- if (
87
- str(event) != str(OntologyEvent.INSERT)
88
- or not str(s).startswith("http://ontology.naas.ai/abi/")
89
- or not str(o).startswith("http://ontology.naas.ai/abi/")
90
- ):
91
- return None
92
-
93
- # Get class type from URI
94
- class_uri = self.__sparql_utils.get_class_uri_from_individual_uri(s)
95
- class_uri_triggers = [
96
- "https://www.commoncoreontologies.org/ont00001262", # Person
97
- "https://www.commoncoreontologies.org/ont00000443", # Commercial Organization
98
- ]
99
- if class_uri in class_uri_triggers:
100
- return self.graph_to_yaml(
101
- CreateIndividualOntologyYamlWorkflowParameters(
102
- individual_uri=s, depth=2
103
- )
104
- )
105
- return None
106
-
107
- def graph_to_yaml(
108
- self, parameters: CreateIndividualOntologyYamlWorkflowParameters
109
- ) -> Union[str, None]:
110
- # Create individual graph
111
- graph = self.__sparql_utils.get_subject_graph(
112
- parameters.individual_uri, parameters.depth
113
- )
114
-
115
- # Get label from individual URI
116
- ontology_id = None
117
- ontology_label = ""
118
- ontology_description = ""
119
- ontology_logo_url = ""
120
- new_ontology = True
121
- for s, p, o in graph:
122
- if s == URIRef(parameters.individual_uri) and p == RDFS.label:
123
- ontology_label = str(o)
124
- ontology_description = f"{ontology_label} Ontology"
125
- if (
126
- s == URIRef(parameters.individual_uri)
127
- and str(p) == "http://ontology.naas.ai/abi/logo"
128
- ):
129
- ontology_logo_url = str(o)
130
- if (
131
- s == URIRef(parameters.individual_uri)
132
- and str(p) == "http://ontology.naas.ai/abi/naas_ontology_id"
133
- ):
134
- ontology_id = str(o)
135
- new_ontology = False
136
-
137
- # Convert graph to YAML & push to Naas workspace
138
- ontology_id = self.__convert_ontology_graph_workflow.graph_to_yaml(
139
- ConvertOntologyGraphToYamlWorkflowParameters(
140
- graph=graph.serialize(format="turtle"),
141
- ontology_id=ontology_id,
142
- label=ontology_label,
143
- description=ontology_description,
144
- logo_url=ontology_logo_url,
145
- )
146
- )
147
- if new_ontology:
148
- graph_insert = Graph()
149
- graph_insert.add(
150
- (
151
- URIRef(parameters.individual_uri),
152
- URIRef("http://ontology.naas.ai/abi/naas_ontology_id"),
153
- Literal(ontology_id),
154
- )
155
- )
156
- self.__configuration.triple_store.insert(graph_insert)
157
- return ontology_id
158
-
159
- def as_tools(self) -> list[BaseTool]:
160
- """Returns a list of LangChain tools for this workflow."""
161
- return [
162
- StructuredTool(
163
- name="create_individual_ontology_yaml",
164
- description="Create or Update a YAML ontology from an individual/instance in triple store and push it to Naas workspace.",
165
- func=lambda **kwargs: self.graph_to_yaml(
166
- CreateIndividualOntologyYamlWorkflowParameters(**kwargs)
167
- ),
168
- args_schema=CreateIndividualOntologyYamlWorkflowParameters,
169
- )
170
- ]
171
-
172
- def as_api(
173
- self,
174
- router: APIRouter,
175
- route_name: str = "",
176
- name: str = "",
177
- description: str = "",
178
- description_stream: str = "",
179
- tags: list[str | Enum] | None = None,
180
- ) -> None:
181
- if tags is None:
182
- tags = []
183
- return None
@@ -1,86 +0,0 @@
1
- import pytest
2
- from naas_abi import secret, services
3
- from naas_abi.workflows.ConvertOntologyGraphToYamlWorkflow import (
4
- ConvertOntologyGraphToYamlWorkflowConfiguration,
5
- )
6
- from naas_abi.workflows.CreateIndividualOntologyYamlWorkflow import (
7
- CreateIndividualOntologyYamlWorkflow,
8
- CreateIndividualOntologyYamlWorkflowConfiguration,
9
- CreateIndividualOntologyYamlWorkflowParameters,
10
- )
11
- from naas_abi_marketplace.applications.naas.integrations.NaasIntegration import (
12
- NaasIntegration,
13
- NaasIntegrationConfiguration,
14
- )
15
-
16
-
17
- @pytest.fixture
18
- def workflow() -> CreateIndividualOntologyYamlWorkflow:
19
- return CreateIndividualOntologyYamlWorkflow(
20
- CreateIndividualOntologyYamlWorkflowConfiguration(
21
- services.triple_store_service,
22
- ConvertOntologyGraphToYamlWorkflowConfiguration(
23
- NaasIntegrationConfiguration(api_key=secret.get("NAAS_API_KEY"))
24
- ),
25
- )
26
- )
27
-
28
-
29
- def test_create_individual_ontology_yaml_workflow(
30
- workflow: CreateIndividualOntologyYamlWorkflow,
31
- ):
32
- import time
33
- from uuid import uuid4
34
-
35
- from naas_abi import config, logger, services
36
- from naas_abi_core.utils.SPARQL import get_subject_graph
37
- from rdflib import OWL, RDF, RDFS, Graph, Literal, Namespace, URIRef
38
-
39
- ABI = Namespace("http://ontology.naas.ai/abi/")
40
-
41
- graph = Graph()
42
- uri = ABI[str(uuid4())]
43
- graph.add(
44
- (uri, RDF.type, URIRef("https://www.commoncoreontologies.org/ont00000443"))
45
- )
46
- graph.add((uri, RDF.type, OWL.NamedIndividual))
47
- graph.add((uri, RDFS.label, Literal("Naas.ai")))
48
- graph.add(
49
- (
50
- uri,
51
- ABI.logo,
52
- Literal(
53
- "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ9gXMaBLQZ39W6Pk53PRuzFjUvv_6lLRWPoQ&s"
54
- ),
55
- )
56
- )
57
- services.triple_store_service.insert(graph)
58
- time.sleep(3)
59
-
60
- # Run workflow
61
- ontology_id = workflow.graph_to_yaml(
62
- CreateIndividualOntologyYamlWorkflowParameters(individual_uri=str(uri), depth=1)
63
- )
64
-
65
- # Check if ontology id is set
66
- graph = get_subject_graph(str(uri), 1)
67
- naas_ontology_id = list(
68
- graph.triples(
69
- (None, URIRef("http://ontology.naas.ai/abi/naas_ontology_id"), None)
70
- )
71
- )[0][2]
72
- assert str(ontology_id) == str(naas_ontology_id), ontology_id
73
-
74
- # Remove graph
75
- services.triple_store_service.remove(graph)
76
-
77
- # Remove ontology
78
- if ontology_id:
79
- naas_integration = NaasIntegration(
80
- NaasIntegrationConfiguration(api_key=secret.get("NAAS_API_KEY"))
81
- )
82
- result = naas_integration.delete_ontology(
83
- workspace_id=config.workspace_id, ontology_id=ontology_id
84
- )
85
- logger.info(f"Removed ontology: {result}")
86
- assert result is not None, result