semantica.triplet_store provides W3C-standard RDF storage with SPARQL 1.1 query support. Use it when you need semantic web compatibility, OWL-style reasoning, SPARQL-based queries, or standards-compliant RDF serialization.

Exported Classes

What You Get

  • TripletStore — Unified interface across embedded Oxigraph, Blazegraph, Apache Jena, and RDF4J: swap backends with one parameter.
  • SPARQL — Full SPARQL SELECT, ASK, CONSTRUCT, and UPDATE query support via execute_query().
  • Bulk Loadingadd_triplets() batches writes with configurable batch size, retry logic, and progress tracking.
  • SKOS Vocabulary — Built-in helpers: add_skos_concept() and get_skos_concepts() for controlled vocabulary management.
  • Named Graphs — Oxigraph, Blazegraph, and RDF4J support named graph scoping via graph= on execute_query().
  • Delta Computationcompute_delta(old_graph_uri, new_graph_uri) returns added and removed triples between two named graph snapshots.

Getting Started

TripletStore wraps the backend of your choice. Construct a Triplet object (from semantica.semantic_extract.types) and call add_triplet():

Quick Start

1

Connect to a backend

2

Add triplets

3

Query with SPARQL

4

Store an entire knowledge graph

Backends

Best for: local development, CI, desktop applications, and persistent single-process workloads without external infrastructure.
Use Oxigraph for zero-infrastructure development and local persistence. Switch to a server-backed store for distributed production deployments by changing backend=.

Triplet Object

All store operations use the Triplet dataclass from semantica.semantic_extract.types:
add_triplet() takes a Triplet object, not keyword arguments. Use Triplet(subject=..., predicate=..., object=...) from semantica.semantic_extract.types and pass the object: not subject=, predicate=, obj= to add_triplet.

TripletStore Methods

SPARQL Queries

execute_query() is the single entry point for all SPARQL operations. It returns a QueryResult: access results via .bindings:

QueryResult fields

execute_query() returns QueryResult, not a list. Iterate result.bindings, not result directly. Each binding is a dict mapping variable name → {"value": ..., "type": ...}.

SPARQL CONSTRUCT Templates

semantica.triplet_store.construct_templates provides parameterized SPARQL CONSTRUCT query templates: define a reusable query once, substitute typed parameters safely, and persist the resulting triples in one call. This is available for the Blazegraph backend only (see Backends above) — BlazegraphStore.execute_sparql() is the only backend with CONSTRUCT-aware RDF parsing.
Each ParameterDescriptor.type controls how its value is rendered: "uri" values are validated against an allowlist and wrapped in <...>, "literal" values are escaped and quoted, and "typed-literal" values require a datatype (e.g. "xsd:integer") and render unquoted for numeric/boolean XSD types. Placeholders use {{param}} rather than SPARQL’s own ?param syntax so template placeholders are never confused with real SPARQL variables in the query body.
CONSTRUCT templates are Blazegraph-only. execute_construct_template() raises ProcessingError if store_backend does not implement both execute_sparql() and add_triplets().

SPARQL Result Pagination

For large result sets, paginate with LIMIT and OFFSET:
Paginate large SPARQL result sets. A SELECT * WHERE { ?s ?p ?o } against a large store returns all triples. Always include LIMIT and OFFSET in exploratory queries. QueryEngine adds LIMIT 1000 automatically unless you specify one.

Named Graph Scoping

Oxigraph, Blazegraph, and RDF4J support named graphs. Scope execute_query() to a named graph with the graph= parameter:
Named graph query scoping is available for Oxigraph, Blazegraph, and RDF4J. The graph= query parameter is silently ignored for the Jena backend.
Use named graphs to isolate sources. Pass graph="http://example.org/source_A" to writes and execute_query() to scope both storage and retrieval. Oxigraph, Blazegraph, and RDF4J support named graph query scoping.

Bulk Loading

add_triplets() batches writes via the internal BulkLoader. Access store.bulk_loader to configure it:
BulkLoader can also be used directly with a progress_callback:

Storing a Knowledge Graph

store(knowledge_graph, ontology) converts a KG+ontology dict structure to RDF and bulk-loads everything in one call:

SKOS Vocabulary Management

Delta Computation

Integration with Export Module

The Export module writes RDF that the triplet store can then receive via add_triplets():
  • Export — Export knowledge graphs to RDF formats.
  • Ontology — Load OWL ontologies and store as RDF triples.
  • Reasoning — SPARQL-based property chain inference.
  • Graph Store — Property graph alternative for Cypher queries.