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 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 — 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: Wikidata-style workloads, high triple counts, named graph support, SPARQL 1.1 Update.
Use Apache Jena for development, Blazegraph for production. Jena initializes with rdflib in-memory: no server required for local testing. Switch to Blazegraph for high-throughput persistent workloads 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

Blazegraph and RDF4J support named graphs. Scope execute_query() to a named graph with the graph= parameter:
Named graph support is only available for Blazegraph and RDF4J backends. The graph= parameter is silently ignored for the Jena backend.
Use named graphs to isolate sources. Pass graph="http://example.org/source_A" to execute_query() to scope a query to a specific named graph. Blazegraph and RDF4J support named graphs; Jena (rdflib backend) does not.

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.