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, SPARQL powers wiki query, inline tables refreshed by wiki render, and (when enabled) a read-only HTTP endpoint on wiki serve.
Common prefixes
The wiki 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 query — ad-hoc queries from the terminal
- wiki render — refresh inline SPARQL result tables in markdown
- wiki serve — optional read-only HTTP endpoint on
wiki serve - wiki-templates/yasgui — 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.