Skip to content

Commit

Permalink
Merge pull request #241 from golnazads/master
Browse files Browse the repository at this point in the history
added author format %E for custom format to output author list as spe…
  • Loading branch information
golnazads committed Aug 16, 2023
2 parents a3c05e9 + 95af99a commit 812c3ea
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 31 deletions.
27 changes: 27 additions & 0 deletions exportsrv/cslstyles/ads-author-E.csl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" initialize="false">
<info>
<title>ADS Author Custom Format E</title>
<title-short>ADS Author Custom Format E</title-short>
<id>https://ui.adsabs.harvard.edu</id>
<category citation-format="author"/>
<category field="generic-base"/>
<summary>Format E: last name followed by initials, no 'and' before the last author</summary>
<updated>2017-06-23T15:43:04+00:00</updated>
<rights license="http://creativecommons.org/licenses/by-sa/3.0/">This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License</rights>
</info>
<locale xml:lang="en"/>
<macro name="author"/>
<citation>
<layout/>
</citation>
<bibliography initialize="false" entry-spacing="0" hanging-indent="true">
<layout>
<text macro="author"/>
<names variable="author">
<name delimiter-precedes-last="contextual" initialize="false" initialize-with="" name-as-sort-order="all" delimiter="; "/>
<label prefix=", "/>
</names>
</layout>
</bibliography>
</style>
6 changes: 3 additions & 3 deletions exportsrv/cslstyles/ads-author-ee.csl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" and="text" initialize="false">
<info>
<title>ADS Author Custom Format L</title>
<title-short>ADS Author Custom Format L</title-short>
<title>ADS Author Custom Format e</title>
<title-short>ADS Author Custom Format e</title-short>
<id>https://ui.adsabs.harvard.edu</id>
<category citation-format="author"/>
<category field="generic-base"/>
<summary>Format L: Author as appears in db, with 'and' before the last author</summary>
<summary>Format e: last name followed by initials with dots, with 'and' before the last author</summary>
<updated>2017-06-23T15:43:04+00:00</updated>
<rights license="http://creativecommons.org/licenses/by-sa/3.0/">This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License</rights>
</info>
Expand Down
6 changes: 3 additions & 3 deletions exportsrv/cslstyles/ads-author-ff.csl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" and="text" initialize="false">
<info>
<title>ADS Author Custom Format M</title>
<title-short>ADS Author Custom Format M</title-short>
<title>ADS Author Custom Format f</title>
<title-short>ADS Author Custom Format f</title-short>
<id>https://ui.adsabs.harvard.edu</id>
<category citation-format="author"/>
<category field="generic-base"/>
<summary>Format M: First Author has the format: lastname, Second Author on has the format: lastname, Before Last Author there is and text, and when shorten has the format: n author(s), et al.</summary>
<summary>Format f: lastname only</summary>
<updated>2017-07-12T17:59:57+00:00</updated>
<rights license="http://creativecommons.org/licenses/by-sa/3.0/">This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License</rights>
</info>
Expand Down
47 changes: 32 additions & 15 deletions exportsrv/formatter/customFormat.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ def __get_solr_field(self, specifier):
'd': 'doi',
'D': 'pubdate',
'e': 'author',
'E': 'author',
'F': 'aff',
'f': 'author',
'G': 'author',
Expand Down Expand Up @@ -403,17 +404,18 @@ def __get_affiliation_list(self, a_doc):
return ''


def __get_n_authors(self, author_list, n_parts_author, before_last, format):
def __get_n_authors(self, author_list, n_parts_author, before_last, format, separator=', '):
"""
:param author_list:
:param n_parts_author:
:param before_last:
:param format:
:param separator:
:return:
"""
split_parts = author_list.replace(before_last, '').split('; ')
return self.__replace_author_separator(', '.join(split_parts[:n_parts_author]), format)
return self.__replace_author_separator(separator.join(split_parts[:n_parts_author]), format)

def __get_first_author(self, author_list, format):
"""
Expand All @@ -427,6 +429,9 @@ def __get_first_author(self, author_list, format):
# this special case, only last name is returned
if format == 'n':
return split_parts[0].split(', ')[0]
# another special case, there is no comma between last name and first/middle initials
if format == 'E':
return split_parts[0].replace(',', '')
return split_parts[0]


Expand All @@ -440,22 +445,25 @@ def __replace_author_separator(self, author_list, format):
if format in ['H', 'h']:
# remove the last separator before and for these formats, then split and rejoin
split_parts = author_list.replace('; and', ' and').split('; ')
elif format == 'E':
# remove commas between lastname and firstname
split_parts = author_list.replace(',', '').split('; ')
else:
split_parts = author_list.split('; ')
return ', '.join(split_parts)
# formats that have no comma between last name and first/middle names
# or only display last name, hence once split each is an one element
if format in ['f','g', 'H', 'h', 'M', 'm', 'n', 'O', 'o','k']:
if format in ['f','g', 'H', 'h', 'M', 'm', 'n', 'O', 'o']:
split_parts = author_list.split('; ')
return self.author_sep.join(split_parts)
# only last names are displayed here
if format in ['H', 'h']:
split_parts = author_list.split('; ')
return self.author_sep.join(split_parts)
# formats that have a comma between last name and first/middle names
# so that each are author is two elements
# so that each author is two elements
# 12/19 changed the author separator in cls to semicolon, and now can split and join
if format in ['A','a','e','G','I','i','L','l','N']:
if format in ['A','a','G','I','i','L','l','N']:
split_parts = author_list.split('; ')
return self.author_sep.join(split_parts)
return author_list
Expand All @@ -466,21 +474,24 @@ def __get_author_list_abbreviated(self, author_list, num_authors, format, m):
"""
Formats First Author Second Author.. Before Last abbreviated
A As in db As in db and first author,..., m authors and xx colleagues
a As in db As in db & first author,..., m authors et al.
E lastname fi lastname fi first author,..., m authors et al
e lastname f.m. lastname f.m. and first author, and xx colleagues
f lastname lastname and first author \\emph{et al.}
G lastname f. i. lastname f. i. first author, et al.
g lastname, f.i. lastname, f.i. and first author, and xx colleagues
H lastname lastname and display requested number of authors
h lastname lastname &
I lastname, f. i. f. i. lastname and first author, and xx colleagues
L lastname, f. i. lastname, f. i. and first author, and xx colleagues
N lastname, f. i. lastname, f. i. first author, and xx colleagues
O f. i lastname f. i lastname and first author, and xx colleagures
l lastname, f. i. lastname, f. i. & first author, et al.
i lastname, f. i. f. i. lastname & first author, et al.
k firstname i lastname firstname i lastname & first author, et al.
L lastname, f. i. lastname, f. i. and first author, and xx colleagures
l lastname, f. i. lastname, f. i. & first author, et al. colleagues
M lastname lastname and first author, et al.
m lastname lastname & first author, et al.
N lastname, f. i. lastname, f. i. first author, and xx colleagues
n lastname +
a As in db As in db & first author,..., m authors et al.
g lastname, f.i. lastname, f.i. and first author, and xx colleagues
h lastname lastname and first author \\emph{et al.}
i lastname, f. i. f. i. lastname & first author, et al.
k firstname i lastname firstname i lastname & first author, et al.
O f. i lastname f. i lastname and first author, and xx
o f. i lastname f. i lastname & first author, et al.
n.m: Maximum number of entries in field (optional).
Expand All @@ -495,6 +506,7 @@ def __get_author_list_abbreviated(self, author_list, num_authors, format, m):
"""
format_etal = u'{}, et al.'
format_etal_no_comma = u'{} et al.'
format_etal_no_dot = u'{} et al'
format_n_authors = u'{}'
format_with_n_colleagues = u'{}, and {} colleagues'
format_escape_emph = u'{} \\emph{{et al.}}'
Expand All @@ -515,8 +527,13 @@ def __get_author_list_abbreviated(self, author_list, num_authors, format, m):
return format_with_n_colleagues.format(', '.join(authors[:m]), num_authors-m)
elif (format == 'O'):
return format_with_n_colleagues.format(', '.join(authors[:m]), num_authors-m)
if (format == 'E'):
# there are no commas between last and first/middle intitials, so to remove those
# send a separator different than comma, so that it can be used to separate authors after
# commas are removed
return format_etal_no_dot.format(self.__get_n_authors(author_list, m, u'', format, '; '))
if (format == 'G'):
# return n authors (LastName, first and middle initials) et. al. - list is seprated by comma
# return n authors (LastName, first and middle initials) et. al. - list is separated by comma
return format_etal.format(self.__get_n_authors(author_list, m, u'', format))
if (format == 'i'):
# here the first author is lastname comma first and middle initials
Expand Down
23 changes: 13 additions & 10 deletions exportsrv/tests/unittests/test_custom_format_functionality.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ def test_get_affiliation_list_limit(self):
def test_get_author_list(self):
# Optional parameters for author field: n.m
# If the number of authors in the list is larger than n, the list will be truncated and m authors are returned
custom_format = CustomFormat(custom_format=r'%A,%3.2A,%a,%3.2a,%G,%3.2G,%g,%3.2g,'
r'%H,%3.2H,%2.1H,%h,%3.2h,%I,%3.2I,%i,%3.2i,'
r'%L,%3.2L,%l,%3.2l,%M,%3.2M,%m,%3.2m,'
r'%N,%3.2N,%n,%3.2n,%e,%3.2e,%f,%3.2f,'
r'%O,%3.2O,%o,%3.2o,%k,%3.2k,'
r'%^A,%^a,%^G,%^g,%^H,%^h,%^I,%^i,%^L,%^l,%^M,%^m,%^N,%^n,%^e,%^f,'
r'%^O,%^o,%^k'
custom_format = CustomFormat(custom_format=r'%A,%3.2A,%a,%3.2a,%E,%3.2E,%e,%3.2e,'
r'%G,%3.2G,%g,%3.2g,%H,%3.2H,%2.1H,%h,%3.2h,'
r'%I,%3.2I,%i,%3.2i,%L,%3.2L,%l,%3.2l,'
r'%M,%3.2M,%m,%3.2m,%N,%3.2N,%n,%3.2n,'
r'%f,%3.2f,%O,%3.2O,%o,%3.2o,%k,%3.2k,'
r'%^A,%^a,%^E,%^e,%^G,%^g,%^H,%^h,%^I,%^i,%^L,%^l,%^M,%^m,%^N,%^n,'
r'%^f,%^O,%^o,%^k'
)
custom_format.set_json_from_solr(solrdata.data_3)

Expand All @@ -141,6 +141,10 @@ def test_get_author_list(self):
('%a', 'English, Jayanne, Taylor, A. R., Mashchenko, S. Y., Irwin, Judith A., Basu, Shantanu, & Johnstone, Doug'),
('%3.2a', 'English, Jayanne, Taylor, A. R., et al.'),
('%G', 'English, J., Taylor, A. R., Mashchenko, S. Y., Irwin, J. A., Basu, S., Johnstone, D.'),
('%E', 'English J, Taylor AR, Mashchenko SY, Irwin JA, Basu S, Johnstone D'),
('%3.2E', 'English J, Taylor AR et al'),
('%e', 'English, J., Taylor, A.R., Mashchenko, S.Y., Irwin, J.A., Basu, S., and Johnstone, D.'),
('%3.2e', 'English, J., Taylor, A.R., and 4 colleagues'),
('%3.2G', 'English, J., Taylor, A. R., et al.'),
('%g', 'English J., Taylor A. R., Mashchenko S. Y., Irwin J. A., Basu S., Johnstone D.'),
('%3.2g', 'English J., Taylor A. R., et al.'),
Expand All @@ -165,8 +169,6 @@ def test_get_author_list(self):
('%3.2N', 'English, J., Taylor, A. R., and 4 colleagues'),
('%n', 'English,+'),
('%3.2n', 'English,+'),
('%e', 'English, J., Taylor, A.R., Mashchenko, S.Y., Irwin, J.A., Basu, S., and Johnstone, D.'),
('%3.2e', 'English, J., Taylor, A.R., and 4 colleagues'),
('%f', 'English, Taylor, Mashchenko, Irwin, Basu, and Johnstone'),
('%3.2f', 'English, Taylor \\emph{et al.}'),
('%O', 'J. English, A. R. Taylor, S. Y. Mashchenko, J. A. Irwin, S. Basu, and D. Johnstone'),
Expand All @@ -177,6 +179,8 @@ def test_get_author_list(self):
('%3.2k', 'Jayanne English, A. R. Taylor, et al.'),
('%^A', 'English, Jayanne'),
('%^a', 'English, Jayanne'),
('%^E', 'English J'),
('%^e', 'English, J.'),
('%^G', 'English, J.'),
('%^g', 'English J.'),
('%^H', 'English'),
Expand All @@ -189,7 +193,6 @@ def test_get_author_list(self):
('%^m', 'English'),
('%^N', 'English, J.'),
('%^n', 'English'),
('%^e', 'English, J.'),
('%^f', 'English'),
('%^O', 'J. English'),
('%^o', 'J. English'),
Expand Down

0 comments on commit 812c3ea

Please sign in to comment.