I have an instance of Wikibase running. I'm able to run federated queries with Wikidata successfully. I have certain queries that compare labels like this:
PREFIX xwdt: <http://www.wikidata.org/prop/direct/>
PREFIX xwd: <http://www.wikidata.org/entity/>
PREFIX xpq: <http://www.wikidata.org/prop/qualifier/>
PREFIX xps: <http://www.wikidata.org/prop/statement/>
PREFIX xp: <http://www.wikidata.org/prop/>
select ?item ?wditem ?itemLabel ?wid ?wditemlabel
where {
?item wdt:P17 wd:Q39.
?item wdt:P31 wd:Q5.
optional {
?item wdt:P14 ?wid .
}
?item rdfs:label ?itemLabel.
SERVICE <https://query.wikidata.org/sparql> {
?wditem xwdt:P27 xwd:Q258.
?wditem xwdt:P106 xwd:Q937857.
?wditem rdfs:label ?wditemlabel.
filter(LANGMATCHES(LANG(?wditemlabel), "en")).
}
filter(contains(?wditemlabel, ?itemLabel))
}
group by ?item ?itemLabel ?wid ?wditem ?wditemlabel
The above works and matches items by their labels however:
1) I initially had filter(contains(?wditemlabel, ?itemLabel))
inside the SERVICE clause and it returned no results. But it seemed to work if I used a static string for one of the variables (e.g. filter(contains("test string", ?itemLabel))
). Why would it work when comparing a variable and a string but not two variables?
2) I expected the query to work without the "group by" at the end. But it looks like without it, some sort of cross join/Cartesian product occurs and each item that is matched is repeated the total number of times (n * n). What part of the query is causing this?