query-643f71b7ddfb265e85796ddbfb17091a

rq turtle/ttl

Books and their authors, where the author is not in the category tree for the book on Commons tool. QuickCategories's User:Lucas WerkmeisterI am trying to get Commons categories for a set of books, where Commons category is missing a categorisation (possibly indirect) for the author; with the aim of feeding the result into on meta. QuickCategories pageThe following is adapted from Lucas's query on the -- that runs fine. this queryIf I run it without the category-tree check -- ie But the full query is throwing me a 500 Server Status Error code. 22:20, 25 April 2019 (UTC)) talk (JhealdCan anyone spot what's going wrong, and tell me how to fix it?

Use at

PREFIX gas: <http://www.bigdata.com/rdf/gas#>
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/>
SELECT DISTINCT ?book ?commonsCategoryBook ?page ?command1
WITH {
  SELECT ?book ?auth WHERE {
    ?book wdt:P195 wd:Q53764729 .
    ?book wdt:P50 ?auth .
  }
} AS %pairs
WITH {
  SELECT ?auth ?commonsCategoryAuth WHERE {
    hint:SubQuery hint:optimizer "None". # we have to disable the optimizer for this subquery because it gets confused by the ?commonsCategoryStatementEn part
    INCLUDE %pairs.
    OPTIONAL {
      ?auth wdt:P373 ?commonsCategoryStatement.
      BIND(STRLANG(CONCAT("Category:", ?commonsCategoryStatement), "en") AS ?commonsCategoryStatementEn)
      ?commonsCategoryFromStatement schema:name ?commonsCategoryStatementEn;
                                    schema:isPartOf <https://commons.wikimedia.org/>.
    }
    OPTIONAL {
      ?commonsCategoryFromSitelink schema:about ?auth;
                                   schema:isPartOf <https://commons.wikimedia.org/>.
      FILTER(STRSTARTS(STR(?commonsCategoryFromSitelink), "https://commons.wikimedia.org/wiki/Category:"))
    }
    BIND(COALESCE(?commonsCategoryFromStatement, ?commonsCategoryFromSitelink) AS ?commonsCategoryAuth)
    FILTER(BOUND(?commonsCategoryAuth))
  }
} AS %authsWithCommonsCategories
WITH {
  SELECT ?book ?commonsCategoryBook WHERE {
    hint:SubQuery hint:optimizer "None". # we have to disable the optimizer for this subquery because it gets confused by the ?commonsCategoryStatementEn part
    INCLUDE %pairs.
    OPTIONAL {
      ?book wdt:P373 ?commonsCategoryStatement.
      BIND(STRLANG(CONCAT("Category:", ?commonsCategoryStatement), "en") AS ?commonsCategoryStatementEn)
      ?commonsCategoryFromStatement schema:name ?commonsCategoryStatementEn;
                                    schema:isPartOf <https://commons.wikimedia.org/>.
    }
    OPTIONAL {
      ?commonsCategoryFromSitelink schema:about ?book;
                                   schema:isPartOf <https://commons.wikimedia.org/>.
      FILTER(STRSTARTS(STR(?commonsCategoryFromSitelink), "https://commons.wikimedia.org/wiki/Category:"))
    }
    BIND(COALESCE(?commonsCategoryFromStatement, ?commonsCategoryFromSitelink) AS ?commonsCategoryBook)
    FILTER(BOUND(?commonsCategoryBook))
  }
} AS %booksWithCommonsCategories
WHERE {
  INCLUDE %pairs
  INCLUDE %booksWithCommonsCategories.
  INCLUDE %authsWithCommonsCategories.
  MINUS {
    SERVICE <https://query.wikidata.org/bigdata/namespace/categories/sparql> {
      SERVICE gas:service {
        gas:program gas:gasClass "com.bigdata.rdf.graph.analytics.BFS";
                    gas:linkType mediawiki:isInCategory;
                    gas:traversalDirection "Reverse";
                    gas:in ?commonsCategoryAuth;
                    gas:out ?commonsCategoryBook.
      }
    }
  }
  BIND(REPLACE(wikibase:decodeUri(SUBSTR(STR(?commonsCategoryBook), STRLEN("https://commons.wikimedia.org/wiki/") + 1)), "_", " ") AS ?page)
  BIND(CONCAT('+', REPLACE(wikibase:decodeUri(SUBSTR(STR(?commonsCategoryAuth), STRLEN("https://commons.wikimedia.org/wiki/") + 1)), "_", " ")) AS ?command1)
} ORDER BY ?page

Query found at