SPARQL (Recursive acronym for SPARQL Protocol and RDF Query Language) is an RDF query language—that is, a semantic query language for databases—able to retrieve and manipulate data stored in RDF format.
In the Wiki CLI, SPARQL powers Wiki Subcommand query, inline tables refreshed by Wiki Subcommand render, and (when enabled) a read-only HTTP endpoint on Wiki Subcommand serve.
Common prefixes
The Wiki CLI automatically binds your namespace prefixes dynamically from the wiki.yaml file. The primary prefix mappings are:
schema:https://schema.org/(Standard schema vocabulary)wiki:https://wazootech.github.io/wiki/wiki/(Your local wiki namespace)rdf:http://www.w3.org/1999/02/22-rdf-syntax-ns#(Standard RDF attributes)
Example query types
Simple SELECT query
Extracts specific properties from your notes. For people, prefer schema:givenName and schema:familyName (see Style Guide):
PREFIX schema: <https://schema.org/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?person ?given ?family WHERE {
?person rdf:type schema:Person .
?person schema:givenName ?given .
?person schema:familyName ?family .
}
Filtered query
Uses standard string or URI filters to constrain your results. For TechArticle pages, schema:headline and schema:description are the display fields:
PREFIX schema: <https://schema.org/>
SELECT ?doc ?headline ?description WHERE {
?doc rdf:type schema:TechArticle .
?doc schema:headline ?headline .
OPTIONAL { ?doc schema:description ?description . }
FILTER(STRSTARTS(STR(?doc), "https://wazootech.github.io/wiki/wiki/"))
}
Active database summary
The table below queries the active graph to list all distinct classes currently instantiated in your wiki:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT DISTINCT ?class WHERE {
?s rdf:type ?class .
FILTER(STRSTARTS(STR(?class), "https://schema.org/"))
}
ORDER BY ?class
| class |
|---|
| https://schema.org/Person |
| https://schema.org/SoftwareApplication |
| https://schema.org/TechArticle |
Related
- Wiki Subcommand query — ad-hoc queries from the terminal
- Wiki Subcommand render — refresh inline SPARQL result tables in markdown
- Wiki Subcommand serve — optional read-only HTTP endpoint on
wiki serve - wiki-yasgui-template — external YASGUI template repository (Wiki CLI templates)
- Style Guide —
sparql:start/sparql:endblock conventions
References
- SPARQL 1.1 Query Language: Query language for RDF graphs.