Skip to content

Commit

Permalink
Merge branch 'carlinmack-wikiproject-aspect'
Browse files Browse the repository at this point in the history
  • Loading branch information
fnielsen committed Jun 30, 2023
2 parents e49dee5 + e2d8a7c commit 59db86c
Show file tree
Hide file tree
Showing 14 changed files with 466 additions and 2 deletions.
92 changes: 92 additions & 0 deletions scholia/app/templates/wikiproject.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{% extends "base.html" %}

{% set aspect = 'wikiproject' %}

{% block in_ready %}

{{ sparql_to_table("maintained") }}
{{ sparql_to_table("focus") }}

{{ sparql_to_iframe('context') }}
{{ sparql_to_table('recently-published-works') }}
{{ sparql_to_iframe('publications-per-year') }}
{{ sparql_to_table('earliest-published-works') }}
{{ sparql_to_table('authors') }}
{{ sparql_to_table('author-awards') }}
{{ sparql_to_table('topics') }}
{{ sparql_to_table('venues') }}
{{ sparql_to_iframe('organization-map') }}

{% endblock %}



{% block page_content %}

<h1 id="h1">WikiProject</h1>

<div id="intro"></div>

<h2 id="types">Types of items maintained by this WikiProject</h2>

<table class="table table-hover" id="maintained-table"></table>

<h2 id="focus">Types of items on focus list of this WikiProject</h2>

<table class="table table-hover" id="focus-table"></table>

<h2 id="context">The topic in context</h2>

<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" id="context-iframe"></iframe>
</div>

<h2 id="works">Works</h2>

<h3 id="recently-published-works">Recently published works<a
href="{{ url_for('app.show_topic_index') }}{{ q }}/latest-works/rss"><img height="24" width="48"
src="{{ url_for('static', filename='images/rss-40674_320.png') }}" alt="RSS icon" /></a></h3>

<table class="table table-hover" id="recently-published-works-table"></table>

<h3 id="publications-per-year">Publications per year</h3>

<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" id="publications-per-year-iframe"></iframe>
</div>

<h3 id="earliest-published-works">Earliest published works</h3>

<table class="table table-hover" id="earliest-published-works-table"></table>

<h2 id="authors-heading">Authors</h2>

<h3 id="authors">Related authors</h3>

<table class="table table-hover" id="authors-table"></table>

<h3 id="author-awards">Awards received by authors</h3>

<table class="table table-hover" id="author-awards-table"></table>

<h2 id="topics">Topics</h2>

<p>From random sample</p>

<table class="table table-hover" id="topics-table"></table>

<h2 id="venues">Related venues and series</h2>

<table class="table table-hover" id="venues-table"></table>

<h2 id="organization-map">Map of organizations associated with related works</h2>

The colours indicate how many publications on the topic are associated with organizations in the given location, as
detailed in the legend (top right).

<div class="embed-responsive embed-responsive-4by3">
<iframe class="embed-responsive-item" id="organization-map-iframe">
</iframe>
</div>

{% endblock %}
31 changes: 31 additions & 0 deletions scholia/app/templates/wikiproject_author-awards.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
PREFIX target: <http://www.wikidata.org/entity/{{ q }}>

SELECT ?count
?award ?awardLabel (CONCAT("/award/", SUBSTR(STR(?award), 32)) AS ?awardUrl)
?recipients ?recipientsUrl
WITH {
SELECT (COUNT(?researcher) AS ?count) ?award
(GROUP_CONCAT(DISTINCT ?researcher_label; separator=", ") AS ?recipients)
(CONCAT("../authors/", GROUP_CONCAT(DISTINCT SUBSTR(STR(?researcher), 32); separator=",")) AS ?recipientsUrl)
WHERE {
{
SELECT DISTINCT ?researcher ?award WHERE {
hint:Query hint:optimizer "None" .
{ ?work wdt:P6104 target: .}
union
{ ?work wdt:P5008 target: .}
?work wdt:P50 ?researcher .
?researcher wdt:P166 ?award .
}
LIMIT 100
}
?researcher rdfs:label ?researcher_label . FILTER (LANG(?researcher_label) = 'en')
}
GROUP BY ?award
} AS %result
WHERE {
INCLUDE %result
?award rdfs:label ?awardLabel . FILTER (LANG(?awardLabel) = 'en')
}
GROUP BY ?count ?award ?awardLabel ?recipients ?recipientsUrl
ORDER BY DESC(?count)
30 changes: 30 additions & 0 deletions scholia/app/templates/wikiproject_authors.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#defaultView:Table

PREFIX target: <http://www.wikidata.org/entity/{{ q }}>

SELECT
?count
?author ?authorLabel ?authorDescription (CONCAT("/author/", SUBSTR(STR(?author), 32)) AS ?authorUrl)
(COALESCE(?orcid_, CONCAT("orcid-search/quick-search/?searchQuery=", ?authorLabel)) AS ?orcid)
WITH {
SELECT
?author
(count(?work) as ?count)
WHERE {
{ ?work wdt:P6104 target: .}
union
{ ?work wdt:P5008 target: .}
?work wdt:P50 ?author .
}
GROUP BY ?author
ORDER BY DESC(?count)
LIMIT 200
} AS %result
WHERE {
INCLUDE %result

# Include optional ORCID iD
OPTIONAL { ?author wdt:P496 ?orcid_ . }
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
}
ORDER BY DESC(?count)
54 changes: 54 additions & 0 deletions scholia/app/templates/wikiproject_context.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
PREFIX target: <http://www.wikidata.org/entity/{{ q }}>
#defaultView:Graph
SELECT ?node ?nodeLabel ?nodeImage ?childNode ?childNodeLabel ?childNodeImage ?rgb
WITH {
SELECT DISTINCT ?property WHERE {
?property a wikibase:Property;
wdt:P31 wd:Q18610173 ;
wdt:P31 wd:Q26940804 .
}
} AS %properties
WITH {
SELECT DISTINCT ?node ?childNode WHERE {
BIND(target: AS ?node)
?node ?p ?i.
?childNode ?x ?p.
?childNode rdf:type wikibase:Property.
FILTER(STRSTARTS(STR(?i), "http://www.wikidata.org/entity/Q"))
FILTER(STRSTARTS(STR(?childNode), "http://www.wikidata.org/entity/P"))
}
LIMIT 5000
} AS %nodes
WITH {
SELECT DISTINCT ?childNode ?node ?rgb WHERE {
BIND("EFFBD8" AS ?rgb)
target: ?p ?childNode.
?node ?x ?p.
?node rdf:type wikibase:Property.
FILTER(STRSTARTS(STR(?childNode), "http://www.wikidata.org/entity/Q"))
}
LIMIT 5000
} AS %childNodes
WHERE {
{
INCLUDE %nodes
}
UNION
{
INCLUDE %childNodes
}

OPTIONAL {
INCLUDE %properties
?property wikibase:directClaim ?nodeclaim.
?node ?nodeclaim ?nodeImage.
}

OPTIONAL {
INCLUDE %properties
?property wikibase:directClaim ?childNodeclaim.
?childNode ?childNodeclaim ?childNodeImage.
}

SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
35 changes: 35 additions & 0 deletions scholia/app/templates/wikiproject_earliest-published-works.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
PREFIX target: <http://www.wikidata.org/entity/{{ q }}>

SELECT ?date ?work ?workLabel (CONCAT("/work/", SUBSTR(STR(?work), 32)) AS ?workUrl)
?topicsUrl ?topics
WITH {
SELECT DISTINCT ?work WHERE {
{ ?work wdt:P6104 target: .}
union
{ ?work wdt:P5008 target: .}
}
} AS %works
WITH {
SELECT (MAX(?dates) as ?datetime) ?work (GROUP_CONCAT(DISTINCT ?topic_label; separator=" // ") AS ?topics)
(CONCAT("../topics/", GROUP_CONCAT(DISTINCT SUBSTR(STR(?topic), 32); separator=",")) AS ?topicsUrl)
WHERE {
INCLUDE %works
?work wdt:P921 ?topic .
?work wdt:P577 ?dates .
FILTER (!isBLANK(?dates)) .
?topic rdfs:label ?topic_label . FILTER (lang(?topic_label) = 'en')
}
GROUP BY ?work
} AS %result
WHERE {
INCLUDE %result

# There is a problem with BC dates
# BIND(xsd:date(?datetime) AS ?date)
BIND(REPLACE(STR(?datetime), 'T.*', '') AS ?date)

SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
}
GROUP BY ?date ?work ?workLabel ?topicsUrl ?topics
ORDER BY ASC(?date)
LIMIT 500
13 changes: 13 additions & 0 deletions scholia/app/templates/wikiproject_focus.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
SELECT ?type ?typeLabel ?count WITH {
SELECT DISTINCT ?type (COUNT(?item) AS ?count) WHERE {
?item wdt:P5008 wd:{{ q }};
(wdt:P31|wdt:P279) ?type.
}
GROUP BY ?type ?count
ORDER BY DESC (?count)
} AS %result
WHERE {
INCLUDE %result
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,da,de,es,fr,it,sv,uk,zh". }
}
ORDER BY DESC (?count)
13 changes: 13 additions & 0 deletions scholia/app/templates/wikiproject_maintained.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
SELECT ?type ?typeLabel ?count WITH {
SELECT DISTINCT ?type (COUNT(?item) AS ?count) WHERE {
?item wdt:P6104 wd:{{ q }};
(wdt:P31|wdt:P279) ?type.
}
GROUP BY ?type ?count
ORDER BY DESC (?count)
} AS %result
WHERE {
INCLUDE %result
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,da,de,es,fr,it,sv,uk,zh". }
}
ORDER BY DESC (?count)
37 changes: 37 additions & 0 deletions scholia/app/templates/wikiproject_organization-map.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#defaultView:Map

PREFIX target: <http://www.wikidata.org/entity/{{ q }}>

SELECT ?organization ?organizationLabel ?geo ?count ?layer
WITH {
SELECT DISTINCT ?work WHERE {
# Works on the topic
{ ?work wdt:P6104 target: .}
union
{ ?work wdt:P5008 target: .}
?work wdt:P50 [].
}
LIMIT 20000
} AS %works
WITH {
SELECT DISTINCT ?organization ?geo (COUNT(DISTINCT ?work) AS ?count) WHERE {
INCLUDE %works
# Authors who have published works on the topic
?work wdt:P50 ?author .
?author ( wdt:P108 | wdt:P463 | wdt:P1416 ) / wdt:P361* ?organization .
# Use the headquarters location by default but keep the coordinate location as a fallback
OPTIONAL{?organization p:P159/pq:P625 ?hq_geo}
OPTIONAL{?organization wdt:P625 ?coord_geo}
BIND(IF(BOUND(?hq_geo), ?hq_geo, ?coord_geo) AS ?geo) .
FILTER(BOUND(?geo)) .
}
GROUP BY ?organization ?geo
ORDER BY DESC (?count)
LIMIT 2000
} AS %organizations
WHERE {
INCLUDE %organizations
BIND(IF( (?count < 1), "No results", IF((?count < 2), "1 result", IF((?count < 11), "1 < results ≤ 10", IF((?count < 101), "10 < results ≤ 100", IF((?count < 1001), "100 < results ≤ 1000", IF((?count < 10001), "1000 < results ≤ 10000", "10000 or more results") ) ) ) )) AS ?layer )
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY DESC (?count)
56 changes: 56 additions & 0 deletions scholia/app/templates/wikiproject_publications-per-year.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#defaultView:BarChart

PREFIX target: <http://www.wikidata.org/entity/{{ q }}>

SELECT
(STR(?year_) AS ?year)
(COUNT(?work) AS ?number_of_publications)

# Work type used to color the bar chart
?type
WITH {
# Find works with the topic. Also report the year
SELECT
?work (MIN(?years) AS ?year_) (1 AS ?dummy) (SAMPLE(?article_type_) AS ?article_type)
WHERE {
{ ?work wdt:P6104 target: .}
union
{ ?work wdt:P5008 target: .}
?work wdt:P577 ?dates .
BIND(YEAR(?dates) AS ?years) .

?work wdt:P31 ?article_type_ .
}
GROUP BY ?work
} AS %works
WITH {
SELECT ?year_ WHERE {
# default values = 0
?year_item wdt:P31 wd:Q577 .
?year_item wdt:P585 ?date .
BIND(YEAR(?date) AS ?year_)
}
} AS %default_counts
WITH {
# Find earliest publication year
SELECT (MIN(?year_) AS ?earliest_year) WHERE {
INCLUDE %works
}
GROUP BY ?dummy
} AS %earliest
WHERE {
{
INCLUDE %works
?article_type rdfs:label ?type . FILTER (LANG(?type) = "en")
}
UNION
{
INCLUDE %default_counts
BIND("_" AS ?type)
}
INCLUDE %earliest
BIND(YEAR(NOW()) AS ?this_year)
FILTER (?year_ >= ?earliest_year && ?year_ <= ?this_year && ?year_ >= YEAR("1900-01-01"^^xsd:dateTime))
}
GROUP BY ?year_ ?type
ORDER BY ?year
Loading

0 comments on commit 59db86c

Please sign in to comment.