Topic on Talk:Wikidata Query Service/User Manual/MWAPI

PAC2 (talkcontribs)

The following query get the number of items by gender in a Wikipedia article.

SELECT ?gender ?genderLabel (COUNT(?item) AS ?count) 
WHERE {
  SERVICE wikibase:mwapi {
     bd:serviceParam wikibase:endpoint "fr‧wikipedia.org"; 
                     wikibase:api "Generator";
                     mwapi:generator "links"; 
                     mwapi:titles "Sociologie";. 
     ?item wikibase:apiOutputItem mwapi:item.
  } 
  FILTER BOUND (?item)                                         # Safeguard to not get a timeout from unbound items when using ?item below
  ?item wdt:P21 ?gender .                                  
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }    
}
GROUP BY ?gender ?genderLabel

Try it!

I've been using thus query regularly this last two weeks and there was no bug but since yesterday night (March, 2nd 2021), this doesn't work anymore. Do you have any explanation for this behaviour change? PAC2 (talk) 20:18, 3 March 2021 (UTC)

Dipsacus fullonum (talkcontribs)

I doubt very much that this query have ever worked. The MWAPI endpoint is misspelled: ""fr‧wikipedia.org" instead of "fr.wikipedia.org"

Dipsacus fullonum (talkcontribs)

PS: I recommend using (COUNT(*) AS ?count) instead of (COUNT(?item) AS ?count). There is no need here to check that ?item is bound and that the value is error free which the latter version does. The change wont save much time here, but it is a good thing to remember to use when possible as it can save considerably time when counting large numbers.

Reply to "Mysterous bug"