query-51be7b364a7defe32ed9113909c06b42
Items without relevant categoriesI am trying to write some queries to help link up WP categories and Wikidata claims. : (Q56285355)Member of the 1386 Parliament :(P39)position held This query finds anyone who is in the English Wikipedia's "English MPs 1386" category, but does not have
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 schema: <http://schema.org/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT distinct ?item ?member
{
VALUES ?term { wd:Q56285355 }
?term wdt:P910 ?category . ?link schema:about ?category; schema:isPartOf <https://en.wikipedia.org/>; schema:name ?cat_title .
SERVICE wikibase:mwapi {
# in
bd:serviceParam wikibase:endpoint "en.wikipedia.org";
wikibase:api "Generator";
mwapi:generator "categorymembers";
mwapi:gcmtitle ?cat_title;
mwapi:gcmprop "ids|title|type";
mwapi:gcmlimit "max".
# out
?member wikibase:apiOutput mwapi:title.
?item wikibase:apiOutputItem mwapi:item.
}
?item wdt:P31 wd:Q5 . filter not exists { ?item p:P39 ?ps . ?ps ps:P39 ?term }
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v6("?cat_title")
v4("?category")
v1("?item"):::projected
v5("?link")
v7("?member"):::projected
v2("?ps")
v4("?term")
c24(["mwapi:item"]):::iri
c6([https://en.wikipedia.org/]):::iri
c11(["en.wikipedia.org"]):::literal
c9(["bd:serviceParam"]):::iri
c26(["wd:Q5"]):::iri
c20(["max"]):::literal
c15(["categorymembers"]):::literal
c22(["mwapi:title"]):::iri
c18(["ids|title|type"]):::literal
c13(["Generator"]):::literal
f0[["not "]]
subgraph f0e0["Exists Clause"]
e0v1 --"p:P39"--> e0v2
e0v2 --"p:statement/P39"--> e0v3
e0v1("?item"):::projected
e0v2("?ps"):::projected
e0v3("?term"):::projected
end
f0--EXISTS--> f0e0
f0 --> v1
f0 --> c1
f0 --> v2
f0 --> c2
f0 --> v4
v1 --"p:P39"--> v2
v2 --"p:statement/P39"--> v4
bind1[/VALUES ?term/]
bind1-->v4
bind10(["wd:Q56285355"])
bind10 --> bind1
v4 --"p:direct/P910"--> v4
v5 --"schema:about"--> v4
v5 --"schema:isPartOf"--> c6
v5 --"schema:name"--> v6
subgraph s1["http://wikiba.se/ontology#mwapi"]
style s1 stroke-width:4px;
c9 --"mwapi:endpoint"--> c11
c9 --"mwapi:api"--> c13
c9 --"mwapi:generator"--> c15
c9 --"mwapi:gcmtitle"--> v6
c9 --"mwapi:gcmprop"--> c18
c9 --"mwapi:gcmlimit"--> c20
v7 --"mwapi:apiOutput"--> c22
v1 --"mwapi:apiOutputItem"--> c24
end
v1 --"p:direct/P31"--> c26