UpdateDataPropertyPipeline
What it is
- A
Pipelinethat updates a single data property (literal value) for a given RDF subject/predicate in a triple store. - It fetches the subject’s current graph, validates the predicate has exactly one existing value, removes the old triple, inserts the new literal, and returns the updated subject graph.
- Special case: when updating
rdfs:label, it also inserts the same value asskos:altLabel.
Public API
-
UpdateDataPropertyPipelineConfiguration(PipelineConfiguration)- Field
triple_store: ITripleStoreService— service used to insert/remove triples.
- Field
-
UpdateDataPropertyPipelineParameters(PipelineParameters)- Fields
subject_uri: str— subject URI (validated byURI_REGEX).predicate_uri: str— predicate URI (must match^http.+$).object_new_value: str— new literal value (see caveats about typing).language: Optional[str] = None— optional language tag for string literals.
- Fields
-
UpdateDataPropertyPipeline(Pipeline)__init__(configuration: UpdateDataPropertyPipelineConfiguration)- Initializes pipeline and SPARQL utilities (uses
ABIModule.get_instance().engine.services.triple_storefor SPARQL reads).
- Initializes pipeline and SPARQL utilities (uses
run(parameters: PipelineParameters) -> rdflib.Graph- Updates the property value in the configured triple store and returns the refreshed subject graph.
as_tools() -> list[langchain_core.tools.BaseTool]- Exposes a LangChain
StructuredToolnamedupdate_data_propertycallingrun(...).
- Exposes a LangChain
as_api(...) -> None- Stub; does not register any routes (returns
None).
- Stub; does not register any routes (returns
Configuration/Dependencies
- Requires an implementation of
ITripleStoreServicewith:insert(graph: rdflib.Graph)remove(graph: rdflib.Graph)
- Uses:
rdflib(Graph,URIRef,Literal,RDFS,SKOS,XSD)SPARQLUtils.get_subject_graph(subject_uri)to read current triples for the subject.
- Logging via
naas_abi_core.logger.
Usage
from rdflib import RDFS
from naas_abi_core.engine.Engine import Engine
from naas_abi.pipelines.UpdateDataPropertyPipeline import (
UpdateDataPropertyPipeline,
UpdateDataPropertyPipelineConfiguration,
UpdateDataPropertyPipelineParameters,
)
engine = Engine()
engine.load(module_names=["naas_abi"])
triple_store = engine.services.triple_store
pipeline = UpdateDataPropertyPipeline(
UpdateDataPropertyPipelineConfiguration(triple_store=triple_store)
)
graph = pipeline.run(
UpdateDataPropertyPipelineParameters(
subject_uri="http://ontology.naas.ai/abi/some-subject",
predicate_uri=str(RDFS.label),
object_new_value="Ford Motor Company",
language="en",
)
)
print(graph.serialize(format="turtle"))
Caveats
- The pipeline expects
parametersto beUpdateDataPropertyPipelineParameters; otherwise it raisesValueError. - Update only succeeds when the subject has:
- exactly one existing triple for
(subject, predicate, ?o). - If zero exist: returns an empty
Graph. - If multiple exist: returns an empty
Graph.
- exactly one existing triple for
object_new_valueis declared asstrin parameters, butrun()contains branches forfloatandint; in typical Pydantic usage it may be coerced tostr, so numeric-typed literals may not be produced as intended.- SPARQL reads use the global engine’s triple store (
ABIModule.get_instance().engine.services.triple_store), while writes useconfiguration.triple_store; these should refer to the same backend to avoid inconsistencies. - When
predicate_uriisrdfs:label, the pipeline also insertsskos:altLabelwith the same literal.