From 1125eddcac0c9b2673dbfb1f62bb0fa9b1ab4054 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Fri, 23 Jul 2021 17:48:35 -0700 Subject: web: refactor refs table into separate refs_macros file --- python/fatcat_web/templates/refs_macros.html | 86 ++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 python/fatcat_web/templates/refs_macros.html (limited to 'python/fatcat_web/templates/refs_macros.html') diff --git a/python/fatcat_web/templates/refs_macros.html b/python/fatcat_web/templates/refs_macros.html new file mode 100644 index 00000000..405aca73 --- /dev/null +++ b/python/fatcat_web/templates/refs_macros.html @@ -0,0 +1,86 @@ +{% import "entity_macros.html" as entity_macros %} + +{% macro pagination_row(hits, direction) %} + + {% if hits.offset %} + « prev   + {% endif %} + Showing {{ hits.offset + 1 }} - {{ hits.offset + hits.count_returned }} of {{ hits.count_total}} references (in {{ hits.query_wall_time_ms }}ms) + {% if hits.count_total != hits.count_returned and hits.offset + hits.limit < hits.count_total %} +  next » + {% endif %} +{% endmacro %} + +{% macro refs_table(hits, direction) %} + + + + + +{% for row in hits.result_refs %} + {% set release = row.release %} + +{% if hits.count_total != hits.count_returned %} + + +{% endif %} +
+ {{ pagination_row(hits) }} +
+ {# TODO: ref_locator? #} + {% if direction == "out" %} + {% if row.ref.ref_key %} + [{{ row.ref.ref_key }}]
+ {% endif %} + {% endif %} + {{ row.ref.match_status }}
+ {% if row.ref.match_provenance %} + via {{ row.ref.match_provenance }} + {% endif %} +
+ {% if release %} + {{ entity_macros.release_summary(release) }} + {% elif row.ref.target_unstructured %} + {{ row.ref.target_unstructured }} + {% if row.ref.target_openlibrary_work %} +
openlibrary:{{ row.ref.target_openlibrary_work }}  + {% endif %} + {% elif row.ref.target_csl %} + {{ entity_macros.csl_summary(row.ref.target_csl) }} + {% else %} + blank + {% endif %} +
+ {% if row.access %} + {% for access in row.access %} + + {%- if access.access_type.name == "wayback" %} + web.archive.org + {%- elif access.access_type.name == "ia_file" -%} + archive.org + {%- else -%} + {{ access.access_type.name }} + {%- endif -%} + {%- if access.mimetype == "application/pdf" %} + [PDF] + {%- elif access.mimetype == "text/html" %} + [HTML] + {%- endif -%} + +
+ {% endfor %} + {% elif direction == "out" and row.ref.target_unstructured %} +
+ + + +
+ {% endif %} +{% endfor %} +
+ {{ pagination_row(hits) }} +
+{% endmacro %} + -- cgit v1.2.3 From cb3d10a06c0166c4eb8ec2d48852e4bfc236ef27 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 27 Jul 2021 17:01:29 -0700 Subject: refs: support for wikipedia outbound refs, and display in tables --- python/fatcat_tools/references.py | 4 ++-- python/fatcat_web/ref_routes.py | 26 ++++++++++++++++++--- python/fatcat_web/templates/refs_macros.html | 20 +++++++++++++--- .../templates/wikipedia_view_fuzzy_refs.html | 27 ++++++++++++++++++++++ 4 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 python/fatcat_web/templates/wikipedia_view_fuzzy_refs.html (limited to 'python/fatcat_web/templates/refs_macros.html') 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/OLW/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/:/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/OLW/refs-in', methods=['GET', 'OPTIONS']) +@app.route('/openlibrary/OLW/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/:/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 @@ {% 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:]) %} + + + {{ wiki_article }} + + [wikipedia] + +
+ lang:{{ wiki_lang }}  + [references]  + {% elif direction == "out" and row.ref.target_unstructured %} {{ row.ref.target_unstructured }} {% if row.ref.target_openlibrary_work %} -
openlibrary:{{ row.ref.target_openlibrary_work }}  +
+ openlibrary:{{ row.ref.target_openlibrary_work }}  + [cited-by]  {% endif %} - {% elif row.ref.target_csl %} + {% elif direction == "in" and row.ref.target_csl %} {{ entity_macros.csl_summary(row.ref.target_csl) }} {% else %} blank 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 %} +

+ [{{ wiki_lang }}] {{ wiki_article }} + {{ wiki_url }} +

+ +{% if direction == "in" %} +

Cited By

+

This page lists references to a wikipedia article, from other works (eg, journal articles). +{% elif direction == "out" %} +

References

+ Refernces from wikipedia article to other entities. +{% endif %} + +{% if hits.result_refs %} + {{ refs_macros.refs_table(hits, direction) }} +{% else %} +

None found +{% endif %} + +{% endblock %} + -- cgit v1.2.3 From fa2ba60834cf3cb3edea05af3c1830e6fc0d5bcc Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 27 Jul 2021 18:48:14 -0700 Subject: refs: several small improvements to web UI --- python/fatcat_web/templates/entity_macros.html | 11 +++- .../templates/openlibrary_view_fuzzy_refs.html | 6 +- python/fatcat_web/templates/refs_macros.html | 71 ++++++++++++++++------ .../templates/release_view_fuzzy_refs.html | 12 ++-- .../templates/wikipedia_view_fuzzy_refs.html | 6 +- 5 files changed, 71 insertions(+), 35 deletions(-) (limited to 'python/fatcat_web/templates/refs_macros.html') diff --git a/python/fatcat_web/templates/entity_macros.html b/python/fatcat_web/templates/entity_macros.html index 37bb2d90..562b99d3 100644 --- a/python/fatcat_web/templates/entity_macros.html +++ b/python/fatcat_web/templates/entity_macros.html @@ -391,7 +391,7 @@ yellow {# this is useful for things like showing lists of releases in tables #} {% macro release_summary(release) %} {{ release.title }} - {% if release.release_type not in ["article-journal", "conference-paper"] %} + {% if release.release_type not in ["article-journal", "paper-conference"] %} [{{ release.release_type or "unknown-type" }}] {% endif %} {% if release.contribs %}
{% endif %} @@ -405,7 +405,14 @@ yellow {% endfor %} {% if release.contribs | length > 8 %} (+ more) {%endif %} {% if release.release_year or release.container or (release.extra and release.extra.container_name) %}
{% endif %} - {% if release.release_year %}{{ release.release_year }}  {% endif %} + {% if release.release_year %} + {% if release.release_date %} + {{ release.release_year }} + {% else %} + {{ release.release_year }} + {% endif %} +   + {% endif %} {% if release.container %} {{ release.container.name }} {% elif release.extra and release.extra.container_name %} diff --git a/python/fatcat_web/templates/openlibrary_view_fuzzy_refs.html b/python/fatcat_web/templates/openlibrary_view_fuzzy_refs.html index 161a7b50..21bf76f2 100644 --- a/python/fatcat_web/templates/openlibrary_view_fuzzy_refs.html +++ b/python/fatcat_web/templates/openlibrary_view_fuzzy_refs.html @@ -19,11 +19,7 @@ Refernces from this book to other entities. {% endif %} -{% if hits.result_refs %} - {{ refs_macros.refs_table(hits, direction) }} -{% else %} -

None found -{% endif %} +{{ refs_macros.refs_table(hits, direction) }} {% endblock %} diff --git a/python/fatcat_web/templates/refs_macros.html b/python/fatcat_web/templates/refs_macros.html index ba4d18ad..3db47064 100644 --- a/python/fatcat_web/templates/refs_macros.html +++ b/python/fatcat_web/templates/refs_macros.html @@ -1,37 +1,67 @@ {% import "entity_macros.html" as entity_macros %} -{% macro pagination_row(hits, direction) %} - - {% if hits.offset %} +{% macro pagination_row(hits, with_links=False) %} + {% if with_links and hits.offset %} « prev   {% endif %} - Showing {{ hits.offset + 1 }} - {{ hits.offset + hits.count_returned }} of {{ hits.count_total}} references (in {{ hits.query_wall_time_ms }}ms) - {% if hits.count_total != hits.count_returned and hits.offset + hits.limit < hits.count_total %} + {% if hits.count_returned == 0 %} + Showing 0 references + {% else %} + Showing {{ hits.offset + 1 }} - {{ hits.offset + hits.count_returned }} of {{ hits.count_total}} references + {% endif %} + {% if with_links and hits.count_total != hits.count_returned and hits.offset + hits.limit < hits.count_total %}  next » {% endif %} {% endmacro %} {% macro refs_table(hits, direction) %} +

+
+ Fuzzy reference matching is a work in progress! +
+ Read more about quality, completeness, and caveats in the fatcat guide. +
+{% if hits.count_total == 0 %} + + -{% if hits.count_total != hits.count_returned %} - - -{% endif %} + +
- {{ pagination_row(hits) }} + {{ pagination_row(hits, with_links=False) }} + (in {{ hits.query_wall_time_ms }}ms)
+
+ + No References Found +
+{% endif %} {% for row in hits.result_refs %} {% set release = row.release %} -
+
{# TODO: ref_locator? #} {% if direction == "out" %} {% if row.ref.ref_key %} [{{ row.ref.ref_key }}]
{% endif %} {% endif %} - {{ row.ref.match_status }}
- {% if row.ref.match_provenance %} - via {{ row.ref.match_provenance }} + + {% if row.ref.match_status == "exact" %} + {% set match_icon = "linkify" %} + {% elif row.ref.match_status == "unmatched" %} + {% set match_icon = "question circle outline" %} + {% else %} + {% set match_icon = "magic" %} {% endif %} +
+ {% if row.ref.match_provenance and row.ref.match_provenance == "fatcat-pubmed" %} + {# this is a common case and making the column render wide #} + via pubmed + {% elif row.ref.match_provenance %} + via {{ row.ref.match_provenance }}
+ {% endif %} +
{% if release %} {{ entity_macros.release_summary(release) }} @@ -62,7 +92,7 @@ {% if row.access %} {% for access in row.access %} - + {%- if access.access_type.name == "wayback" %} web.archive.org {%- elif access.access_type.name == "ia_file" -%} @@ -83,18 +113,23 @@ {% endif %} {% endfor %}
- {{ pagination_row(hits) }} -
+
+ JSON +
+ {% if hits.count_returned != hits.count_total %} +
+ {{ pagination_row(hits, with_links=True) }} +
+ {% endif %} +
{% endmacro %} diff --git a/python/fatcat_web/templates/release_view_fuzzy_refs.html b/python/fatcat_web/templates/release_view_fuzzy_refs.html index ffca0bc9..8cba4f4e 100644 --- a/python/fatcat_web/templates/release_view_fuzzy_refs.html +++ b/python/fatcat_web/templates/release_view_fuzzy_refs.html @@ -13,13 +13,15 @@ {% elif direction == "out" %}

References

NOTE: currently batch computed and may include additional references sources, or be missing recent changes, compared to entity reference list. -{% endif %} -{% if hits.result_refs %} - {{ refs_macros.refs_table(hits, direction) }} -{% else %} -

None found + {% if hits.count_total == 0 and release.refs %} +

+

No fuzzy references found, but there are {{ release.refs|count }} legacy references +

+ {% endif %} {% endif %} +{{ refs_macros.refs_table(hits, direction) }} + {% endblock %} diff --git a/python/fatcat_web/templates/wikipedia_view_fuzzy_refs.html b/python/fatcat_web/templates/wikipedia_view_fuzzy_refs.html index 5b53d692..3e1453c1 100644 --- a/python/fatcat_web/templates/wikipedia_view_fuzzy_refs.html +++ b/python/fatcat_web/templates/wikipedia_view_fuzzy_refs.html @@ -17,11 +17,7 @@ Refernces from wikipedia article to other entities. {% endif %} -{% if hits.result_refs %} - {{ refs_macros.refs_table(hits, direction) }} -{% else %} -

None found -{% endif %} +{{ refs_macros.refs_table(hits, direction) }} {% endblock %} -- cgit v1.2.3 From f29da9adb50a37cb6aad4e435fc09a5d682cbe6c Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 27 Jul 2021 18:57:25 -0700 Subject: refs: revert fatcat-pubmed -> pubmed truncation This was just going to be confusing --- python/fatcat_web/templates/refs_macros.html | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'python/fatcat_web/templates/refs_macros.html') diff --git a/python/fatcat_web/templates/refs_macros.html b/python/fatcat_web/templates/refs_macros.html index 3db47064..8b6a5dc3 100644 --- a/python/fatcat_web/templates/refs_macros.html +++ b/python/fatcat_web/templates/refs_macros.html @@ -55,10 +55,7 @@ {% set match_icon = "magic" %} {% endif %}
- {% if row.ref.match_provenance and row.ref.match_provenance == "fatcat-pubmed" %} - {# this is a common case and making the column render wide #} - via pubmed - {% elif row.ref.match_provenance %} + {% if row.ref.match_provenance %} via {{ row.ref.match_provenance }}
{% endif %} -- cgit v1.2.3 From ed56037d929d50abab707ee5eb9f583789a8ac7a Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 27 Jul 2021 19:21:49 -0700 Subject: refs: fix typo preventing CSL from rendering in refs output --- python/fatcat_web/templates/refs_macros.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python/fatcat_web/templates/refs_macros.html') diff --git a/python/fatcat_web/templates/refs_macros.html b/python/fatcat_web/templates/refs_macros.html index 8b6a5dc3..3095ce54 100644 --- a/python/fatcat_web/templates/refs_macros.html +++ b/python/fatcat_web/templates/refs_macros.html @@ -81,7 +81,7 @@ openlibrary:{{ row.ref.target_openlibrary_work }}  [cited-by]  {% endif %} - {% elif direction == "in" and row.ref.target_csl %} + {% elif direction == "out" and row.ref.target_csl %} {{ entity_macros.csl_summary(row.ref.target_csl) }} {% else %} blank -- cgit v1.2.3 From 4338ec346381647f079a464092e45c609894fe11 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Wed, 4 Aug 2021 12:11:20 -0700 Subject: refs web: correct URL to refs section of guide --- python/fatcat_web/templates/refs_macros.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python/fatcat_web/templates/refs_macros.html') diff --git a/python/fatcat_web/templates/refs_macros.html b/python/fatcat_web/templates/refs_macros.html index 3095ce54..4ccca7a5 100644 --- a/python/fatcat_web/templates/refs_macros.html +++ b/python/fatcat_web/templates/refs_macros.html @@ -19,7 +19,7 @@

Fuzzy reference matching is a work in progress!
- Read more about quality, completeness, and caveats in the fatcat guide. + Read more about quality, completeness, and caveats in the fatcat guide. -- cgit v1.2.3 From 56e4ce2d8347cdfedd492d54fde080772f3d8725 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Fri, 6 Aug 2021 11:58:10 -0700 Subject: refs: format (commas) large refs hit counts --- python/fatcat_web/templates/refs_macros.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python/fatcat_web/templates/refs_macros.html') diff --git a/python/fatcat_web/templates/refs_macros.html b/python/fatcat_web/templates/refs_macros.html index 4ccca7a5..47ea2dcf 100644 --- a/python/fatcat_web/templates/refs_macros.html +++ b/python/fatcat_web/templates/refs_macros.html @@ -7,7 +7,7 @@ {% if hits.count_returned == 0 %} Showing 0 references {% else %} - Showing {{ hits.offset + 1 }} - {{ hits.offset + hits.count_returned }} of {{ hits.count_total}} references + Showing {{ "{:,}".format(hits.offset + 1) }} - {{ "{:,}".format(hits.offset + hits.count_returned) }} of {{ "{:,}".format(hits.count_total) }} references {% endif %} {% if with_links and hits.count_total != hits.count_returned and hits.offset + hits.limit < hits.count_total %}  next » -- cgit v1.2.3