问题
PREFIX ex: <http://www.semanticweb.org/caeleanb/ontologies/twittermap#>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?name (STR(?name) AS ?strip_name) ?name2
WHERE {
?p ex:displayName ?name2 .
SERVICE <http://dbpedia.org/sparql> {
{ ?s rdfs:label ?name .
?s rdf:type foaf:Person . }
UNION
{ ?x rdfs:label ?name .
?x dbo:wikiPageRedirects ?s . }
}
FILTER(STR(?name) = ?name2) .
}
This is the SPARQL query that I am sending to my Stardog SPARQL endpoint (hosted locally). I know a bunch of the prefixes are missing but I promise it's not a prefix problem, Stardog holds the rest of the prefixes.
The query is supposed to find all foaf:Person
s which share a label string with a display name resource in my own ontology. The reason for the UNION is to try to catch all pages which redirect to the Person as well (but let me know if that part looks screwed up).
Basically the problem is that the above query gives me output like:
name strip_name name2
John McCain (en) | John McCain | John McCain
John McCain (de) | John McCain | John McCain
John McCain (es) | John McCain | John McCain
...
But John McCain is not a placeholder, he is the only one who shows up, just in a bunch of different languages. However, I expect many more to show up, since I can run queries like:
PREFIX ex: <http://www.semanticweb.org/caeleanb/ontologies/twittermap#>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?name (STR(?name) AS ?strip_name) ?name2
WHERE {
?p ex:displayName ?name2 .
SERVICE <http://dbpedia.org/sparql> {
{ ?s rdfs:label ?name .
?s rdf:type foaf:Person .
FILTER(?name="Bill Nye"@en)}
UNION
{ ?x rdfs:label ?name .
?x dbo:wikiPageRedirects ?s .
FILTER(?name="Bill Nye"@en)}
}
FILTER(STR(?name) = ?name2) .
}
and get output like:
name strip_name name2
Bill Nye (en) | Bill Nye | Bill Nye
I can repeat this trick with other names that I know should match in my ontology like "Jamie Oliver" and "Donald Trump" but for some reason the only name that shows up in the general version of the query is John McCain. Can anyone explain this to me? I'm sure I don't understand some part of the SERVICE block but I've tried a lot of different configurations and cannot get this query to work properly. Thanks for any help.
来源:https://stackoverflow.com/questions/46856300/how-can-i-match-string-labels-from-an-external-sparql-endpoint-with-string-label