Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
REFERENCE_SERVICE_MAX_RECORDS_SOLR = 100

REFERENCE_SERVICE_QUERY_FIELDS_SOLR = "author,[fields author=10]author_norm,[fields author_norm=10],first_author_norm," \
"year,title,pub,pub_raw,aff_raw,[fields aff_raw=1]," \
"year,title,pub,pub_raw,aff_raw,[fields aff_raw=1],scix_id," \
"volume,issue,page,page_range,bibstem,bibcode,identifier,doi,doctype"

# maximum references that can be resolved in one call
Expand Down
7 changes: 4 additions & 3 deletions referencesrv/resolver/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class Solution(object):
* score
* source_hypothesis (the hypothesis that eventually got it right)
"""
def __init__(self, cited_bibcode, score, source_hypothesis='not given', citing_bibcode=None):
def __init__(self, cited_bibcode, score, source_hypothesis='not given', cited_bibcode=None, citing_bibcode=None, scix_id=None):
"""

:param cited_bibcode:
Expand All @@ -276,14 +276,15 @@ def __init__(self, cited_bibcode, score, source_hypothesis='not given', citing_b
self.score = score
self.citing_bibcode = str(citing_bibcode)
self.source_hypothesis = source_hypothesis
self.scix_id = scix_id

def __str__(self):
"""

:return:
"""
if isinstance(self.score, Evidences):
return '%.1f %s'%(self.score.avg(),self.cited_bibcode)
return '%.1f bibcode:%s scixid:%s'%(self.score.avg(),self.cited_bibcode, self.scix_id)
raise NoSolution("NotResolved")

def __repr__(self):
Expand Down Expand Up @@ -459,4 +460,4 @@ def predicate(x):
non_numbers = filterfalse(predicate, t2)
sorted_numbers = sorted(numbers)
sorted_non_numbers = sorted(non_numbers, key=str)
return sorted_numbers + sorted_non_numbers
return sorted_numbers + sorted_non_numbers
4 changes: 3 additions & 1 deletion referencesrv/resolver/solrtestdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def get_test_data():
u'numFound': 2,
u'docs': [
{u'bibcode': u'2019AAS...23320704A',
u'scix_id': u'scix:6ANE-YQXJ-KRH0',
u'author': [u'Accomazzi, Alberto'],
u'title': [u'The NASA Astrophysics Data System\xe2\u20ac\u2122s Decadal Plan for the 2020s'],
u'doctype': u'abstract',
Expand All @@ -32,6 +33,7 @@ def get_test_data():
u'identifier': [u'2019AAS...23320704A'],
u'page': [u'207.04']},
{u'bibcode': u'2019AAS...23338108A',
u'scix_id': u'scix:AGA3-9D3P-Y7EF',
u'author': [u'Accomazzi, Alberto', u'Kurtz, Michael J.', u'Henneken, Edwin', u'Grant, Carolyn S.', u'Thompson, Donna M.', u'Chyla, Roman', u'McDonald, Stephen', u'Blanco-Cuaresma, Sergi', u'Shapurian, Golnaz', u'Hostetler, Timothy', u'Templeton, Matthew', u'Lockhart, Kelly'],
u'title': [u'Transitioning from ADS Classic to the new ADS search platform'],
u'doctype': u'abstract',
Expand All @@ -45,4 +47,4 @@ def get_test_data():
u'page': [u'381.08']}
]
}
}
}
5 changes: 2 additions & 3 deletions referencesrv/resolver/solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,10 @@ def solve_for_fields(hypothesis):

current_app.logger.debug("evidences from %s"%(hypothesis.name))
for score, sol in sorted2(scored):
current_app.logger.debug("score %s %s %s"%(sol['bibcode'], score.get_score(), score))
current_app.logger.debug("score %s %s %s"%(sol.get('bibcode',None), score.get_score(), score))

score, sol = choose_solution(scored, query_string, hypothesis)

return Solution(sol["bibcode"], score, hypothesis.name)
return Solution(sol.get("bibcode",None), score, hypothesis.name, scix_id=sol.get("scix_id",None))

raise OverflowOrNone("Got either too many or no records from solr")

Expand Down
5 changes: 4 additions & 1 deletion referencesrv/tests/unittests/test_referencesrv_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ def test_01(self):
u'year': u'2020',
u'page': u'2',
u'bibcode': u'2020JHEP...09..002P',
u'scix_id': u'scix:5KGH-MC98-7AYN',
u'author': [u'Penington, Geoffrey'], u'issue': u'9',
u'aff_raw': u'Stanford Institute for Theoretical Physics, Stanford University, 450 Jane Stanford Way, 94305, Stanford, CA, USA',
u'pub': u'Journal of High Energy Physics',
Expand All @@ -769,7 +770,7 @@ def test_01(self):
}
})
r = self.client.post(path='/text', data=json.dumps({'reference': ['Penington, G, 2020, JHEP, 9']}))
self.assertEqual(r.data, b"1.0 2020JHEP...09..002P -- Penington, G, 2020, JHEP, 9")
self.assertEqual(r.data, b"1.0 bibcode:2020JHEP...09..002P scixid:scix:5KGH-MC98-7AYN -- Penington, G, 2020, JHEP, 9")

def test_02(self):
""" test text endpoint when request is to return in json format """
Expand All @@ -785,6 +786,7 @@ def test_02(self):
u'year': u'2020',
u'page': u'2',
u'bibcode': u'2020JHEP...09..002P',
u'scix_id': u'scix:5KGH-MC98-7AYN',
u'author': [u'Penington, Geoffrey'], u'issue': u'9',
u'aff_raw': u'Stanford Institute for Theoretical Physics, Stanford University, 450 Jane Stanford Way, 94305, Stanford, CA, USA',
u'pub': u'Journal of High Energy Physics',
Expand All @@ -802,6 +804,7 @@ def test_02(self):
data=json.dumps({'reference': ['Penington, G, 2020, JHEP, 9']}),
headers={'accept':'application/json'})
self.assertEqual(json.loads(r.data), {"resolved": [{"refstring": "Penington, G, 2020, JHEP, 9",
"scix_id":"scix:5KGH-MC98-7AYN",
"score": "1.0",
"bibcode": "2020JHEP...09..002P"}]})

Expand Down
14 changes: 7 additions & 7 deletions referencesrv/tests/unittests/test_referencesrv_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ def test_Solution(self):
"""
e = Evidences()
e.add_evidence(1, 'bibcode')
s = Solution(cited_bibcode='2013SPIE.8004.2013Z', score=e)
self.assertEqual(str(s), '1.0 2013SPIE.8004.2013Z')
s = Solution(cited_bibcode='2013SPIE.8004.2013Z', scix_id='foo', score=e)
self.assertEqual(str(s), '1.0 bibcode:2013SPIE.8004.2013Z scixid:foo')
self.assertEqual(repr(s), "'2013SPIE.8004.2013Z'")


Expand Down Expand Up @@ -417,22 +417,22 @@ def test_solve_reference(self):
'volume': '233',
'year': '2019',
'page': '207.04'}
self.assertEqual(str(solve_reference(Hypotheses(ref))), '1.0 2019AAS...23320704A')
self.assertEqual(str(solve_reference(Hypotheses(ref))), '1.0 bibcode:2019AAS...23320704A scixid:scix:6ANE-YQXJ-KRH0')
# testing with first author only and page
# eventhough other authors are missing but because of page match is found
ref = {'authors': 'Accomazzi, A.',
'journal': 'AAS233 Meeting',
'volume': '233',
'year': '2019',
'page': '381.08'}
self.assertEqual(str(solve_reference(Hypotheses(ref))), '0.8 2019AAS...23338108A')
self.assertEqual(str(solve_reference(Hypotheses(ref))), '0.8 bibcode:2019AAS...23338108A scixid:scix:AGA3-9D3P-Y7EF')
# testing with first author only and no page, hence record with only the first author is returned
ref = {'authors': 'Accomazzi, A.',
'journal': 'AAS233 Meeting',
'volume': '233',
'year': '2019',
'page': '0'}
self.assertEqual(str(solve_reference(Hypotheses(ref))), '0.8 2019AAS...23320704A')
self.assertEqual(str(solve_reference(Hypotheses(ref))), '0.8 bibcode:2019AAS...23320704A scixid:scix:6ANE-YQXJ-KRH0')
# when we have multiple solutions and not enough reference information to decide which
# page and author are the deciding factor between these two test records
# here first author and page are wrong
Expand All @@ -454,7 +454,7 @@ def test_solve_reference(self):
# however the first record is authored by one author only and
# it is the same first author of the second record
# verify that the first record is returned
self.assertEqual(str(solve_reference(Hypotheses(ref))), '0.8 2019AAS...23320704A')
self.assertEqual(str(solve_reference(Hypotheses(ref))), '0.8 bibcode:2019AAS...23320704A scixid:scix:6ANE-YQXJ-KRH0')


def test_add_volume_evidence(self):
Expand Down Expand Up @@ -637,7 +637,7 @@ def test_Querier(self):
self.assertEqual(solrquery.make_params('author:("Accomazzi, A") AND year:"2019" AND bibstem:(AAS)'),
{'q': 'author:("Accomazzi, A") AND year:"2019" AND bibstem:(AAS)',
'rows': '100',
'fl': u'author,[fields author=10]author_norm,[fields author_norm=10],first_author_norm,year,title,pub,pub_raw,aff_raw,[fields aff_raw=1],volume,issue,page,page_range,bibstem,bibcode,identifier,doi,doctype'})
'fl': u'author,[fields author=10]author_norm,[fields author_norm=10],first_author_norm,year,title,pub,pub_raw,aff_raw,[fields aff_raw=1],scix_id,volume,issue,page,page_range,bibstem,bibcode,identifier,doi,doctype'})

# no author_norm
solution = {u'bibcode': u'2013JARS....7.3461V',
Expand Down
4 changes: 3 additions & 1 deletion referencesrv/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ def format_resolved_reference(returned_format, resolved, reference, id, cache=Tr
cache_resolved_set(reference, resolved)
if 'application/json' in returned_format:
resolved = resolved.split()
result = {'refstring': reference, 'score': resolved[0], 'bibcode': resolved[1]}
bibcode = resolved[1].replace('bibcode:','').strip()
scix_id = resolved[2].replace('scixid:','').strip()
result = {'refstring': reference, 'score': resolved[0], 'bibcode': bibcode, 'scix_id':scix_id}
if comment:
result['comment'] = comment
if id:
Expand Down
Loading