aboutsummaryrefslogtreecommitdiffstats
path: root/python/fatcat_web
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2021-09-21 22:26:07 -0700
committerBryan Newbold <bnewbold@robocracy.org>2021-10-18 10:18:48 -0700
commit7f85ecea4e5a844ad78d129ed0b32a759ca7c1ad (patch)
tree5b1d43fc6c5a10138bf68912435aeaf58d62b1a4 /python/fatcat_web
parent4be667616ae209fa0efaaa2350c1b75eacf0e344 (diff)
downloadfatcat-7f85ecea4e5a844ad78d129ed0b32a759ca7c1ad.tar.gz
fatcat-7f85ecea4e5a844ad78d129ed0b32a759ca7c1ad.zip
add GET w/ query params to reference match endpoint (and JSON version)
Diffstat (limited to 'python/fatcat_web')
-rw-r--r--python/fatcat_web/forms.py12
-rw-r--r--python/fatcat_web/ref_routes.py37
-rw-r--r--python/fatcat_web/templates/reference_match.html4
3 files changed, 47 insertions, 6 deletions
diff --git a/python/fatcat_web/forms.py b/python/fatcat_web/forms.py
index a856ef22..2757ebd2 100644
--- a/python/fatcat_web/forms.py
+++ b/python/fatcat_web/forms.py
@@ -487,6 +487,10 @@ class EntityTomlForm(EntityEditForm):
class ReferenceMatchForm(FlaskForm):
+ class Meta:
+ # this is an API, so disable CSRF
+ csrf = False
+
submit_type = SelectField('submit_type',
[validators.DataRequired()],
choices=['parse', 'match'])
@@ -496,12 +500,20 @@ class ReferenceMatchForm(FlaskForm):
title = StringField("Title")
journal = StringField("Journal or Conference")
first_author = StringField("First Author")
+ #author_names = StringField("Author Names")
#year = IntegerField('Year Released',
# [validators.Optional(True), valid_year])
year = StringField("Year Released")
+ date = StringField("Date Released")
volume = StringField("Volume")
issue = StringField("Issue")
pages = StringField("Pages")
+ publisher = StringField("Publisher")
+ doi = StringField("DOI")
+ pmid = StringField("PubMed Identifier (PMID)")
+ arxiv_id = StringField("arxiv.org Identifier")
+ release_type = StringField("Release Type")
+ release_stage = StringField("Release Stage")
@staticmethod
def from_grobid_parse(parse_dict, raw_citation):
diff --git a/python/fatcat_web/ref_routes.py b/python/fatcat_web/ref_routes.py
index d4219012..33d2f725 100644
--- a/python/fatcat_web/ref_routes.py
+++ b/python/fatcat_web/ref_routes.py
@@ -3,13 +3,16 @@ Flask endpoints for reference (citation) endpoints. Eg, listing references
"inbound" and "outbound" from a specific release or work.
"""
-from flask import render_template, request, Response
+import json
+
+from flask import render_template, request, Response, jsonify
from fatcat_openapi_client import *
from fuzzycat.grobid_unstructured import grobid_api_process_citation, transform_grobid_ref_xml, grobid_ref_to_release
from fuzzycat.simple import close_fuzzy_biblio_matches, close_fuzzy_release_matches
from fatcat_tools.references import enrich_inbound_refs, enrich_outbound_refs, get_inbound_refs, get_outbound_refs, RefHits
from fatcat_tools.transforms.access import release_access_options
+from fatcat_tools.transforms.entities import entity_to_dict
from fatcat_web import app, api
from fatcat_web.cors import crossdomain
from fatcat_web.forms import *
@@ -92,16 +95,18 @@ def wikipedia_view_refs_outbound(wiki_lang: str, wiki_article: str):
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():
- form = ReferenceMatchForm()
grobid_status = None
grobid_dict = None
- if form.is_submitted():
- if form.validate_on_submit():
+ form = ReferenceMatchForm()
+ if not form.is_submitted() and request.args.get('submit_type'):
+ form = ReferenceMatchForm(request.args)
+
+ if form.is_submitted() or request.args.get('title'):
+ if form.validate():
if form.submit_type.data == 'parse':
resp_xml = grobid_api_process_citation(form.raw_citation.data)
if not resp_xml:
@@ -166,3 +171,25 @@ def wikipedia_view_refs_outbound_json(wiki_lang: str, wiki_article: str):
wikipedia_article = wiki_lang + ":" + wiki_article
hits = _refs_web("out", wikipedia_article=wikipedia_article)
return Response(hits.json(exclude_unset=True), mimetype="application/json")
+
+
+@app.route('/reference/match.json', methods=['GET', 'OPTIONS'])
+@crossdomain(origin='*',headers=['access-control-allow-origin','Content-Type'])
+def reference_match_json():
+ form = ReferenceMatchForm(request.args)
+ if form.validate():
+ if form.submit_type.data == 'match':
+ matches = close_fuzzy_biblio_matches(es_client=app.es_client, biblio=form.data, match_limit=10) or []
+ else:
+ raise NotImplementedError()
+ for m in matches:
+ # expand releases more completely
+ m.release = api.get_release(m.release.ident, expand="container,files,filesets,webcaptures", hide="abstract,refs")
+ # hack in access options
+ m.access_options = release_access_options(m.release)
+
+ # and convert to dict (for jsonify)
+ m.release = entity_to_dict(m.release)
+ return jsonify(matches), 200
+ else:
+ return Response(json.dumps(dict(errors=form.errors)), mimetype="application/json", status=400)
diff --git a/python/fatcat_web/templates/reference_match.html b/python/fatcat_web/templates/reference_match.html
index f2335f52..08ab33fc 100644
--- a/python/fatcat_web/templates/reference_match.html
+++ b/python/fatcat_web/templates/reference_match.html
@@ -83,7 +83,9 @@
<td class="">
{% if match.access_options %}
<a href="{{ match.access_options[0].access_url}}" class="ui tiny green active button">{{ match.access_options[0].access_type.name }}</a>
- {% endif %}
+ {% else %}
+ <i class="ui tiny grey inactive button">no fulltext</a>
+ {% endif %}
{% endfor %}
</tbody>
</table>