mirror of
https://github.com/semantica-agi/semantica.git
synced 2026-09-15 04:00:33 +00:00
- Rewrote all 26 reference module pages: removed blockquote taglines and horizontal rule separators, added "What You Get" bullet summaries, added constructor/method parameter tables, expanded thin files (graph_store, triplet_store, visualization, provenance) with full API coverage, added backend comparison tables and real-world usage patterns - Renamed Modules tab from "API Reference" and group from "Context & Knowledge" to "Context & Intelligence" in docs.json - Fixed logo: copied "Semantica Logo.png" to web-safe semantica-logo.png and updated all 4 references in docs.json - Improved core docs (index, modules, concepts, quickstart, installation, getting-started) with better fonts, bullet points, and complete module listings (mcp_server, evals, core, utils previously missing) - Rewrote community pages (community, community-projects, contributing-guide, use-cases, architecture, faq, learning-more, glossary) with heading hierarchy fixes, expanded definitions, and better structure - Fixed markdown linter warnings: MD036 bold-as-heading, MD001 heading skips, MD040 missing code fence language, MD032 blank lines around lists
4.8 KiB
4.8 KiB
title, description, icon
| title | description | icon |
|---|---|---|
| Triplet Store Module | RDF triple storage with SPARQL queries and bulk loading — Blazegraph, Apache Jena, and RDF4J. | table |
semantica.triplet_store provides W3C-standard RDF storage with full SPARQL query support. Use it when you need semantic web compatibility, OWL reasoning, SPARQL-based queries, or standards-compliant RDF serialization.
What You Get
TripletStore— unified interface for all RDF backends- Backends — Blazegraph, Apache Jena (Fuseki), RDF4J
- SPARQL — full SELECT, CONSTRUCT, ASK, and UPDATE query support
- Bulk loading — efficient batch import for large triple sets
- Import / Export — Turtle, JSON-LD, N-Triples, RDF/XML
Basic Usage
from semantica.triplet_store import TripletStore
store = TripletStore(
backend="blazegraph",
endpoint="http://localhost:9999/blazegraph/sparql"
)
# Add a single triplet
store.add_triplet(
subject="http://example.org/apple_inc",
predicate="http://example.org/founded_by",
obj="http://example.org/steve_jobs"
)
# Bulk load a list of triplets
store.add_triplets_bulk(triplets)
SPARQL Queries
# SELECT — returns tabular results
results = store.sparql("""
PREFIX ex: <http://example.org/>
SELECT ?person ?company WHERE {
?person ex:founded ?company .
?company ex:located_in ex:SiliconValley .
}
""")
for row in results:
print(row["person"], row["company"])
# CONSTRUCT — returns a graph of matched triples
graph = store.sparql_construct("""
PREFIX ex: <http://example.org/>
CONSTRUCT {
?s ex:connected_to ?o
} WHERE {
?s ex:founded ?company .
?company ex:has_investor ?o .
}
""")
# ASK — returns True/False
exists = store.sparql_ask("""
PREFIX ex: <http://example.org/>
ASK { ex:apple_inc ex:founded_by ex:steve_jobs . }
""")
# UPDATE — insert or delete triples
store.sparql_update("""
PREFIX ex: <http://example.org/>
INSERT DATA {
ex:apple_inc ex:listed_on ex:NASDAQ .
}
""")
Backends
# Blazegraph — open source, SPARQL 1.1
store = TripletStore(
backend="blazegraph",
endpoint="http://localhost:9999/blazegraph/sparql",
namespace="semantica"
)
# Apache Jena Fuseki — open source, widely used
store = TripletStore(
backend="jena",
endpoint="http://localhost:3030/dataset/sparql",
update_endpoint="http://localhost:3030/dataset/update"
)
# RDF4J — enterprise-grade, Eclipse Foundation
store = TripletStore(
backend="rdf4j",
server_url="http://localhost:8080/rdf4j-server",
repository_id="semantica"
)
Backend Comparison
| Backend | License | Query Language | Best For |
|---|---|---|---|
| Blazegraph | Open source | SPARQL 1.1 | Wikidata-style workloads |
| Apache Jena | Apache 2.0 | SPARQL 1.1 | General RDF, OWL reasoning |
| RDF4J | Eclipse 1.0 | SPARQL 1.1 | Enterprise, Java ecosystems |
Import and Export
# Import from file
store.import_file("ontology.ttl", format="turtle")
store.import_file("data.jsonld", format="json-ld")
store.import_file("triples.nt", format="nt")
# Export to file
store.export("output.ttl", format="turtle")
store.export("output.nt", format="nt")
store.export("output.xml", format="xml")
Graph Management
# Named graphs — store triples in isolated contexts
store.add_triplet(
subject="http://example.org/a",
predicate="http://example.org/p",
obj="http://example.org/b",
graph="http://example.org/graph1"
)
# Query a specific named graph
results = store.sparql("""
SELECT ?s ?p ?o FROM <http://example.org/graph1> WHERE {
?s ?p ?o .
}
""")
# List all named graphs
graphs = store.list_graphs()
# Clear a named graph
store.clear_graph("http://example.org/graph1")
Integration with Export Module
The Export module can write RDF that the triplet store then imports:
from semantica.export import RDFExporter
from semantica.triplet_store import TripletStore
# Export KG to Turtle
exporter = RDFExporter()
exporter.export_to_file(kg, "output.ttl", format="turtle")
# Load into triplet store
store = TripletStore(backend="jena", endpoint="http://localhost:3030/dataset/sparql")
store.import_file("output.ttl", format="turtle")
# Now query with SPARQL
results = store.sparql("SELECT * WHERE { ?s ?p ?o } LIMIT 10")