Skip to content

Commit

Permalink
Merge pull request #238 from golnazads/master
Browse files Browse the repository at this point in the history
added xe specifier for custom format to output eprint comment
  • Loading branch information
golnazads committed Jun 9, 2023
2 parents 59a4fd2 + 13aada2 commit 256ca74
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 12 deletions.
22 changes: 12 additions & 10 deletions exportsrv/formatter/customFormat.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ class CustomFormat(Format):
re.compile(r'(%Z(?:EOL):\".*\"\s?)'),
]
REGEX_CUSTOME_FORMAT = re.compile(
r'''( # start of capture group 1
% # literal "%"
(?:[\\></=])? # field encoding
(?: # first option
(?:\d+|\*)? # width
(?:\.(?:\d+|\*))? # precision
r'''( # start of capture group 1
% # literal "%"
(?:[\\></=])? # field encoding
(?: # first option
(?:\d+|\*)? # width
(?:\.(?:\d+|\*))? # precision
(?:\^)?
p{0,2}[AaBcCdDeEfFGgHhiIJjKkLlMmNnOopPQqRSTUuVWXxY] # type
[px]{0,2}[AaBcCdDeEfFGgHhiIJjKkLlMmNnOopPQqRSTUuVWXxY] # type
)
)''', flags=re.X
)
Expand Down Expand Up @@ -202,6 +202,7 @@ def __get_solr_field(self, specifier):
'W': 'doctype',
'X': 'eid,identifier',
'x': 'comment',
'xe': 'pubnote',
'Y': 'year'
}
specifier = ''.join(re.findall(r'([AaBcCdDeEfFGgHhiIJjKkLlMmNnOopPQqRSTUuVWXxY]{1,2})', specifier))
Expand Down Expand Up @@ -310,8 +311,9 @@ def __parse(self):
for m in self.REGEX_CUSTOME_FORMAT.finditer(self.custom_format):
self.parsed_spec.append(tuple((m.start(1), m.group(1), self.__get_solr_field(m.group(1)))))
# we have %p, %pp, and %pc, when doing replace, %p causes other two to be replaced
# re did not work, so pushing %p to the end to be the last item to get replaced
self.parsed_spec = sorted(self.parsed_spec, key=lambda tup: tup[1] == '%p')
# similarly %x and %xe
# so pushing %p and %x to the end to be the last item to get replaced
self.parsed_spec = sorted(self.parsed_spec, key=lambda tup: tup[1] in ['%p', '%x'])
self.__escape()
self.__for_csv()

Expand Down Expand Up @@ -829,7 +831,7 @@ def __get_doc(self, index):
result = self.custom_format
a_doc = self.from_solr['response'].get('docs')[index]
for field in self.parsed_spec:
if (field[2] == 'title') or (field[2] == 'doi') or (field[2] == 'comment'):
if (field[2] == 'title') or (field[2] == 'doi') or (field[2] == 'comment') or (field[2] == 'pubnote'):
result = self.__add_in(result, field, ''.join(a_doc.get(field[2], '')))
elif (field[2] == 'author'):
result = self.__add_in(result, field, self.__get_author_list(field[1], index))
Expand Down
30 changes: 30 additions & 0 deletions exportsrv/tests/unittests/stubdata/solrdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1381,4 +1381,34 @@
}
]
}
}

data_15 = \
{
u'responseHeader': {
u'status': 0,
u'QTime': 8,
u'params': {
u'q': u'bibcode:(2023JSMTE2023b3301M OR 2023yCat..19220186H OR 2019Sci...365..565B)',
u'fl': u'bibcode,comment,pubnote',
u'_': u'1686158703270'
}
},
u'response': {
'numFound': 3,
'start': 0,
'docs': [
{
u'bibcode': u'2019Sci...365..565B',
u'comment': [u'Galaxies B and C from figures 2 are not in SIMBAD.'],
u'pubnote': [u'Published online in Science 27 June 2019; doi:10.1126/science.aaw5903']},
{
u'bibcode': u'2023JSMTE2023b3301M',
u'pubnote': [u'doi:10.1088/1742-5468/acaf82']},
{
u'bibcode': u'2023yCat..19220186H',
u'comment': [u'fig1.dat 6946x39 Keck/NIRES near-IR spectrum of peculiar type Ia; SN2020qxp/ASASSN-20jq taken at +191d past the epoch ; of rest-frame B-band maximum (MJD=59277.50)']
}
]
}
}
10 changes: 10 additions & 0 deletions exportsrv/tests/unittests/test_custom_format_functionality.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,5 +400,15 @@ def test_author_without_firstname(self):
assert (custom_format.get().get('export', '') == r''.join(formatted))


def test_comment_and_pubnote(self):
# verify the new specifier xe which should output putnote
formatted = [u'2019Sci...365..565B\n comment:Galaxies B and C from figures 2 are not in SIMBAD.\n eprint_comment: Published online in Science 27 June 2019; doi:10.1126/science.aaw5903\n',
u'2023JSMTE2023b3301M\n comment:\n eprint_comment: doi:10.1088/1742-5468/acaf82\n',
u'2023yCat..19220186H\n comment:fig1.dat 6946x39 Keck/NIRES near-IR spectrum of peculiar type Ia; SN2020qxp/ASASSN-20jq taken at +191d past the epoch ; of rest-frame B-band maximum (MJD=59277.50)\n eprint_comment:\n']
custom_format = CustomFormat(custom_format=r'%R\n comment:%x\n eprint_comment: %xe')
custom_format.set_json_from_solr(solrdata.data_15)
assert (custom_format.get().get('export', '') == r''.join(formatted))


if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion exportsrv/tests/unittests/test_export_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def test_ads_formatter(self):

def test_default_solr_fields(self):
default_fields = 'author,title,year,pubdate,pub,pub_raw,issue,volume,page,page_range,aff,aff_canonical,doi,abstract,' \
'read_count,bibcode,identifier,copyright,keyword,doctype,[citations],comment,version,' \
'read_count,bibcode,identifier,copyright,keyword,doctype,[citations],comment,pubnote,version,' \
'property,esources,data,isbn,eid,issn,arxiv_class,editor,series,publisher,bibstem,page_count,orcid_pub'
assert (views.default_solr_fields() == default_fields)

Expand Down
2 changes: 1 addition & 1 deletion exportsrv/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def default_solr_fields():
:return: list of fields needed from solr
"""
return 'author,title,year,pubdate,pub,pub_raw,issue,volume,page,page_range,aff,aff_canonical,doi,abstract,' \
'read_count,bibcode,identifier,copyright,keyword,doctype,[citations],comment,version,' \
'read_count,bibcode,identifier,copyright,keyword,doctype,[citations],comment,pubnote,version,' \
'property,esources,data,isbn,eid,issn,arxiv_class,editor,series,publisher,bibstem,page_count,orcid_pub'


Expand Down

0 comments on commit 256ca74

Please sign in to comment.