query-ce85862d6f87dc9b6fc8adc0dff067f5

rq turtle/ttl

Books or suclasses of books (NOT editions) written in a language the author, supposedly, can't write SELECT DISTINCT ?work ?workLabel ?worklangLabel ?authorLabel ?knownlanguagesLabel ?nativelanguageLabel WHERE {

#Work is an instance or any subclass of book ?work wdt:P31/wdt:P279* wd:Q571 .

#Work is an instance of whatever ?work wdt:P31 ?what .

#BUT is not an instance of a version, translation or edition FILTER ( ?what != wd:Q3331189 )

#Show inception date of the work if available OPTIONAL { ?work wdt:P571 ?date . BIND(YEAR( ?date ) as ?year) }

#Get the language of the work ?work wdt:P407 ?worklang .

#AND the author ?work wdt:P50 ?author .

# Be sure author has almost one value for native language OR language known, written, etc. { ?author wdt:P1412 ?knownlanguages . } UNION { ?author wdt:P103 ?nativelanguage . }

FILTER NOT EXISTS { # Author doesn't know ?worklang { ?author wdt:P1412 ?worklang . }

# OR ?worklang is his native language UNION { ?author wdt:P103 ?worklang . }

# OR ?worklang is not a subclass of his known languages UNION { ?author wdt:P1412 ?knownlanguages . ?knownlanguages wdt:P279* ?worklang . }

# OR ?worklang is not a subclass of his native language UNION { ?author wdt:P103 ?nativelanguage . ?nativelanguage wdt:P279* ?worklang . } }

SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }

}

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
#Books or suclasses of books (NOT editions) written in a language the author, supposedly, can't write
SELECT DISTINCT ?work ?workLabel ?worklangLabel ?authorLabel ?knownlanguagesLabel ?nativelanguageLabel WHERE {

  #Work is an instance or any subclass of book 
  ?work wdt:P31/wdt:P279* wd:Q571 .

  #Work is an instance of whatever
  ?work wdt:P31 ?what .

  #BUT is not an instance of a version, translation or edition
  FILTER ( ?what != wd:Q3331189 )  

  #Show inception date of the work if available
  OPTIONAL { ?work wdt:P571 ?date . BIND(YEAR( ?date ) as ?year) }

  #Get the language of the work
  ?work wdt:P407 ?worklang .

  #AND the author
  ?work wdt:P50 ?author .

  # Be sure author has almost one value for native language OR language known, written, etc.
  { ?author wdt:P1412 ?knownlanguages . } UNION { ?author wdt:P103 ?nativelanguage . }     

  FILTER NOT EXISTS {
  # Author doesn't know ?worklang
  { ?author wdt:P1412 ?worklang . }

  # OR ?worklang is his native language
  UNION { ?author wdt:P103 ?worklang . }

  # OR ?worklang is not a subclass of his known languages
  UNION  { ?author wdt:P1412 ?knownlanguages . ?knownlanguages wdt:P279* ?worklang . } 

  # OR ?worklang is not a subclass of his native language
  UNION  { ?author wdt:P103 ?nativelanguage . ?nativelanguage wdt:P279* ?worklang . }
  }

  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; v1("?author") v7("?date") v3("?knownlanguages") v4("?nativelanguage") v5("?what") v6("?work"):::projected v2("?worklang") v8("?year") a1((" ")) c11(["bd:serviceParam"]):::iri c13(["#91;AUTO_LANGUAGE#93;,en"]):::literal c6(["wd:Q571"]):::iri f0[["not "]] subgraph f0e0["Exists Clause"] subgraph unione00[" Union "] subgraph unione00l[" "] style unione00l fill:#abf,stroke-dasharray: 3 3; subgraph unione01[" Union "] subgraph unione01l[" "] style unione01l fill:#abf,stroke-dasharray: 3 3; subgraph unione02[" Union "] subgraph unione02l[" "] style unione02l fill:#abf,stroke-dasharray: 3 3; e0v1 --"wdt:P103"--> e0v4 e0v4 --"wdt:P279"--> e0v2 end subgraph unione02r[" "] style unione02r fill:#abf,stroke-dasharray: 3 3; e0v1 --"wdt:P1412"--> e0v3 e0v3 --"wdt:P279"--> e0v2 end unione02r <== or ==> unione02l end end subgraph unione01r[" "] style unione01r fill:#abf,stroke-dasharray: 3 3; e0v1 --"wdt:P103"--> e0v2 end unione01r <== or ==> unione01l end end subgraph unione00r[" "] style unione00r fill:#abf,stroke-dasharray: 3 3; e0v1 --"wdt:P1412"--> e0v2 end unione00r <== or ==> unione00l end e0v1("?author"):::projected e0v3("?knownlanguages"):::projected e0v4("?nativelanguage"):::projected e0v2("?worklang"):::projected end f0--EXISTS--> f0e0 f0 --> v1 f0 --> c1 f0 --> v2 f0 --> c2 f0 --> v3 f0 --> c3 f0 --> v4 subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; subgraph union1[" Union "] subgraph union1l[" "] style union1l fill:#abf,stroke-dasharray: 3 3; subgraph union2[" Union "] subgraph union2l[" "] style union2l fill:#abf,stroke-dasharray: 3 3; v1 --"wdt:P103"--> v4 v4 --"wdt:P279"--> v2 end subgraph union2r[" "] style union2r fill:#abf,stroke-dasharray: 3 3; v1 --"wdt:P1412"--> v3 v3 --"wdt:P279"--> v2 end union2r <== or ==> union2l end end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; v1 --"wdt:P103"--> v2 end union1r <== or ==> union1l end end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v1 --"wdt:P1412"--> v2 end union0r <== or ==> union0l end f1[["?what != 'wd:Q3331189'"]] f1 --> v5 v6 --"wdt:P31"--> a1 a1 --"wdt:P279"--> c6 v6 --"wdt:P31"--> v5 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v6 -."wdt:P571".-> v7 bind2[/"year-from-dateTime(?date)"/] v7 --o bind2 bind2 --as--o v8 end v6 --"wdt:P407"--> v2 v6 --"wdt:P50"--> v1 subgraph union3[" Union "] subgraph union3l[" "] style union3l fill:#abf,stroke-dasharray: 3 3; v1 --"wdt:P103"--> v4 end subgraph union3r[" "] style union3r fill:#abf,stroke-dasharray: 3 3; v1 --"wdt:P1412"--> v3 end union3r <== or ==> union3l end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c11 --"wikibase:language"--> c13 end