query-fa9ce5070953fe4890178537c0d677c4
Faster way to query sparql with labelsHi, I need to run SPARQL at wikidata endpoint using query that has a few labels in it, label query is very slow and inefficient, such as this, to find journalist that are born in Chicago it takes about 29 seconds, I have many other query that also time out.
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?ent ?wdtProperty ?val ?valLabel
WHERE { VALUES ?label1 { rdfs:label skos:altLabel } ?val wdt:P31|wdt:P106 [ ?label1 'journalist'@en ].
VALUES ?label2 { rdfs:label skos:altLabel } ?ent ?label2 "Chicago"@en.
VALUES ?labelB2 { rdfs:label skos:altLabel } ?wdProperty2 ?labelB2 "place of birth"@en;
wikibase:directClaim ?wdtProperty2.
?val ?wdtProperty2 ?ent .
OPTIONAL { ?val rdfs:label ?valLabel FILTER(lang(?valLabel) = "en") }
} LIMIT 10
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v5("?ent"):::projected
v2("?label1")
v4("?label2")
v6("?labelB2")
v3("?val"):::projected
v1("?valLabel"):::projected
v7("?wdProperty2")
v8("?wdtProperty2")
a1((" "))
a2((" "))
c2([sjournalist^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>"]):::literal
c5([sChicago^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>"]):::literal
c6([splace of birth^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>"]):::literal
bind0[/VALUES ?label1/]
bind0-->v2
bind00(["rdfs:label"])
bind00 --> bind0
bind01(["skos:altLabel"])
bind01 --> bind0
a1 -->v2--> c2
a2 -->v2--> c2
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
v3 --"wdt:P106"--> a2
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v3 --"wdt:P31"--> a1
end
union0r <== or ==> union0l
end
bind1[/VALUES ?label2/]
bind1-->v4
bind10(["rdfs:label"])
bind10 --> bind1
bind11(["skos:altLabel"])
bind11 --> bind1
v5 -->v4--> c5
bind2[/VALUES ?labelB2/]
bind2-->v6
bind20(["rdfs:label"])
bind20 --> bind2
bind21(["skos:altLabel"])
bind21 --> bind2
v7 -->v6--> c6
v7 --"wikibase:directClaim"--> v8
v3 -->v8--> v5
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v3 -."rdfs:label".-> v1
end