query-f45e8213e75b939b99245cad5751929a

rq turtle/ttl

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

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

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v9("?article_en"):::projected v10("?article_it"):::projected v4("?cat_title_en") v7("?cat_title_it") v3("?category") v9("?category_en"):::projected v9("?category_it"):::projected v6("?in_en") v8("?in_it") v5("?item"):::projected a1((" ")) a2((" ")) c20(["mwapi:item"]):::iri c21([https://it.wikipedia.org/]):::iri c22(["it.wikipedia.org"]):::literal c4([https://en.wikipedia.org/]):::iri c11(["en.wikipedia.org"]):::literal c7(["bd:serviceParam"]):::iri c18(["max"]):::literal c14(["categorymembers"]):::literal c16(["ids"]):::literal c25(["#91;AUTO_LANGUAGE#93;,en"]):::literal c9(["Generator"]):::literal f0[["(?category_en = '0^^xsd:integer' || ?category_it = '0^^xsd:integer')"]] f0 --> v9 f0 --> v9 bind1[/VALUES ?category/] bind1-->v3 bind10(["wd:Q7893678"]) bind10 --> bind1 subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; a2 --"schema:about"--> v3 a2 --"schema:isPartOf"--> c21 a2 --"schema:name"--> v7 subgraph s1["http://wikiba.se/ontology#mwapi"] style s1 stroke-width:4px; c7 --"mwapi:api"--> c9 c7 --"mwapi:endpoint"--> c22 c7 --"mwapi:gcmtitle"--> v7 c7 --"mwapi:generator"--> c14 c7 --"mwapi:gcmprop"--> c16 c7 --"mwapi:gcmlimit"--> c18 v5 --"mwapi:apiOutputItem"--> c20 end bind2[/VALUES ?in_it/] bind2-->v8 bind20(["true^^xsd:boolean"]) bind20 --> bind2 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; a1 --"schema:about"--> v3 a1 --"schema:isPartOf"--> c4 a1 --"schema:name"--> v4 subgraph s1["http://wikiba.se/ontology#mwapi"] style s1 stroke-width:4px; c7 --"mwapi:api"--> c9 c7 --"mwapi:endpoint"--> c11 c7 --"mwapi:gcmtitle"--> v4 c7 --"mwapi:generator"--> c14 c7 --"mwapi:gcmprop"--> c16 c7 --"mwapi:gcmlimit"--> c18 v5 --"mwapi:apiOutputItem"--> c20 end bind3[/VALUES ?in_en/] bind3-->v6 bind30(["true^^xsd:boolean"]) bind30 --> bind3 end union0r <== or ==> union0l end bind6[/"count(?in_en)"/] v6 --o bind6 bind6 --as--o v9 bind7[/"count(?in_it)"/] v8 --o bind7 bind7 --as--o v9 v9 --"schema:about"--> v5 v9 --"schema:isPartOf"--> c4 v10 --"schema:about"--> v5 v10 --"schema:isPartOf"--> c21 subgraph s2["http://wikiba.se/ontology#label"] style s2 stroke-width:4px; c7 --"mwapi:language"--> c25 end