sparql-examples

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

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

247

rq turtle/ttl

Work aspect: list of authors

Use at

PREFIX p: <http://www.wikidata.org/prop/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX schema: <http://schema.org/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://wikidata.org/entity/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX target: <http://www.wikidata.org/entity/Q28942417>

# List of authors for a work
SELECT DISTINCT
  # Author order
  ?order

  ?academic_age

  # Author item and label
  ?author ?authorUrl ?authorDescription

WHERE {
  {
    target: p:P50 ?author_statement .
    ?author_statement ps:P50 ?author_ .
    ?author_ rdfs:label ?author .
    FILTER (LANG(?author) = 'en')
    BIND(CONCAT("../author/", SUBSTR(STR(?author_), 32)) AS ?authorUrl)
    OPTIONAL {
      ?author_statement pq:P1545 ?order_ .
      BIND(xsd:integer(?order_) AS ?order)
    }
    OPTIONAL {
      ?author_ schema:description ?authorDescription .
      FILTER (LANG(?authorDescription) = "en")
    }
  }
  UNION
  {
    target: p:P2093 ?authorstring_statement .
    ?authorstring_statement ps:P2093 ?author_
    BIND(CONCAT(?author_, " ↗") AS ?author)
    OPTIONAL {
      ?authorstring_statement pq:P1545 ?order_ .
      BIND(xsd:integer(?order_) AS ?order)
    }
    BIND(CONCAT("https://author-disambiguator.toolforge.org/names_oauth.php?doit=Look+for+author&name=", ENCODE_FOR_URI(?author_)) AS ?authorUrl)
  }
  OPTIONAL {
    SELECT ?author_ (MAX(?academic_age_) AS ?academic_age) {
      target: wdt:P50 ?author_ ;
                 wdt:P577 ?publication_date .
      [] wdt:P31 / wdt:P279* wd:Q55915575 ;
         wdt:P50 ?author_ ;
         wdt:P577 ?other_publication_date .
      BIND(YEAR(?publication_date) - YEAR(?other_publication_date) AS ?academic_age_)
    }
    GROUP BY ?author_
  }
}
ORDER BY ?order
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v12("?academic_age"):::projected 
  v11("?academic_age_")
  v9("?author"):::projected 
  v2("?authorDescription"):::projected 
  v9("?authorUrl"):::projected 
  v5("?author_")
  v4("?author_statement")
  v8("?authorstring_statement")
  v9("?order"):::projected 
  v7("?order_")
  v10("?other_publication_date")
  v9("?publication_date")
  a1((" "))
  a2((" "))
  c2(["wd:Q28942417"]):::iri 
  c14([http://wikidata.org/entity/Q55915575]):::iri 
  subgraph union0[" Union "]
  subgraph union0l[" "]
    style union0l fill:#abf,stroke-dasharray: 3 3;
    c2 --"p:P2093"-->  v8
    v8 --"p:statement/P2093"-->  v5
    bind0[/"concat(?author_,' ↗')"/]
    v5 --o bind0
    bind0 --as--o v9
    subgraph optional0["(optional)"]
    style optional0 fill:#bbf,stroke-dasharray: 5 5;
      v8 -."p:qualifier/P1545".->  v7
      bind1[/"http://www.w3.org/2001/XMLSchema#integer(?order_)"/]
      v7 --o bind1
      bind1 --as--o v9
    end
    bind2[/"concat('https://author-disambiguator.toolforge.org/names_oauth.php?doit=Look+for+author&name=',encode-for-uri(?author_))"/]
    v5 --o bind2
    bind2 --as--o v9
  end
  subgraph union0r[" "]
    style union0r fill:#abf,stroke-dasharray: 3 3;
    f3[["?author = 'en'"]]
    f3 --> v9
    c2 --"p:P50"-->  v4
    v4 --"p:statement/P50"-->  v5
    v5 --"rdfs:label"-->  v9
    bind4[/"concat('../author/',substring(str(?author_),'32^^xsd:integer'))"/]
    v5 --o bind4
    bind4 --as--o v9
    subgraph optional1["(optional)"]
    style optional1 fill:#bbf,stroke-dasharray: 5 5;
      v4 -."p:qualifier/P1545".->  v7
      bind5[/"http://www.w3.org/2001/XMLSchema#integer(?order_)"/]
      v7 --o bind5
      bind5 --as--o v9
    end
    subgraph optional2["(optional)"]
    style optional2 fill:#bbf,stroke-dasharray: 5 5;
      v5 -."schema:description".->  v2
    end
  end
  union0r <== or ==> union0l
  end
  subgraph optional3["(optional)"]
  style optional3 fill:#bbf,stroke-dasharray: 5 5;
    c2 -."p:direct/P50".->  v5
    c2 --"p:direct/P577"-->  v9
    a1 --"p:direct/P31"-->  a2
    a2 --"p:direct/P279"-->  c14
    a1 --"p:direct/P50"-->  v5
    a1 --"p:direct/P577"-->  v10
    bind6[/"year-from-dateTime(?publication_date) - year-from-dateTime(?other_publication_date)"/]
    v9 --o bind6
    v10 --o bind6
    bind6 --as--o v11
    bind8[/"max(?academic_age_)"/]
    v11 --o bind8
    bind8 --as--o v12
  end