sparql-examples

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

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

065

rq turtle/ttl

Dataset 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#>
# List of authors for a work
PREFIX target: <http://www.wikidata.org/entity/Q4203254>

SELECT DISTINCT
  # Author order
  ?order

  ?academic_age

  # Author item and label
  ?author ?authorUrl ?authorDescription
  
  ?orcid
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_ wdt:P496 ?orcid_ . }
    # Either show the ORCID iD or construct part of a URL to search on the ORCID homepage
    BIND(COALESCE(?orcid_, CONCAT("orcid-search/search/?searchQuery=", ENCODE_FOR_URI(?author))) AS ?orcid)
    OPTIONAL {
      ?author_ schema:description ?authorDescription .
      FILTER (LANG(?authorDescription) = "en")
    }
  }
  UNION
  {
    target: p:P2093 ?authorstring_statement .
    ?authorstring_statement ps:P2093 ?author_
    BIND(CONCAT("UNRESOLVED: ", ?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 wd:Q13442814 ;
         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;
  v14("?academic_age"):::projected 
  v13("?academic_age_")
  v11("?author"):::projected 
  v2("?authorDescription"):::projected 
  v11("?authorUrl"):::projected 
  v5("?author_")
  v4("?author_statement")
  v10("?authorstring_statement")
  v9("?orcid"):::projected 
  v8("?orcid_")
  v11("?order"):::projected 
  v7("?order_")
  v12("?other_publication_date")
  v11("?publication_date")
  a1((" "))
  c2(["wd:Q4203254"]):::iri 
  c14([http://wikidata.org/entity/Q13442814]):::iri 
  subgraph union0[" Union "]
  subgraph union0l[" "]
    style union0l fill:#abf,stroke-dasharray: 3 3;
    c2 --"p:P2093"-->  v10
    v10 --"p:statement/P2093"-->  v5
    bind0[/"concat('UNRESOLVED: ',?author_)"/]
    v5 --o bind0
    bind0 --as--o v11
    subgraph optional0["(optional)"]
    style optional0 fill:#bbf,stroke-dasharray: 5 5;
      v10 -."p:qualifier/P1545".->  v7
      bind1[/"http://www.w3.org/2001/XMLSchema#integer(?order_)"/]
      v7 --o bind1
      bind1 --as--o v11
    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 v11
  end
  subgraph union0r[" "]
    style union0r fill:#abf,stroke-dasharray: 3 3;
    f3[["?author = 'en'"]]
    f3 --> v11
    c2 --"p:P50"-->  v4
    v4 --"p:statement/P50"-->  v5
    v5 --"rdfs:label"-->  v11
    bind4[/"concat('../author/',substring(str(?author_),'32^^xsd:integer'))"/]
    v5 --o bind4
    bind4 --as--o v11
    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 v11
    end
    subgraph optional2["(optional)"]
    style optional2 fill:#bbf,stroke-dasharray: 5 5;
      v5 -."p:direct/P496".->  v8
    end
    bind6[/"?orcid_concat('orcid-search/search/?searchQuery=',encode-for-uri(?author))"/]
    v8 --o bind6
    v11 --o bind6
    bind6 --as--o v9
    subgraph optional3["(optional)"]
    style optional3 fill:#bbf,stroke-dasharray: 5 5;
      v5 -."schema:description".->  v2
    end
  end
  union0r <== or ==> union0l
  end
  subgraph optional4["(optional)"]
  style optional4 fill:#bbf,stroke-dasharray: 5 5;
    c2 -."p:direct/P50".->  v5
    c2 --"p:direct/P577"-->  v11
    a1 --"p:direct/P31"-->  c14
    a1 --"p:direct/P50"-->  v5
    a1 --"p:direct/P577"-->  v12
    bind7[/"year-from-dateTime(?publication_date) - year-from-dateTime(?other_publication_date)"/]
    v11 --o bind7
    v12 --o bind7
    bind7 --as--o v13
    bind9[/"max(?academic_age_)"/]
    v13 --o bind9
    bind9 --as--o v14
  end