query-d522b65050d2065516be1602d35883a5

rq turtle/ttl

“controversies” articles with the most sitelinks (language versions)

note: technically, this counts all sitelinks, not only Wikipedia ones (e.g. also Wikimedia Commons categories) –

the top results are correct, though, so I don’t think it’s worth complicating the query further to fix this

SELECT ?controversies ?controversiesLabel ?sitelinks WHERE { # find all “controversies” items using CirrusSearch (SPARQL isn’t the right tool for this job) SERVICE wikibase:mwapi { bd:serviceParam wikibase:endpoint "www.wikidata.org"; wikibase:api "Search"; # note: the “inlabel” keyword also searches aliases # exclude scholarly articles (Q13442814), there’s plenty of them and we don’t care about them here # also exclude categories (Q4167836, P4224); we’ll filter them out again below, but excluding some here speeds things up mwapi:srsearch "inlabel:controversies@en -haswbstatement:P31=Q13442814 -haswbstatement:P31=Q4167836 -haswbstatement:P4224"; # get as many search results at once as possible mwapi:srlimit "max". ?controversies wikibase:apiOutputItem mwapi:title. } # get the number of sitelinks and the English label ?controversies wikibase:sitelinks ?sitelinks; rdfs:label ?controversiesLabel. FILTER(LANG(?controversiesLabel) = "en") # filter out categories (-haswbstatement:P31=Q4167836 doesn’t exclude categories that are instance of a subclass of Q4167836) FILTER(!STRSTARTS(?controversiesLabel, "Category:"@en)) # also filter out templates (only one match at the moment, not worth adding this to the search string) FILTER(!STRSTARTS(?controversiesLabel, "Template:"@en)) # filter out the item about the “controversy” concept FILTER(?controversies != wd:Q1255828) # require at least one sitelink (article) FILTER(?sitelinks > 0) } ORDER BY DESC(?sitelinks)

Use at

PREFIX mwapi: <http://wikiba.se/ontology#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bd: <http://www.bigdata.com/rdf#>
# “controversies” articles with the most sitelinks (language versions)
# note: technically, this counts all sitelinks, not only Wikipedia ones (e.g. also Wikimedia Commons categories) –
# the top results are correct, though, so I don’t think it’s worth complicating the query further to fix this
SELECT ?controversies ?controversiesLabel ?sitelinks WHERE {
  # find all “controversies” items using CirrusSearch (SPARQL isn’t the right tool for this job)
  SERVICE wikibase:mwapi {
    bd:serviceParam wikibase:endpoint "www.wikidata.org";
                    wikibase:api "Search";
                    # note: the “inlabel” keyword also searches aliases
                    # exclude scholarly articles (Q13442814), there’s plenty of them and we don’t care about them here
                    # also exclude categories (Q4167836, P4224); we’ll filter them out again below, but excluding some here speeds things up
                    mwapi:srsearch "inlabel:controversies@en -haswbstatement:P31=Q13442814 -haswbstatement:P31=Q4167836 -haswbstatement:P4224";
                    # get as many search results at once as possible
                    mwapi:srlimit "max".
    ?controversies wikibase:apiOutputItem mwapi:title.
  }
  # get the number of sitelinks and the English label
  ?controversies wikibase:sitelinks ?sitelinks;
                 rdfs:label ?controversiesLabel.
  FILTER(LANG(?controversiesLabel) = "en")
  # filter out categories (-haswbstatement:P31=Q4167836 doesn’t exclude categories that are instance of a subclass of Q4167836)
  FILTER(!STRSTARTS(?controversiesLabel, "Category:"@en))
  # also filter out templates (only one match at the moment, not worth adding this to the search string)
  FILTER(!STRSTARTS(?controversiesLabel, "Template:"@en))
  # filter out the item about the “controversy” concept
  FILTER(?controversies != wd:Q1255828)
  # require at least one sitelink (article)
  FILTER(?sitelinks > 0)
}
ORDER BY DESC(?sitelinks)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v2("?controversies"):::projected v3("?controversiesLabel"):::projected v1("?sitelinks"):::projected c9(["www.wikidata.org"]):::literal c15(["max"]):::literal c13(["inlabel:controversies@en -haswbstatement:P31=Q13442814 -haswbstatement:P31=Q4167836 -haswbstatement:P4224"]):::literal c7(["bd:serviceParam"]):::iri c11(["Search"]):::literal c17(["mwapi:title"]):::iri f0[["?sitelinks > '0^^xsd:integer'"]] f0 --> v1 f1[["?controversies != 'wd:Q1255828'"]] f1 --> v2 f2[["not starts-with(?controversiesLabel,sTemplate:^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>')"]] f2 --> v3 f3[["not starts-with(?controversiesLabel,sCategory:^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>')"]] f3 --> v3 f4[["?controversiesLabel = 'en'"]] f4 --> v3 subgraph s1["http://wikiba.se/ontology#mwapi"] style s1 stroke-width:4px; c7 --"mwapi:endpoint"--> c9 c7 --"mwapi:api"--> c11 c7 --"mwapi:srsearch"--> c13 c7 --"mwapi:srlimit"--> c15 v2 --"mwapi:apiOutputItem"--> c17 end v2 --"mwapi:sitelinks"--> v1 v2 --"rdfs:label"--> v3