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 Loading —
add_triplets()batches writes with configurable batch size, retry logic, and progress tracking. - SKOS Vocabulary — Built-in helpers:
add_skos_concept()andget_skos_concepts()for controlled vocabulary management. - Named Graphs — Blazegraph and RDF4J support named graph scoping via
graph=onexecute_query(). - Delta Computation —
compute_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
- Blazegraph
- Apache Jena
- RDF4J
- Backend Comparison
Triplet Object
All store operations use theTriplet dataclass from semantica.semantic_extract.types:
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
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.
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:Named Graph Scoping
Blazegraph and RDF4J support named graphs. Scopeexecute_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.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 viaadd_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.
