Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WikiProject aspect #2289

Merged
merged 9 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions scholia/app/templates/wikiproject.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{% extends "base.html" %}

{% set aspect = 'wikiproject' %}

{% block in_ready %}

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

{% if main_subject %}
{{ 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') }}
{% endif %}


var url = 'https://www.wikidata.org/w/api.php?action=wbgetentities&ids=' +
'{{ main_subject }}' +
'&format=json&callback=?';

$.getJSON(url, function (data) {
var item = data.entities["{{ main_subject }}"];
if ('en' in item.labels) {
$("#main-subject").append(': <a href="/topic/{{ main_subject }}">' + item.labels.en.value + '</a>');
carlinmack marked this conversation as resolved.
Show resolved Hide resolved
$("#main-subject").append(' (<a href="https://www.wikidata.org/wiki/{{ main_subject }}">{{ main_subject }}</a>)');
} else {
$("#main-subject").append(': <a href="https://www.wikidata.org/wiki/{{ main_subject }}">{{ main_subject }}</a>');
$("#main-subject").append(' (<a href="/topic/{{ main_subject }}">Topic</a>)');
}
});

{% 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>

{% if main_subject %}

<h2 id="main-subject">Main subject</h2>

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

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

<h3 id="recently-published-works">Recently published works on the topic <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 on the topic</h3>

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

<h3 id="authors">Authors publishing about the topic</h3>

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

<h3 id="author-awards">Awards received by authors who published on the topic</h3>

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

<h3 id="topics">Co-occurring topics</h3>

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

<h3 id="venues">Venues and series publishing works about the topic</h3>

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

<h3 id="organization-map">Map of organizations associated with works about the topic</h3>

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>
{% endif %}

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

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:P921 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)
32 changes: 32 additions & 0 deletions scholia/app/templates/wikiproject_authors.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#defaultView:Table

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

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:P921/wdt:P31*/wdt:P279* target: . }
UNION
{ ?work wdt:P921/wdt:P361+ target: . }
UNION
{ ?work wdt:P921/wdt:P1269+ 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 "en,da,de,es,fr,jp,nl,no,ru,sv,zh" . }
}
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/{{ main_subject }}>
#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". }
}
33 changes: 33 additions & 0 deletions scholia/app/templates/wikiproject_earliest-published-works.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
PREFIX target: <http://www.wikidata.org/entity/{{ main_subject }}>

SELECT ?date ?work ?workLabel (CONCAT("/work/", SUBSTR(STR(?work), 32)) AS ?workUrl)
?topicsUrl ?topics
WITH {
SELECT DISTINCT ?work WHERE {
?work wdt:P921 / (wdt:P361+ | wdt:P1269+ | (wdt:P31* / wdt:P279*) ) 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 "en,da,de,es,fr,jp,nl,no,ru,sv,zh". }
}
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)
34 changes: 34 additions & 0 deletions scholia/app/templates/wikiproject_organization-map.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#defaultView:Map

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

SELECT ?organization ?organizationLabel ?geo ?count ?layer
WITH {
SELECT DISTINCT ?work WHERE {
# Works on the topic
?work wdt:P921 / (wdt:P361+ | wdt:P1269+ | (wdt:P31* / wdt:P279*) ) target: .
}
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)
54 changes: 54 additions & 0 deletions scholia/app/templates/wikiproject_publications-per-year.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#defaultView:BarChart

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

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:P921 / (wdt:P31*/wdt:P279* | wdt:P361+ | wdt:P1269+) 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