Among the SPARQL Query Examples, there is a query for US presidents and spouses:
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX v: <http://www.wikidata.org/prop/statement/>
SELECT ?p ?w ?l ?wl WHERE {
wd:Q30 p:P6/v:P6 ?p .
?p wdt:P26 ?w .
OPTIONAL {
?p rdfs:label ?l filter (lang(?l) = "en") .
}
OPTIONAL {
?w rdfs:label ?wl filter (lang(?wl) = "en").
}
}
It contains function-like syntax, lang(?l)
, which is intended to filter by language.
How does this work? Is this a special function of Blazegraph? Or are different languages stored as normal values in RDF graphs?
How can I store data this way, so that it will be retrieved with the lang
function correctly?
May I have my own function to have ND predicates, like probability(?a) > 0.8
?
lang
is a native SPARQL operator (see the standard) which returns the language tag of an RDF literal (e.g. the EN
in ?p foaf:name "Robert"@EN.
).
Some SPARQL engines support the ability to implement custom functions. See for example this tutorial for Sesame and this for Blazegraph.