query-f45e8213e75b939b99245cad5751929a
08:49, 7 February 2020 (UTC)) talk (Dipsacus fullonumI found the answer myself. It was (of course) that the engine tried to get all articles before running the subquery, and the solution is to change it to a named subquery which will run first. Version 3 is below. Execution time is about 1 second. --) talk (Dipsacus fullonumAbove is version 2. I moved the API access to a subquery and tried to get links to the articles. Currently the subquery gives 3 results, so I am surprised that getting ?article_en and ?article_it takes long time. With both outcommented as above, the whole query takes about 1 second. But if I try to get ?article_it, it takes 50 seconds. And If I try to get ?article_en, it times out. Can anyone explain, or even better fix, that? -- TODO
Use at
- https://query.wikidata.org/sparql
PREFIX mwapi: <http://wikiba.se/ontology#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX schema: <http://schema.org/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?item ?itemLabel ?article_en ?category_en ?article_it ?category_it
WHERE
{
{
SELECT ?item (COUNT(?in_en) AS ?category_en) (COUNT(?in_it) AS ?category_it)
WHERE
{
VALUES ?category { wd:Q7893678 }
{
[] schema:about ?category; schema:isPartOf <https://en.wikipedia.org/>; schema:name ?cat_title_en.
SERVICE wikibase:mwapi
{
bd:serviceParam wikibase:api "Generator".
bd:serviceParam wikibase:endpoint "en.wikipedia.org".
bd:serviceParam mwapi:gcmtitle ?cat_title_en.
bd:serviceParam mwapi:generator "categorymembers".
bd:serviceParam mwapi:gcmprop "ids".
bd:serviceParam mwapi:gcmlimit "max".
?item wikibase:apiOutputItem mwapi:item.
}
VALUES ?in_en { true }
}
UNION
{
[] schema:about ?category; schema:isPartOf <https://it.wikipedia.org/>; schema:name ?cat_title_it.
SERVICE wikibase:mwapi
{
bd:serviceParam wikibase:api "Generator".
bd:serviceParam wikibase:endpoint "it.wikipedia.org".
bd:serviceParam mwapi:gcmtitle ?cat_title_it.
bd:serviceParam mwapi:generator "categorymembers".
bd:serviceParam mwapi:gcmprop "ids".
bd:serviceParam mwapi:gcmlimit "max".
?item wikibase:apiOutputItem mwapi:item.
}
VALUES ?in_it { true }
}
}
GROUP BY ?item
HAVING (?category_en = 0 || ?category_it = 0)
}
?article_en schema:about ?item; schema:isPartOf <https://en.wikipedia.org/>.
?article_it schema:about ?item; schema:isPartOf <https://it.wikipedia.org/>.
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Query found at
- https://www.wikidata.org/wiki/User:Luckyz/CategoryComparison
- https://www.wikidata.org/wiki/Wikidata:Request_a_query/Archive/2020/02