Skip to content

Commit a12778a

Browse files
committed
fix(pipelines): add type assertions and improve label formatting in NexusPlatformPipeline
- Added assertions for ResultRow instances when iterating query results to ensure type safety. - Reformatted label capitalization from URI components for better readability. - Minor code cleanup: inline logger.debug call and remove redundant lines. Test Plan: - Verified that pipeline functions run without errors. - Observed logs confirming skip on unchanged signature. - Manual check of label formatting and graph modifications.
1 parent 1079f6d commit a12778a

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

libs/naas-abi/naas_abi/pipelines/NexusPlatformPipeline.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from naas_abi_core.utils.Expose import APIRouter
2121
from naas_abi_core.utils.SPARQL import SPARQLUtils
2222
from rdflib import RDF, Graph, Literal, Namespace, URIRef
23+
from rdflib.query import ResultRow
2324

2425
# Bump when the schema of what the pipeline writes changes (so old signatures
2526
# from older code versions trigger a rebuild even if inputs look identical).
@@ -181,6 +182,7 @@ def _read_stored_signature(self) -> str | None:
181182
"""
182183
)
183184
for row in results:
185+
assert isinstance(row, ResultRow)
184186
return str(row[0])
185187
return None
186188

@@ -199,13 +201,10 @@ def _write_signature(self, signature: str) -> None:
199201
)
200202
old_graph = Graph()
201203
for row in old_results:
202-
old_graph.add(
203-
(self._bootstrap_uri(), self._signature_predicate(), row[0])
204-
)
204+
assert isinstance(row, ResultRow)
205+
old_graph.add((self._bootstrap_uri(), self._signature_predicate(), row[0]))
205206
if len(old_graph) > 0:
206-
self.__triple_store.remove(
207-
old_graph, graph_name=self.__nexus_graph_uri
208-
)
207+
self.__triple_store.remove(old_graph, graph_name=self.__nexus_graph_uri)
209208

210209
new_graph = Graph()
211210
new_graph.add(
@@ -277,9 +276,14 @@ def create_graph_to_nexus_graph(
277276
label=role_label,
278277
is_knowledge_graph_role_of=[uri],
279278
)
279+
label = " ".join(
280+
word.capitalize()
281+
for word in uri.split("/")[-1].split("#")[-1].replace("_", " ").split()
282+
)
283+
280284
knowledge_graph = KnowledgeGraph(
281285
_uri=uri,
282-
label=uri.split("/")[-1].split("#")[-1].capitalize(),
286+
label=label,
283287
has_knowledge_graph_role=[knowledge_graph_role],
284288
)
285289
return knowledge_graph, knowledge_graph_role
@@ -599,9 +603,7 @@ def run(self, parameters: PipelineParameters) -> Graph:
599603
if not self.__force_update:
600604
stored_signature = self._read_stored_signature()
601605
if stored_signature is not None and stored_signature == current_signature:
602-
logger.debug(
603-
"Nexus platform signature unchanged; skipping rebuild."
604-
)
606+
logger.debug("Nexus platform signature unchanged; skipping rebuild.")
605607
return Graph()
606608

607609
# Ensure the nexus graph exists, then clear it so removed agents

0 commit comments

Comments
 (0)