sparql-examples

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

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

240

rq turtle/ttl

Work aspect: citations per year

Use at

PREFIX p: <http://www.wikidata.org/prop/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
#defaultView:BarChart

PREFIX target: <http://www.wikidata.org/entity/Q28942417>

SELECT
  (STR(?year_) AS ?year)
  (SUM(?count_) AS ?count)
  ?kind
WHERE {
  {
    VALUES ?year_ { 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013
                    2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 }
    BIND(0 AS ?count_)
    BIND("_" AS ?kind)
  }
  UNION 
  {
    SELECT
      ?year_
      (COUNT(DISTINCT ?citing_work) AS ?count_)
      ?kind
    WHERE {
      ?citing_work wdt:P2860 target: .
  
      # Detect self-citations
      BIND(IF(EXISTS { target: wdt:P50 ?selfauthor . ?citing_work  wdt:P50 ?selfauthor } ,
        "detected incoming self-citations",
        "citations from others or non-detected self-citations") AS ?kind)

      # Year of citation
      ?citing_work wdt:P577 ?date .
      BIND(YEAR(?date) AS ?year_)
    }
    GROUP BY ?year_ ?kind
  }
  UNION 
  {
    SELECT
      ?year_
      (COUNT(DISTINCT ?cited_work) AS ?count_)
      ?kind
    WHERE {
      target: wdt:P2860 ?cited_work .
  
      # Detect self-citations
      BIND(IF(EXISTS { ?cited_work wdt:P50 ?selfauthor . target: wdt:P50 ?selfauthor },
        "detected outgoing self-citations",
        "outgoing citations to others or non-detected self-citations") AS ?kind)

      # Year of citation
      ?cited_work wdt:P577 ?date .
      BIND(YEAR(?date) AS ?year_)
    }
    GROUP BY ?year_ ?kind
  }
}
GROUP BY ?year_ ?kind
ORDER BY DESC(?year_)

graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v6("?cited_work")
  v4("?citing_work")
  v8("?count")
  v7("?count_"):::projected 
  v5("?date")
  v7("?kind"):::projected 
  v7("?year")
  v7("?year_"):::projected 
  c2([http://www.wikidata.org/entity/Q28942417]):::iri 
  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;
      c2 --"p:direct/P2860"-->  v6
      v6 --"p:direct/P50"-->  null
      c2 --"p:direct/P50"-->  null
      bind0[/"if( ,'detected outgoing self-citations','outgoing citations to others or non-detected self-citations')"/]
      subgraph bind0e0["Exists Clause"]
        e0v1 --"p:direct/P50"-->  e0v2
        e0c2 --"p:direct/P50"-->  e0v2
        e0v1("?cited_work"):::projected 
        e0v2("?selfauthor"):::projected 
        e0c2([http://www.wikidata.org/entity/Q28942417]):::iri 
      end
      bind0--EXISTS--> bind0e0
      v6 --o bind0
      null --o bind0
      null --o bind0
      c2 --o bind0
      bind0 --as--o v7
      v6 --"p:direct/P577"-->  v5
      bind1[/"year-from-dateTime(?date)"/]
      v5 --o bind1
      bind1 --as--o v7
      bind3[/"count(?cited_work)"/]
      v6 --o bind3
      bind3 --as--o v7
    end
    subgraph union1r[" "]
      style union1r fill:#abf,stroke-dasharray: 3 3;
      v4 --"p:direct/P2860"-->  c2
      c2 --"p:direct/P50"-->  null
      v4 --"p:direct/P50"-->  null
      bind4[/"if( ,'detected incoming self-citations','citations from others or non-detected self-citations')"/]
      subgraph bind4e1["Exists Clause"]
        e1c1 --"p:direct/P50"-->  e1v1
        e1v2 --"p:direct/P50"-->  e1v1
        e1v2("?citing_work"):::projected 
        e1v1("?selfauthor"):::projected 
        e1c1([http://www.wikidata.org/entity/Q28942417]):::iri 
      end
      bind4--EXISTS--> bind4e1
      c2 --o bind4
      null --o bind4
      null --o bind4
      v4 --o bind4
      bind4 --as--o v7
      v4 --"p:direct/P577"-->  v5
      bind5[/"year-from-dateTime(?date)"/]
      v5 --o bind5
      bind5 --as--o v7
      bind7[/"count(?citing_work)"/]
      v4 --o bind7
      bind7 --as--o v7
    end
    union1r <== or ==> union1l
    end
  end
  subgraph union0r[" "]
    style union0r fill:#abf,stroke-dasharray: 3 3;
    bind8[/VALUES ?year_/]
    bind8-->v7
    bind80(["2004^^xsd:integer"])
    bind80 --> bind8
    bind81(["2005^^xsd:integer"])
    bind81 --> bind8
    bind82(["2006^^xsd:integer"])
    bind82 --> bind8
    bind83(["2007^^xsd:integer"])
    bind83 --> bind8
    bind84(["2008^^xsd:integer"])
    bind84 --> bind8
    bind85(["2009^^xsd:integer"])
    bind85 --> bind8
    bind86(["2010^^xsd:integer"])
    bind86 --> bind8
    bind87(["2011^^xsd:integer"])
    bind87 --> bind8
    bind88(["2012^^xsd:integer"])
    bind88 --> bind8
    bind89(["2013^^xsd:integer"])
    bind89 --> bind8
    bind810(["2014^^xsd:integer"])
    bind810 --> bind8
    bind811(["2015^^xsd:integer"])
    bind811 --> bind8
    bind812(["2016^^xsd:integer"])
    bind812 --> bind8
    bind813(["2017^^xsd:integer"])
    bind813 --> bind8
    bind814(["2018^^xsd:integer"])
    bind814 --> bind8
    bind815(["2019^^xsd:integer"])
    bind815 --> bind8
    bind816(["2020^^xsd:integer"])
    bind816 --> bind8
    bind817(["2021^^xsd:integer"])
    bind817 --> bind8
    bind818(["2022^^xsd:integer"])
    bind818 --> bind8
    bind819(["2023^^xsd:integer"])
    bind819 --> bind8
    bind9[/"'0^^xsd:integer'"/]
    bind9 --as--o v7
    bind10[/"'_'"/]
    bind10 --as--o v7
  end
  union0r <== or ==> union0l
  end
  bind12[/"str(?year_)"/]
  v7 --o bind12
  bind12 --as--o v7
  bind13[/"sum(?count_)"/]
  v7 --o bind13
  bind13 --as--o v8