I have some triples that look like this:
test:thing rdfs:label "Non-Language Label"
test:thing rdfs:label "English Label"@en
test:thing rdfs:label "French Label"@fr
I'd like to form a sparql query that gives me the "Non-Language Label" AND the "French Label", if any exists.
I tried this and it's not working:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?label ?preferredLabel
WHERE {
test:thing rdfs:label ?label
OPTIONAL {
test:thing rdfs:label ?preferredLabel .
FILTER (regex(str(?preferredLabel), '(^|\\\\W)fr', 'i'))
}
}
Thanks in advance!
The easiest way to check the language of literals is to use the lang() function. Using this, your query can be written as:
I don't see why you need
OPTIONAL
here at all. Jan's query is failing because there is no shared variable between the outer pattern and the optional so you are trying to calculate the cross product of every label fortest:thing
with every non/french labelledtest:thing
which may be huge and why the query processor is failing.You simply want something like the following unless I've misunderstood your question
If you want the two labels separately then you could do something like: