SPARQL reference (OntoIndex v0.8)¶
Status: Documents behavior in OntoIndex v0.8.0. Pre-1.0 APIs may change. Canonical feature list: What ships today.
Run SPARQL queries over the indexed triple store built from workspace ontology files.
ontoindex sparql /path/to/workspace "SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 10"
From a git clone:
cargo run -- sparql fixtures "SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 5"
Source of truth: sparql.rs on GitHub (Oxigraph SPARQL engine).
Behavior¶
- Queries run against triples parsed from all indexed files in the workspace
- The workspace is re-indexed on each CLI invocation (same as
queryandvalidate) - Result formats: text (default), JSON (
--format json) - SQL virtual tables are separate — use
ontoindex queryfor catalog tables likeclasses
Prefixes and IRIs¶
- Use full IRIs in queries, or declare prefixes in the SPARQL query:
PREFIX ex: <http://example.org/people#>
SELECT ?label WHERE { ex:Person rdfs:label ?label }
- Prefixes from Turtle
@prefixdeclarations in source files are not automatically injected into SPARQL — declare them in the query string.
Examples¶
# All triples (limited)
ontoindex sparql fixtures "SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 5"
# Labels for a known IRI
ontoindex sparql fixtures "SELECT ?label WHERE { <http://example.org/people#Person> rdfs:label ?label }"
# Count classes (approximate via rdf:type)
ontoindex sparql fixtures "SELECT (COUNT(?c) AS ?count) WHERE { ?c a owl:Class }"
# JSON output
ontoindex sparql fixtures "SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 3" --format json
More examples: query cookbook on GitHub.
Limits¶
| Limit | Value |
|---|---|
| Query string size | 1 MiB (MAX_QUERY_BYTES) |
| Result rows | 100,000 (silently truncated; LSP sets truncated: true) |
See workspace-limits.md.
LSP¶
SPARQL is available via the CLI, Rust API, LSP (ontoindex/sparql), and the VS Code Query Workbench (v0.5+). See lsp-api.md.
Related¶
- SQL-like catalog queries: sql-reference.md
- Query cookbook: query cookbook on GitHub