query-65007f922d5d42627209badb19889c93

rq turtle/ttl

requirements:

no aliases

only 1 label in de

3 descriptions in de, en, nl; those same apart from start

0 or 1 creator, if 1 matching with that one given in description

SELECT DISTINCT (STRAFTER(STR(?item), "entity/") AS ?qid) ?Lde (CONCAT("Gemälde aus dem Umkreis von ", ?descriptionTail) AS ?Dde) (CONCAT("painting by the circle of ", ?descriptionTail) AS ?Den) ("" AS ?Dnl) ?creator ?uncertaincreator

WHERE { ?item wdt:P195 wd:Q812285. ?item wdt:P31 wd:Q3305213. FILTER NOT EXISTS {?item skos:altLabel ?alias.} # no aliases OPTIONAL { ?item rdfs:label ?itemLabelOther FILTER((LANG(?itemLabelOther)) != "de") . } FILTER(!BOUND(?itemLabelOther)) # no non-de labels ?item rdfs:label ?itemLabel FILTER((LANG(?itemLabel)) = "de") . # 1 label in de OPTIONAL { ?item schema:description ?descriptionOther FILTER(LANG(?descriptionOther) NOT IN ("de", "en", "nl")) . } FILTER(!BOUND(?descriptionOther)) # no non-de/en/nl descriptions ?item schema:description ?descriptionDe FILTER(LANG(?descriptionDe) = "de") . ?item schema:description ?descriptionEn FILTER(LANG(?descriptionEn) = "en") . ?item schema:description ?descriptionNl FILTER(LANG(?descriptionNl) = "nl") . BIND(STRAFTER(STR(?descriptionDe), "Gemälde von ") AS ?descriptionTail) FILTER(?descriptionTail = STRAFTER(STR(?descriptionEn), "painting by ")) FILTER(?descriptionTail = STRAFTER(STR(?descriptionNl), "schilderij van ")) # same description tails

FILTER(REGEX(?itemLabel, "^.+\(.+\)$")) BIND(REPLACE(?itemLabel, "^.+\((.+)\)$", "$1") AS ?bracket) FILTER(REGEX(?bracket, 'Umkreis')) BIND(CONCAT("^(.+)\(", STR(?bracket), "\)$") AS ?matchBareLabel) # STR() shouldn't be necessary

BIND(REPLACE(?itemLabel, ?matchBareLabel, "$1") AS ?Lde) # why doesn't this work?

BIND(REPLACE(?itemLabel, "^(.+)\(Umkreis\)$", "$1") AS ?Lde)

MINUS { ?item p:P170 ?creatorstatement . ?creatorstatement prov:wasDerivedFrom ?reference . } OPTIONAL { ?item wdt:P170 ?creator . ?creator rdfs:label ?creatorLabel . # for matching purposes } OPTIONAL { ?item p:P170 ?creatorstatement. ?creatorstatement ps:P170 wd:Q4233718. ?creatorstatement ?qualifier ?uncertaincreator. ?qualifierproperty wikibase:qualifier ?qualifier. } }

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX schema: <http://schema.org/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX p: <http://www.wikidata.org/prop/>
# requirements:
# no aliases
# only 1 label in de
# 3 descriptions in de, en, nl; those same apart from start
# 0 or 1 creator, if 1 matching with that one given in description

SELECT DISTINCT
(STRAFTER(STR(?item), "entity/") AS ?qid)
?Lde
(CONCAT("Gemälde aus dem Umkreis von ", ?descriptionTail) AS ?Dde)
(CONCAT("painting by the circle of ", ?descriptionTail) AS ?Den)
("" AS ?Dnl)
?creator ?uncertaincreator

WHERE {
  ?item wdt:P195 wd:Q812285.
  ?item wdt:P31 wd:Q3305213.
  FILTER NOT EXISTS {?item skos:altLabel ?alias.} # no aliases
  OPTIONAL { ?item rdfs:label ?itemLabelOther FILTER((LANG(?itemLabelOther)) != "de") . }
  FILTER(!BOUND(?itemLabelOther)) # no non-de labels
  ?item rdfs:label ?itemLabel FILTER((LANG(?itemLabel)) = "de") . # 1 label in de
  OPTIONAL { ?item schema:description ?descriptionOther FILTER(LANG(?descriptionOther) NOT IN ("de", "en", "nl")) . }
  FILTER(!BOUND(?descriptionOther)) # no non-de/en/nl descriptions
  ?item schema:description ?descriptionDe FILTER(LANG(?descriptionDe) = "de") .
  ?item schema:description ?descriptionEn FILTER(LANG(?descriptionEn) = "en") .
  ?item schema:description ?descriptionNl FILTER(LANG(?descriptionNl) = "nl") .
  BIND(STRAFTER(STR(?descriptionDe), "Gemälde von ") AS ?descriptionTail)
  FILTER(?descriptionTail = STRAFTER(STR(?descriptionEn), "painting by "))
  FILTER(?descriptionTail = STRAFTER(STR(?descriptionNl), "schilderij van ")) # same description tails

  FILTER(REGEX(?itemLabel, "^.+\\(.+\\)$"))
  BIND(REPLACE(?itemLabel, "^.+\\((.+)\\)$", "$1") AS ?bracket)
  FILTER(REGEX(?bracket, 'Umkreis'))
  BIND(CONCAT("^(.+)\\(", STR(?bracket), "\\)$") AS ?matchBareLabel) # STR() shouldn't be necessary
#  BIND(REPLACE(?itemLabel, ?matchBareLabel, "$1") AS ?Lde) # why doesn't this work?
  BIND(REPLACE(?itemLabel, "^(.+)\\(Umkreis\\)$", "$1") AS ?Lde)

  MINUS {
    ?item p:P170 ?creatorstatement .
    ?creatorstatement prov:wasDerivedFrom ?reference .
  }
  OPTIONAL { ?item wdt:P170 ?creator .
             ?creator rdfs:label ?creatorLabel . # for matching purposes
           }
  OPTIONAL {
    ?item p:P170 ?creatorstatement.
    ?creatorstatement ps:P170 wd:Q4233718.
    ?creatorstatement ?qualifier ?uncertaincreator.
    ?qualifierproperty wikibase:qualifier ?qualifier.
  }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v21("?Dde") v22("?Den") v23("?Dnl") v12("?Lde"):::projected v10("?alias") v11("?bracket") v15("?creator"):::projected v16("?creatorLabel") v13("?creatorstatement") v6("?descriptionDe") v5("?descriptionEn") v4("?descriptionNl") v7("?descriptionOther") v11("?descriptionTail"):::projected v9("?item"):::projected v2("?itemLabel") v8("?itemLabelOther") v11("?matchBareLabel") v20("?qid") v17("?qualifier") v19("?qualifierproperty") v14("?reference") v18("?uncertaincreator"):::projected c19(["wd:Q4233718"]):::iri c10(["wd:Q812285"]):::iri c12(["wd:Q3305213"]):::iri f0[["regex(?bracket,'Umkreis')"]] f0 --> v11 f1[["regex(?itemLabel,'^.+\(.+\)$')"]] f1 --> v2 f2[["?descriptionTail = substring-after(str(?descriptionNl),'schilderij van ')"]] f2 --> v11 f2 --> v4 f3[["?descriptionTail = substring-after(str(?descriptionEn),'painting by ')"]] f3 --> v11 f3 --> v5 f4[["?descriptionNl = 'nl'"]] f4 --> v4 f5[["?descriptionEn = 'en'"]] f5 --> v5 f6[["?descriptionDe = 'de'"]] f6 --> v6 f7[["not bound(?descriptionOther)"]] f7 --> v7 f8[["?itemLabel = 'de'"]] f8 --> v2 f9[["not bound(?itemLabelOther)"]] f9 --> v8 f10[["not "]] subgraph f10e0["Exists Clause"] e0v1 --"skos:altLabel"--> e0v2 e0v2("?alias"):::projected e0v1("?item"):::projected end f10--EXISTS--> f10e0 f10 --> v9 f10 --> c8 f10 --> v10 v9 --"skos:altLabel"--> v10 v9 --"p:direct/P195"--> c10 v9 --"p:direct/P31"--> c12 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v9 -."rdfs:label".-> v8 end v9 --"rdfs:label"--> v2 subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v9 -."schema:description".-> v7 end v9 --"schema:description"--> v6 v9 --"schema:description"--> v5 v9 --"schema:description"--> v4 bind11[/"substring-after(str(?descriptionDe),'Gemälde von ')"/] v6 --o bind11 bind11 --as--o v11 bind12[/"replace(?itemLabel,'^.+\((.+)\)$','$1')"/] v2 --o bind12 bind12 --as--o v11 bind13[/"concat('^(.+)\(',str(?bracket),'\)$')"/] v11 --o bind13 bind13 --as--o v11 bind14[/"replace(?itemLabel,'^(.+)\(Umkreis\)$','$1')"/] v2 --o bind14 bind14 --as--o v12 subgraph minus15["MINUS"] style minus15 stroke-width:6px,fill:pink,stroke:red; v9 --"p:P170"--> v13 v13 --"prov:wasDerivedFrom"--> v14 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v9 -."p:direct/P170".-> v15 v15 --"rdfs:label"--> v16 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v9 -."p:P170".-> v13 v13 --"p:statement/P170"--> c19 v13 -->v17--> v18 v19 --"wikibase:qualifier"--> v17 end bind16[/"substring-after(str(?item),'entity/')"/] v9 --o bind16 bind16 --as--o v20 bind17[/"concat('Gemälde aus dem Umkreis von ',?descriptionTail)"/] v11 --o bind17 bind17 --as--o v21 bind18[/"concat('painting by the circle of ',?descriptionTail)"/] v11 --o bind18 bind18 --as--o v22 bind19[/"''"/] bind19 --as--o v23