Skip to content

Commit

Permalink
Merge pull request #239 from golnazads/master
Browse files Browse the repository at this point in the history
added outputing number of references for custom format
  • Loading branch information
golnazads committed Jun 26, 2023
2 parents 256ca74 + c087ea2 commit 5eaf53a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions exportsrv/formatter/customFormat.py
Expand Up @@ -46,7 +46,7 @@ class CustomFormat(Format):
(?:\d+|\*)? # width
(?:\.(?:\d+|\*))? # precision
(?:\^)?
[px]{0,2}[AaBcCdDeEfFGgHhiIJjKkLlMmNnOopPQqRSTUuVWXxY] # type
[px]{0,2}[AaBcCdDeEfFGgHhiIJjKkLlMmNnOopPQqrRSTUuVWXxY] # type
)
)''', flags=re.X
)
Expand Down Expand Up @@ -193,6 +193,7 @@ def __get_solr_field(self, specifier):
'pc':'page_count',
'Q': 'pub_raw',
'q': 'pub',
'r': 'num_references',
'R': 'bibcode',
'S': 'issue',
'T': 'title',
Expand All @@ -205,7 +206,7 @@ def __get_solr_field(self, specifier):
'xe': 'pubnote',
'Y': 'year'
}
specifier = ''.join(re.findall(r'([AaBcCdDeEfFGgHhiIJjKkLlMmNnOopPQqRSTUuVWXxY]{1,2})', specifier))
specifier = ''.join(re.findall(r'([AaBcCdDeEfFGgHhiIJjKkLlMmNnOopPQqrRSTUuVWXxY]{1,2})', specifier))
return fieldDict.get(specifier, '')


Expand Down Expand Up @@ -850,7 +851,7 @@ def __get_doc(self, index):
result = self.__add_in(result, field, a_doc.get(field[2], ''))
elif (field[2] == 'pub') or (field[2] == 'pub_raw'):
result = self.__add_in(result, field, self.__get_publication(field[1], a_doc))
elif (field[2] == 'num_citations') or (field[2] == 'page_count'):
elif (field[2] == 'num_citations') or (field[2] == 'num_references') or (field[2] == 'page_count'):
result = self.__add_in(result, field, str(a_doc.get(field[2], '')))
elif (field[2] == 'eid,identifier'):
result = self.__add_in(result, field, get_eprint(a_doc))
Expand Down
7 changes: 4 additions & 3 deletions exportsrv/tests/unittests/test_custom_format_functionality.py
Expand Up @@ -370,17 +370,18 @@ def test_page_range(self):
assert (custom_format.get().get('export', '') == formatted_record)

def test_num_citiations(self):
# verify %c outputs num_citations
# verify %c and %r outputs respectively for num_citations and num_references
with mock.patch.object(self.current_app.client, 'get') as get_mock:
get_mock.return_value = mock_response = mock.Mock()
mock_response.json.return_value = solrdata.data_11
mock_response.status_code = 200
solr_data = get_solr_data(bibcodes=["2016ApJ...818L..26F"], fields='read_count,bibcode,doctype,[citations],bibstem',
sort=self.current_app.config['EXPORT_SERVICE_NO_SORT_SOLR'])
self.assertEqual(solr_data['response']['docs'][0]['num_citations'], 29)
custom_format = CustomFormat(custom_format=r'%R: %c')
self.assertEqual(solr_data['response']['docs'][0]['num_references'], 40)
custom_format = CustomFormat(custom_format=r'%R: %c|%r')
custom_format.set_json_from_solr(solrdata.data_11)
assert (custom_format.get().get('export', '') == "2016ApJ...818L..26F: 29\n")
assert (custom_format.get().get('export', '') == "2016ApJ...818L..26F: 29|40\n")

def test_escaping_literal(self):
# verify for example %%R is translated to %R and not recognized as field ID bibcode
Expand Down

0 comments on commit 5eaf53a

Please sign in to comment.