aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--python/fatcat_tools/references.py4
-rw-r--r--python/fatcat_web/ref_routes.py26
-rw-r--r--python/fatcat_web/templates/refs_macros.html20
-rw-r--r--python/fatcat_web/templates/wikipedia_view_fuzzy_refs.html27
4 files changed, 69 insertions, 8 deletions
diff --git a/python/fatcat_tools/references.py b/python/fatcat_tools/references.py
index 81b55f41..508cf19d 100644
--- a/python/fatcat_tools/references.py
+++ b/python/fatcat_tools/references.py
@@ -289,8 +289,8 @@ def enrich_inbound_refs(refs: List[BiblioRef], fatcat_api_client: Any, hide: Opt
release = fatcat_api_client.get_release(ref.source_release_ident, hide=hide, expand=expand)
access = release_access_options(release)
if ref.source_wikipedia_article:
- wiki_lang = ref.source_wikipedia.split(':')[0]
- wiki_article = ':'.join(ref.source_wikipedia.split(':')[1:])
+ wiki_lang = ref.source_wikipedia_article.split(':')[0]
+ wiki_article = ':'.join(ref.source_wikipedia_article.split(':')[1:]).replace(' ', '_')
access.append(AccessOption(
access_type="wikipedia",
access_url=f"https://{wiki_lang}.wikipedia.org/wiki/{wiki_article}",
diff --git a/python/fatcat_web/ref_routes.py b/python/fatcat_web/ref_routes.py
index 6f887c4d..88ac0744 100644
--- a/python/fatcat_web/ref_routes.py
+++ b/python/fatcat_web/ref_routes.py
@@ -15,7 +15,7 @@ from fatcat_web.cors import crossdomain
from fatcat_web.forms import *
from fatcat_web.entity_helpers import *
-def _refs_web(direction, release_ident=None, work_ident=None, openlibrary_id=None) -> RefHits:
+def _refs_web(direction, release_ident=None, work_ident=None, openlibrary_id=None, wikipedia_article=None) -> RefHits:
offset = request.args.get('offset', '0')
offset = max(0, int(offset)) if offset.isnumeric() else 0
limit = request.args.get('limit', '30')
@@ -37,6 +37,7 @@ def _refs_web(direction, release_ident=None, work_ident=None, openlibrary_id=Non
elif direction == "out":
hits = get_outbound_refs(
release_ident=release_ident,
+ wikipedia_article=wikipedia_article,
work_ident=work_ident,
es_client=app.es_client,
offset=offset,
@@ -74,12 +75,23 @@ def release_view_refs_outbound(ident):
@app.route('/openlibrary/OL<int:id_num>W/refs-in', methods=['GET'])
def openlibrary_view_refs_inbound(id_num):
if request.accept_mimetypes.best == "application/json":
- return openlibrary_view_refs_inbound(id_num)
+ return openlibrary_view_refs_inbound_json(id_num)
openlibrary_id = f"OL{id_num}W"
hits = _refs_web("in", openlibrary_id=openlibrary_id)
return render_template('openlibrary_view_fuzzy_refs.html', openlibrary_id=openlibrary_id, direction="in", hits=hits), 200
+@app.route('/wikipedia/<string(length=2):wiki_lang>:<string:wiki_article>/refs-out', methods=['GET'])
+def wikipedia_view_refs_outbound(wiki_lang: str, wiki_article: str):
+ if request.accept_mimetypes.best == "application/json":
+ return wikipedia_view_refs_outbound_json(wiki_lang, wiki_article)
+
+ wiki_url = f"https://{wiki_lang}.wikipedia.org/wiki/{wiki_article}"
+ wiki_article = wiki_article.replace('_', ' ')
+ wikipedia_article = wiki_lang + ":" + wiki_article
+ hits = _refs_web("out", wikipedia_article=wikipedia_article)
+ return render_template('wikipedia_view_fuzzy_refs.html', wiki_article=wiki_article, wiki_lang=wiki_lang, wiki_url=wiki_url, direction="out", hits=hits), 200
+
@app.route('/reference/match', methods=['GET', 'POST'])
def reference_match():
@@ -140,9 +152,17 @@ def release_view_refs_inbound_json(ident):
hits = _refs_web("in", release_ident=ident)
return Response(hits.json(exclude_unset=True), mimetype="application/json")
-@app.route('/openlibrary/OL<int:id_num>W/refs-in', methods=['GET', 'OPTIONS'])
+@app.route('/openlibrary/OL<int:id_num>W/refs-in.json', methods=['GET', 'OPTIONS'])
@crossdomain(origin='*',headers=['access-control-allow-origin','Content-Type'])
def openlibrary_view_refs_inbound_json(ident):
openlibrary_id = f"OL{id_num}W"
hits = _refs_web("in", openlibrary_id=openlibrary_id)
return Response(hits.json(exclude_unset=True), mimetype="application/json")
+
+@app.route('/wikipedia/<string(length=2):wiki_lang>:<string:wiki_article>/refs-out.json', methods=['GET', 'OPTIONS'])
+@crossdomain(origin='*',headers=['access-control-allow-origin','Content-Type'])
+def wikipedia_view_refs_outbound_json(wiki_lang: str, wiki_article: str):
+ wiki_article = wiki_article.replace('_', ' ')
+ wikipedia_article = wiki_lang + ":" + wiki_article
+ hits = _refs_web("out", wikipedia_article=wikipedia_article)
+ return Response(hits.json(exclude_unset=True), mimetype="application/json")
diff --git a/python/fatcat_web/templates/refs_macros.html b/python/fatcat_web/templates/refs_macros.html
index 405aca73..ba4d18ad 100644
--- a/python/fatcat_web/templates/refs_macros.html
+++ b/python/fatcat_web/templates/refs_macros.html
@@ -35,12 +35,26 @@
<td class="">
{% if release %}
{{ entity_macros.release_summary(release) }}
- {% elif row.ref.target_unstructured %}
+ {% elif direction == "in" and row.ref.source_wikipedia_article %}
+ {% set wiki_lang = row.ref.source_wikipedia_article.split(':')[0] %}
+ {% set wiki_article = ':'.join(row.ref.source_wikipedia_article.split(':')[1:]) %}
+ <b>
+ <a href="https://{{ wiki_lang }}.wikipedia.org/wiki/{{ wiki_article.replace(' ', '_') }}">
+ {{ wiki_article }}
+ </a>
+ [wikipedia]
+ </b>
+ <br>
+ <span style="color:green;">lang:{{ wiki_lang }}</span>&nbsp;
+ <a href="/wikipedia/{{ wiki_lang }}:{{ wiki_article.replace(' ', '_') }}/refs-out" style="color:green;">[references]</a>&nbsp;
+ {% elif direction == "out" and row.ref.target_unstructured %}
<code>{{ row.ref.target_unstructured }}</code>
{% if row.ref.target_openlibrary_work %}
- <br><a href="https://openlibrary.org/{{ row.ref.target_openlibrary_work }}" style="color:green;">openlibrary:{{ row.ref.target_openlibrary_work }}</a>&nbsp;
+ <br>
+ <a href="https://openlibrary.org/{{ row.ref.target_openlibrary_work }}" style="color:green;">openlibrary:{{ row.ref.target_openlibrary_work }}</a>&nbsp;
+ <a href="/openlibrary/{{ row.ref.target_openlibrary_work}}/refs-in" style="color:green;">[cited-by]</a>&nbsp;
{% endif %}
- {% elif row.ref.target_csl %}
+ {% elif direction == "in" and row.ref.target_csl %}
{{ entity_macros.csl_summary(row.ref.target_csl) }}
{% else %}
<i>blank</i>
diff --git a/python/fatcat_web/templates/wikipedia_view_fuzzy_refs.html b/python/fatcat_web/templates/wikipedia_view_fuzzy_refs.html
new file mode 100644
index 00000000..5b53d692
--- /dev/null
+++ b/python/fatcat_web/templates/wikipedia_view_fuzzy_refs.html
@@ -0,0 +1,27 @@
+{% extends "base.html" %}
+{% import "refs_macros.html" as refs_macros %}
+
+{% block title %}Wikipedia Refs{% endblock %}
+
+{% block fullbody %}
+<h1 class="ui header">
+ [{{ wiki_lang }}] {{ wiki_article }}
+ <span class="sub header"><a href="{{ wiki_url }}"><code>{{ wiki_url }}</code></a></span>
+</h1>
+
+{% if direction == "in" %}
+ <h3>Cited By</h3>
+ <p>This page lists references to a wikipedia article, from other works (eg, journal articles).
+{% elif direction == "out" %}
+ <h3>References</h3>
+ <i>Refernces from wikipedia article to other entities.</i>
+{% endif %}
+
+{% if hits.result_refs %}
+ {{ refs_macros.refs_table(hits, direction) }}
+{% else %}
+ <br><br><p><b>None found</b>
+{% endif %}
+
+{% endblock %}
+