The SPARQL prologue allows users to list IRI prefixes and base IRIs, which is very useful for shortening IRIs in the query or update body. In Flint, there are two elements in the prologue, both of which are optional: the base IRI and the prefix map.
:base
The :base
IRI sets the base IRI that subsequent IRIs are relative to. In the following example:
{:base "<http://foo.org/>"
:select [?x]
:where [[?x "<bar>" ?y]]}
<bar>
expands to <http://foo.org/>
. During SPARQL translation, the above query becomes:
BASE <http://foo.org/>
SELECT ?x
WHERE {
?x <bar> ?y
}
NOTE: The SPARQL spec allows for multiple base IRIs to be defined, but this is not allowed in Flint. Having multiple base IRIs means that each set of IRIs after a base will use a different base IRI. Since this is mainly useful for defining different bases for IRI prefixes, which clashes with Flint's approach of one :prefixes
map per query or update.
:prefixes
The :prefixes` map associates prefix keywords to IRI prefixes. In the following example:
{:prefixes {:foaf "<http://xmlns.com/foaf/0.1/>"
:$ "<http://foo.org/>"}
:select [?x]
:where [[?x :foaf/name "Dr. X"]
[?y :bar ?z]]}
both :foaf/name
and :bar
are prefixed IRIs that are resolvable thanks to their prefixes having been defined in the :prefixes
map. Note the special prefix :$
, which represents the "null" prefix; this allows for prefixed IRIs like :bar
to be written without a namespace, while ensuring that it is still expandable to a full IRI. The above query translates to:
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX : <http://foo.org/>
SELECT ?x
WHERE {
?x foaf:name "Dr. X"
?y :bar ?z
}
While in SPARQL each prefix-IRI pair is preceded by PREFIX
, the :prefixes
map approach is more idiomatic to Clojure.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close