Skip to content

Commit

Permalink
Remove use of main subject, tidy, add auto_lang
Browse files Browse the repository at this point in the history
  • Loading branch information
carlinmack committed Jun 28, 2023
1 parent a0fdc7f commit a032000
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 65 deletions.
45 changes: 14 additions & 31 deletions scholia/app/templates/wikiproject.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
{{ 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') }}
Expand All @@ -17,23 +16,6 @@
{{ 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>');
$("#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 %}

Expand All @@ -53,17 +35,15 @@ <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>
<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>

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

Expand All @@ -75,27 +55,31 @@ <h3 id="publications-per-year">Publications per year</h3>
<iframe class="embed-responsive-item" id="publications-per-year-iframe"></iframe>
</div>

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

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

<h3 id="authors">Authors publishing about the topic</h3>
<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 who published on the topic</h3>
<h3 id="author-awards">Awards received by authors</h3>

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

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

<p>From random sample</p>

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

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

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

<h3 id="organization-map">Map of organizations associated with works about the topic</h3>
<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).
Expand All @@ -104,6 +88,5 @@ <h3 id="organization-map">Map of organizations associated with works about the t
<iframe class="embed-responsive-item" id="organization-map-iframe">
</iframe>
</div>
{% endif %}

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

SELECT ?count
?award ?awardLabel (CONCAT("/award/", SUBSTR(STR(?award), 32)) AS ?awardUrl)
Expand All @@ -11,7 +11,9 @@ WITH {
{
SELECT DISTINCT ?researcher ?award WHERE {
hint:Query hint:optimizer "None" .
?work wdt:P921 target: .
{ ?work wdt:P6104 target: .}
union
{ ?work wdt:P5008 target: .}
?work wdt:P50 ?researcher .
?researcher wdt:P166 ?award .
}
Expand Down
12 changes: 5 additions & 7 deletions scholia/app/templates/wikiproject_authors.sparql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#defaultView:Table

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

SELECT
?count
Expand All @@ -11,11 +11,9 @@ WITH {
?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:P6104 target: .}
union
{ ?work wdt:P5008 target: .}
?work wdt:P50 ?author .
}
GROUP BY ?author
Expand All @@ -27,6 +25,6 @@ WHERE {

# 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" . }
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
}
ORDER BY DESC(?count)
2 changes: 1 addition & 1 deletion scholia/app/templates/wikiproject_context.sparql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PREFIX target: <http://www.wikidata.org/entity/{{ main_subject }}>
PREFIX target: <http://www.wikidata.org/entity/{{ q }}>
#defaultView:Graph
SELECT ?node ?nodeLabel ?nodeImage ?childNode ?childNodeLabel ?childNodeImage ?rgb
WITH {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
PREFIX target: <http://www.wikidata.org/entity/{{ main_subject }}>
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:P921 / (wdt:P361+ | wdt:P1269+ | (wdt:P31* / wdt:P279*) ) target: .
{ ?work wdt:P6104 target: .}
union
{ ?work wdt:P5008 target: .}
}
} AS %works
WITH {
Expand All @@ -26,7 +28,7 @@ WHERE {
# 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". }
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
}
GROUP BY ?date ?work ?workLabel ?topicsUrl ?topics
ORDER BY ASC(?date)
Expand Down
7 changes: 5 additions & 2 deletions scholia/app/templates/wikiproject_organization-map.sparql
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#defaultView:Map

PREFIX target: <http://www.wikidata.org/entity/{{ main_subject }}>
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:P921 / (wdt:P361+ | wdt:P1269+ | (wdt:P31* / wdt:P279*) ) target: .
{ ?work wdt:P6104 target: .}
union
{ ?work wdt:P5008 target: .}
?work wdt:P50 [].
}
LIMIT 20000
} AS %works
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#defaultView:BarChart

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

SELECT
(STR(?year_) AS ?year)
Expand All @@ -13,7 +13,9 @@ WITH {
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:P6104 target: .}
union
{ ?work wdt:P5008 target: .}
?work wdt:P577 ?dates .
BIND(YEAR(?dates) AS ?years) .

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
PREFIX target: <http://www.wikidata.org/entity/{{ main_subject }}>
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:P921 / (wdt:P361+ | wdt:P1269+ | (wdt:P31* / wdt:P279*) ) target: .
{ ?work wdt:P6104 target: .}
union
{ ?work wdt:P5008 target: .}
}
} AS %works
WITH {
Expand All @@ -25,7 +27,7 @@ WHERE {
# 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". }
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
GROUP BY ?date ?work ?workLabel ?topicsUrl ?topics
ORDER BY DESC(?date)
Expand Down
8 changes: 5 additions & 3 deletions scholia/app/templates/wikiproject_topics.sparql
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#defaultView:Table

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

SELECT ?count (CONCAT("/topics/{{ q }},", SUBSTR(STR(?topic), 32)) AS ?countUrl)
?topic ?topicLabel (CONCAT("/topic/", SUBSTR(STR(?topic), 32)) AS ?topicUrl)
?example_work ?example_workLabel (CONCAT("/work/", SUBSTR(STR(?example_work), 32)) AS ?example_workUrl)
WITH {
SELECT (COUNT(?work) AS ?count) ?topic (SAMPLE(?work) AS ?example_work) WHERE {
# Find works for the specific queried topic
?work wdt:P921/( wdt:P31*/wdt:P279* | wdt:P361+ | wdt:P1269+) target: .
VALUES ?p { wdt:P6104 wdt:P5008 }
# Find works for the specific queried topic
SERVICE bd:sample { ?work ?p target: . bd:serviceParam bd:sample.limit 10000 }

# Find co-occuring topics
?work wdt:P921 ?topic .
Expand All @@ -21,6 +23,6 @@ WITH {
WHERE {
# Label the results
INCLUDE %result
SERVICE wikibase:label { bd:serviceParam wikibase:language "en,da,de,es,fr,jp,nl,no,ru,sv,zh" . }
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
}
ORDER BY DESC(?count)
9 changes: 4 additions & 5 deletions scholia/app/templates/wikiproject_venues.sparql
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
#defaultView:Table

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

SELECT ?count ?short_name
?venue ?venueLabel (CONCAT("/venue/", SUBSTR(STR(?venue), 32)) AS ?venueUrl)
WITH {
SELECT (count(?work) as ?count) ?venue (SAMPLE(?short_name_) AS ?short_name) 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:P6104 target: . }
union { ?work wdt:P5008 target: . }
?work wdt:P1433/wdt:P179* ?venue .
OPTIONAL { ?venue wdt:P1813 ?short_name_ . }
}
GROUP BY ?venue
} AS %result
WHERE {
INCLUDE %result
SERVICE wikibase:label { bd:serviceParam wikibase:language "en,da,de,es,fr,jp,nl,no,ru,sv,zh" . }
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
}
ORDER BY DESC(?count)
LIMIT 200
3 changes: 1 addition & 2 deletions scholia/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2480,8 +2480,7 @@ def show_wikiproject(q):
Rendered HTML page for specific WikiProject.
"""
main_subject = get_prop_value(q, "P921")
return render_template('wikiproject.html', q=q, main_subject=main_subject)
return render_template('wikiproject.html', q=q)


@main.route('/favicon.ico')
Expand Down
7 changes: 3 additions & 4 deletions scholia/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def identifier_to_qs(property, identifier):
Notes
-----
The Wikidata Query Service is queries to resolve the given identifier. If
The Wikidata Query Service is queried to resolve the given identifier. If
an error happens an empty list is returned.
Examples
Expand Down Expand Up @@ -296,7 +296,7 @@ def identifier_to_qs(property, identifier):


def get_prop_value(q, prop):
"""Given Q and P, return value (which is a Wikidata item)
"""Given Q and P, return value (which is a Wikidata item).
Parameters
----------
Expand All @@ -312,7 +312,7 @@ def get_prop_value(q, prop):
Notes
-----
The Wikidata Query Service is queries to resolve the given identifier. If
The Wikidata Query Service is queried to resolve the given identifier. If
an error happens an empty string is returned.
Examples
Expand All @@ -328,7 +328,6 @@ def get_prop_value(q, prop):
q=q,
prop=prop,
)
print(query)

url = 'https://query.wikidata.org/sparql'
params = {'query': query, 'format': 'json'}
Expand Down

0 comments on commit a032000

Please sign in to comment.