mirror of
https://github.com/semantica-agi/semantica.git
synced 2026-08-30 04:40:16 +00:00
- Added grid‑card layouts, icons, and admonitions to all reference pages - Removed all mkdocstrings ::: directives that caused alias‑resolution errors - Fixed export module alias issue (RDFExporter) by cleaning the docs - Updated README‑style sections for better readability - Added a PowerShell helper script (remove_mkdocstrings.ps1) for future clean‑ups
2.8 KiB
2.8 KiB
Triple Store Module
Store and query RDF triples with support for SPARQL queries and semantic reasoning using industry-standard triple stores.
Overview
- RDF Storage: Store subject-predicate-object triples
- SPARQL Queries: W3C-compliant query language
- Reasoning: RDFS and OWL reasoning
- Multiple Backends: RDFLib, Jena, Virtuoso, GraphDB
- Federation: Query across multiple triple stores
Algorithms Used
Query Algorithms
- SPARQL Query Optimization: Join reordering with selectivity estimation
- Triple Pattern Matching: Index-based lookup with B+ trees
- Graph Pattern Matching: Subgraph isomorphism
- Query Planning: Cost-based optimization
Indexing
- SPO Index: Subject-Predicate-Object index
- POS Index: Predicate-Object-Subject index
- OSP Index: Object-Subject-Predicate index
- Six-Index Scheme: All permutations for optimal query performance
Main Classes
TripleStore
Methods:
| Method | Description | Algorithm |
|---|---|---|
add_triple(subject, predicate, object) |
Add single triple | Index insertion |
add_triples(triples) |
Batch add triples | Bulk index insertion |
query(sparql_query) |
Execute SPARQL query | Query optimization + execution |
delete(pattern) |
Delete matching triples | Pattern matching + deletion |
serialize(format) |
Serialize to RDF format | Format-specific serialization |
Example:
from semantica.triple_store import TripleStore
store = TripleStore(backend="rdflib")
# Add triples
store.add_triple(
subject="http://example.org/AppleInc",
predicate="http://example.org/foundedBy",
object="http://example.org/SteveJobs"
)
# SPARQL query
results = store.query("""
SELECT ?company ?founder WHERE {
?company <http://example.org/foundedBy> ?founder .
}
""")
for row in results:
print(f"{row['company']} founded by {row['founder']}")
SPARQLQueryEngine
Methods:
| Method | Description | Algorithm |
|---|---|---|
execute(query) |
Execute SPARQL query | Parse + optimize + execute |
parse_query(sparql) |
Parse SPARQL syntax | SPARQL parser |
optimize_query(query) |
Optimize query plan | Join reordering |
explain_query(query) |
Explain query plan | Query plan visualization |
SPARQL Query Types:
- SELECT: Retrieve variable bindings
- CONSTRUCT: Build RDF graph
- ASK: Boolean query
- DESCRIBE: Describe resources
Configuration
# config.yaml - Triple Store Configuration
triple_store:
backend: rdflib # rdflib, jena, virtuoso, graphdb
indexing:
schemes: [SPO, POS, OSP] # Index permutations
query:
optimize: true
timeout: 30 # seconds