sparql-examples

A set of SPARQL examples that are used in different TGX resources

View the Project on GitHub BiGCAT-UM/sparql-examples

008

rq turtle/ttl

Author aspect: list of retracted articles

Use at

PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://wikidata.org/entity/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
#defaultView:Table
PREFIX target: <http://www.wikidata.org/entity/Q97270>

SELECT
  (MIN(?dates) AS ?date)
  ?work ?workLabel
  (GROUP_CONCAT(DISTINCT ?type_label; separator=", ") AS ?type)
  (SAMPLE(?pages_) AS ?pages)
  ?venue ?venueLabel
  (GROUP_CONCAT(DISTINCT ?author_label; separator=", ") AS ?authors)
  (CONCAT("../authors/", GROUP_CONCAT(DISTINCT SUBSTR(STR(?author), 32); separator=",")) AS ?authorsUrl)
WHERE {
  ?work wdt:P50 target: .
  ?work wdt:P50 ?author .
  { ?work wdt:P31 wd:Q45182324 } UNION { ?work wdt:P793 wd:Q7316896 . } UNION { ?work wdt:P5824 [] . }
  OPTIONAL {
    ?author rdfs:label ?author_label_ . FILTER (LANG(?author_label_) = 'en')
  }
  BIND(COALESCE(?author_label_, SUBSTR(STR(?author), 32)) AS ?author_label)
  OPTIONAL { ?work wdt:P31 ?type_ . ?type_ rdfs:label ?type_label . FILTER (LANG(?type_label) = 'en') }
  ?work wdt:P577 ?datetimes .
  BIND(xsd:date(?datetimes) AS ?dates)
  OPTIONAL { ?work wdt:P1104 ?pages_ }
  OPTIONAL { ?work wdt:P1433 ?venue }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en" . }
}
GROUP BY ?work ?workLabel ?venue ?venueLabel
ORDER BY DESC(?date)

graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v5("?author")
  v6("?author_label"):::projected 
  v3("?author_label_")
  v14("?authors")
  v15("?authorsUrl")
  v12("?date")
  v9("?dates"):::projected 
  v8("?datetimes")
  v13("?pages")
  v10("?pages_"):::projected 
  v12("?type")
  v7("?type_")
  v2("?type_label"):::projected 
  v11("?venue"):::projected 
  v4("?work"):::projected 
  a1((" "))
  c7([http://wikidata.org/entity/Q7316896]):::iri 
  c3(["wd:Q97270"]):::iri 
  c5([http://wikidata.org/entity/Q45182324]):::iri 
  c16(["#91;AUTO_LANGUAGE#93;,mul,en"]):::literal 
  c14([http://www.bigdata.com/rdf#serviceParam]):::iri 
  v4 --"p:direct/P50"-->  c3
  v4 --"p:direct/P50"-->  v5
  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;
      v4 --"p:direct/P5824"-->  a1
    end
    subgraph union1r[" "]
      style union1r fill:#abf,stroke-dasharray: 3 3;
      v4 --"p:direct/P793"-->  c7
    end
    union1r <== or ==> union1l
    end
  end
  subgraph union0r[" "]
    style union0r fill:#abf,stroke-dasharray: 3 3;
    v4 --"p:direct/P31"-->  c5
  end
  union0r <== or ==> union0l
  end
  subgraph optional0["(optional)"]
  style optional0 fill:#bbf,stroke-dasharray: 5 5;
    v5 -."rdfs:label".->  v3
  end
  bind0[/"?author_label_substring(str(?author),'32^^xsd:integer')"/]
  v3 --o bind0
  v5 --o bind0
  bind0 --as--o v6
  subgraph optional1["(optional)"]
  style optional1 fill:#bbf,stroke-dasharray: 5 5;
    v4 -."p:direct/P31".->  v7
    v7 --"rdfs:label"-->  v2
  end
  v4 --"p:direct/P577"-->  v8
  bind1[/"http://www.w3.org/2001/XMLSchema#date(?datetimes)"/]
  v8 --o bind1
  bind1 --as--o v9
  subgraph optional2["(optional)"]
  style optional2 fill:#bbf,stroke-dasharray: 5 5;
    v4 -."p:direct/P1104".->  v10
  end
  subgraph optional3["(optional)"]
  style optional3 fill:#bbf,stroke-dasharray: 5 5;
    v4 -."p:direct/P1433".->  v11
  end
  subgraph s1["http://wikiba.se/ontology#label"]
    style s1 stroke-width:4px;
    c14 --"wikibase:language"-->  c16
  end
  bind7[/"min(?dates)"/]
  v9 --o bind7
  bind7 --as--o v12
  bind8[/"?type_label"/]
  v2 --o bind8
  bind8 --as--o v12
  bind9[/"sample(?pages_)"/]
  v10 --o bind9
  bind9 --as--o v13
  bind10[/"?author_label"/]
  v6 --o bind10
  bind10 --as--o v14
  bind11[/"concat('../authors/',)"/]
  null --o bind11
  bind11 --as--o v15