query-cb58dec6a2133d478c4e922bc8f234f6
Mwapi service duplicates querying categories : bug ? that implied querying categories (quality classification categories) could be solved with WDQS and its mwapi service, but a weirdness that might be a bug is bugging me : some duplicates. This is a query that checks if the talkpage of some articles are classified in one category on enwiki "Category:Start-Class biography articles". it works correctly. But the same query decomenting one or two other categories to include their members in the results returns repectively twice or trice each article. This is weird ! each article is classified in only one of these categories, it should appear once ! There is a join on the « ?category » variable. WD:RAQA question on check this one
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 bd: <http://www.bigdata.com/rdf#>
select ?item ?itemLabel ?genreLabel ?article ?name (lang(?name) as ?lang) ?category {
?item wdt:P31 wd:Q5 ;
wdt:P106/wdt:P279* wd:Q266569 .
optional {
?item wdt:P21 ?genre
}
filter (?genre != wd:Q6581097 ).
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
?article schema:about ?item ; schema:isPartOf <https://en.wikipedia.org/> ; schema:name ?name
########### find articles by their ratings on enwiki
# compute the name of the talk page on enwiki
bind (concat("Talk:", ?name) as ?title)
# find the categories of the talkpage using mwapi
SERVICE wikibase:mwapi {
# Categories that contain these pages
bd:serviceParam wikibase:api "Categories";
wikibase:endpoint "en.wikipedia.org";
mwapi:titles ?title.
# Output the page title and category
#?otitle wikibase:apiOutput mwapi:title.
?category wikibase:apiOutput mwapi:category .
}
values ?category { #### add relevant (sub?)categories if needed
"Category:Start-Class biography articles"
#"Category:Stub-Class biography articles"
#"Category:C-Class biography articles"
}
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v3("?article"):::projected
v7("?category"):::projected
v1("?genre")
v2("?item"):::projected
v7("?lang")
v4("?name"):::projected
v5("?title")
a1((" "))
c18(["Categories"]):::literal
c6(["wd:Q266569"]):::iri
c14([https://en.wikipedia.org/]):::iri
c20(["en.wikipedia.org"]):::literal
c9(["bd:serviceParam"]):::iri
c23(["mwapi:category"]):::iri
c3(["wd:Q5"]):::iri
c11(["#91;AUTO_LANGUAGE#93;,en"]):::literal
f0[["?genre != 'wd:Q6581097'"]]
f0 --> v1
v2 --"wdt:P31"--> c3
v2 --"wdt:P106"--> a1
a1 --"wdt:P279"--> c6
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v2 -."wdt:P21".-> v1
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c9 --"mwapi:language"--> c11
end
v3 --"schema:about"--> v2
v3 --"schema:isPartOf"--> c14
v3 --"schema:name"--> v4
bind1[/"concat('Talk:',?name)"/]
v4 --o bind1
bind1 --as--o v5
subgraph s2["http://wikiba.se/ontology#mwapi"]
style s2 stroke-width:4px;
c9 --"mwapi:api"--> c18
c9 --"mwapi:endpoint"--> c20
c9 --"mwapi:titles"--> v5
v7 --"mwapi:apiOutput"--> c23
end
bind2[/VALUES ?category/]
bind2-->v7
bind20(["Category:Start-Class biography articles"])
bind20 --> bind2
bind3[/"?name"/]
v4 --o bind3
bind3 --as--o v7