query-626d28313676d96e3795c8e7265d2460
How to use wikidata property paths?Given a term/concept, I want to decide if it belongs to computer science. For that, I am checking if the concept has a property path to computer science node. In other words, I am checking whether computer science is an ancestral concept. For this purpose, I am using the following wikidata query.
Use at
- https://query.wikidata.org/sparql
PREFIX mwapi: <http://wikiba.se/ontology#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT DISTINCT ?item {
VALUES ?searchTerm { "word2vec"}
SERVICE wikibase:mwapi {
bd:serviceParam wikibase:api "EntitySearch".
bd:serviceParam wikibase:endpoint "www.wikidata.org".
bd:serviceParam wikibase:limit 3 .
bd:serviceParam mwapi:search ?searchTerm.
bd:serviceParam mwapi:language "en".
?item wikibase:apiOutputItem mwapi:item.
?num wikibase:apiOrdinal true.
}
?item (wdt:P279|wdt:P31) ?type
filter exists {?type (wdt:P279|wdt:P361)* wd:Q21198}
}
ORDER BY ?searchTerm ?num
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v4("?item"):::projected
v2("?num")
v4("?searchTerm")
v3("?type")
c9(["www.wikidata.org"]):::literal
c2(["wd:Q21198"]):::iri
c16(["mwapi:item"]):::iri
c14(["en"]):::literal
c5(["bd:serviceParam"]):::iri
c7(["EntitySearch"]):::literal
c11(["3^^xsd:integer"]):::literal
c18(["true^^xsd:boolean"]):::literal
f0[[" "]]
subgraph f0e0["Exists Clause"]
subgraph unione00[" Union "]
subgraph unione00l[" "]
style unione00l fill:#abf,stroke-dasharray: 3 3;
e0v1 --"wdt:P361"--> e0c2
end
subgraph unione00r[" "]
style unione00r fill:#abf,stroke-dasharray: 3 3;
e0v1 --"wdt:P279"--> e0c2
end
unione00r <== or ==> unione00l
end
e0v1("?type"):::projected
e0c2(["wd:Q21198"]):::iri
end
f0--EXISTS--> f0e0
f0 --> v3
f0 --> c1
f0 --> c2
f0 --> c3
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
v3 --"wdt:P361"--> c2
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v3 --"wdt:P279"--> c2
end
union0r <== or ==> union0l
end
bind1[/VALUES ?searchTerm/]
bind1-->v4
bind10(["word2vec"])
bind10 --> bind1
subgraph s1["http://wikiba.se/ontology#mwapi"]
style s1 stroke-width:4px;
c5 --"mwapi:api"--> c7
c5 --"mwapi:endpoint"--> c9
c5 --"mwapi:limit"--> c11
c5 --"mwapi:search"--> v4
c5 --"mwapi:language"--> c14
v4 --"mwapi:apiOutputItem"--> c16
v2 --"mwapi:apiOrdinal"--> c18
end
subgraph union1[" Union "]
subgraph union1l[" "]
style union1l fill:#abf,stroke-dasharray: 3 3;
v4 --"wdt:P31"--> v3
end
subgraph union1r[" "]
style union1r fill:#abf,stroke-dasharray: 3 3;
v4 --"wdt:P279"--> v3
end
union1r <== or ==> union1l
end