On 10/12/15 20:18, Osma Suominen wrote:
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX text: <http://jena.apache.org/text#>
SELECT *
WHERE {
GRAPH <http://www.yso.fi/onto/yso/> {
GRAPH <urn:x-arq:UnionGraph> {
(?s ?score ?literal) text:query 'musiikkikasv*' .
}
?s skos:prefLabel ?label .
FILTER (LANG(?label)=LANG(?literal))
}
}
You are running with union default graph? In which case that's good.
Else use <urn:x-arq:DefaultGraph>
One of my regrets in SPARQL is that you can't get back to the default
graph inside a GRAPH block.
The key to your query is the back that the FILTER covers the inner GRAPH.
This should work:
WHERE {
(?s ?score ?literal) text:query 'musiikkikasv*' .
GRAPH <http://www.yso.fi/onto/yso/> { ?s skos:prefLabel ?label . }
FILTER (LANG(?label)=LANG(?literal))
}
and it gets optimized into a
You had an OPTIONAL in the original:
WHERE {
(?s ?score ?literal) text:query 'musiikkikasv*' .
OPTIONAL {
GRAPH <http://www.yso.fi/onto/yso/>
{ ?s skos:prefLabel ?label . }
}
FILTER (!BOUND(?label) || LANG(?label)=LANG(?literal))
}
or
WHERE {
(?s ?score ?literal) text:query 'musiikkikasv*' .
OPTIONAL {
GRAPH <http://www.yso.fi/onto/yso/>
{ ?s skos:prefLabel ?label . }
FILTER (LANG(?label)=LANG(?literal))
}
}
In this one it is very important the FILTER is at the top level of the
OPTIONAL{} block. It puts ?literal in-scope because the FILTER is part
of the LeftJoin condition.
Andy