kapps_triplestore_interface.queries.triple_multi#

kapps_triplestore_interface.queries.triple_multi.triples_get(self: GraphDB, triple: Tuple[str | IRI | BNode | None, str | IRI | None, str | IRI | BNode | Any | Literal | None] | None = None, sub: str | IRI | BNode | None = None, pred: str | IRI | None = None, obj: str | IRI | BNode | Any | Literal | None = None, include_explicit: bool | None = True, include_implicit: bool | None = True, named_graph: str | IRI | None = None) → List[Tuple[IRI | BNode, IRI, Any]][source]#

Retrieve triples matching any combination of subject, predicate, or object.

Parameters:
  • triple (Optional[PartialTripleLike]) – Combined (subject, predicate, object) filter tuple. Use this or individual sub/pred/obj.

  • sub (Optional[SubjectLike]) – Subject filter (IRI/shorthand/string).

  • pred (Optional[PredicateLike]) – Predicate filter (IRI/shorthand/string).

  • obj (Optional[ObjectLike]) – Object filter (IRI/shorthand/Literal/string).

  • include_explicit (Optional[bool]) – Include explicit triples. Defaults to True.

  • include_implicit (Optional[bool]) – Include inferred triples. Defaults to True.

  • named_graph (Optional[GraphNameLike]) – Override the client’s default named graph.

Returns:

Matching triples as (subject, predicate, object), where the object is converted to an appropriate Python type when applicable.

Return type:

List[Tuple[Subject, Predicate, Any]]

Raises:

InvalidInputError – If neither or both of triple and any of sub/pred/obj are provided.

kapps_triplestore_interface.queries.triple_multi.any_triple_exists(self: GraphDB, triples: Set[Tuple[str | IRI | BNode, str | IRI, str | IRI | BNode | Any | Literal]] | List[Tuple[str | IRI | BNode, str | IRI, str | IRI | BNode | Any | Literal]] | Tuple[Tuple[str | IRI | BNode, str | IRI, str | IRI | BNode | Any | Literal]], named_graph: str | IRI | None = None) → bool[source]#

Check if any of the given triples exist.

Parameters:
  • triples (TriplesLike) – Triples to check.

  • named_graph (Optional[GraphNameLike]) – Override the client’s default named graph.

Returns:

True if at least one exists, False otherwise.

Return type:

bool

kapps_triplestore_interface.queries.triple_multi.all_triple_exists(self: GraphDB, triples: Set[Tuple[str | IRI | BNode, str | IRI, str | IRI | BNode | Any | Literal]] | List[Tuple[str | IRI | BNode, str | IRI, str | IRI | BNode | Any | Literal]] | Tuple[Tuple[str | IRI | BNode, str | IRI, str | IRI | BNode | Any | Literal]], named_graph: str | IRI | None = None) → bool[source]#

Check if all of the given triples exist.

Parameters:
  • triples (TriplesLike) – Triples to check.

  • named_graph (Optional[GraphNameLike]) – Override the client’s default named graph.

Returns:

True if all exist, False otherwise.

Return type:

bool

kapps_triplestore_interface.queries.triple_multi.triples_add(self: GraphDB, triples_to_add: Set[Tuple[str | IRI | BNode, str | IRI, str | IRI | BNode | Any | Literal]] | List[Tuple[str | IRI | BNode, str | IRI, str | IRI | BNode | Any | Literal]] | Tuple[Tuple[str | IRI | BNode, str | IRI, str | IRI | BNode | Any | Literal]], check_exist: bool | None = True, named_graph: str | IRI | None = None) → bool[source]#

Add multiple triples to the graph database.

Parameters:
  • triples_to_add (TriplesLike) – Triples to add.

  • check_exist (Optional[bool]) – If True, abort when any triple already exists. Defaults to True.

  • named_graph (Optional[GraphNameLike]) – Override the client’s default named graph.

Returns:

True if all triples were added, False otherwise.

Return type:

bool

kapps_triplestore_interface.queries.triple_multi.triples_delete(self: GraphDB, triples_to_delete: Set[Tuple[str | IRI | BNode, str | IRI, str | IRI | BNode | Any | Literal]] | List[Tuple[str | IRI | BNode, str | IRI, str | IRI | BNode | Any | Literal]] | Tuple[Tuple[str | IRI | BNode, str | IRI, str | IRI | BNode | Any | Literal]], check_exist: bool | None = True, named_graph: str | IRI | None = None) → bool[source]#

Delete multiple triples from the graph database.

Parameters:
  • triples_to_delete (TriplesLike) – Triples to delete.

  • check_exist (Optional[bool]) – If True, abort when any triple does not exist. Defaults to True.

  • named_graph (Optional[GraphNameLike]) – Override the client’s default named graph.

Returns:

True if all triples were deleted, False otherwise.

Return type:

bool

kapps_triplestore_interface.queries.triple_multi.triples_update(self: GraphDB, old_triples: Set[Tuple[str | IRI | BNode, str | IRI, str | IRI | BNode | Any | Literal]] | List[Tuple[str | IRI | BNode, str | IRI, str | IRI | BNode | Any | Literal]] | Tuple[Tuple[str | IRI | BNode, str | IRI, str | IRI | BNode | Any | Literal]], new_triples: Set[Tuple[str | IRI | BNode, str | IRI, str | IRI | BNode | Any | Literal]] | List[Tuple[str | IRI | BNode, str | IRI, str | IRI | BNode | Any | Literal]] | Tuple[Tuple[str | IRI | BNode, str | IRI, str | IRI | BNode | Any | Literal]], check_exist: bool | None = True, named_graph: str | IRI | None = None) → bool[source]#

Update multiple RDF triples in the triplestore.

The removal of old_triples and the insertion of new_triples are applied in a single atomic DELETE … INSERT … WHERE SPARQL transaction. The two lists need not be the same length: this supports pure additions, pure removals, and general replacements. Atomicity matters for constraint (e.g. SHACL) correctness — replacing a cardinality-constrained property (such as a possession handover under a “possessed by exactly one resource” shape) must never expose the intermediate state in which the property is momentarily absent.

Parameters:
  • old_triples (TriplesLike) – Triples to remove.

  • new_triples (TriplesLike) – Triples to insert. Need not match the length of old_triples.

  • check_exist (Optional[bool]) – If True, abort when any old triple does not exist. Defaults to True.

  • named_graph (Optional[GraphNameLike]) – Override the client’s default named graph.

Returns:

True if the update was successful, False otherwise.

Return type:

bool