Skip to content

Commit

Permalink
fix Ed is stripped in LaTeX formats
Browse files Browse the repository at this point in the history
  • Loading branch information
nooraangelva committed Jun 21, 2022
1 parent 54cd048 commit b239570
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
11 changes: 8 additions & 3 deletions inspire_utils/name.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ParsedName(object):
constants = _prepare_nameparser_constants()
"""The default constants configuration for `HumanName` to use for parsing all names."""

def __init__(self, name, constants=None):
def __init__(self, name, constants=None, without_titles=False):
"""Create a ParsedName instance.
Args:
Expand All @@ -79,15 +79,20 @@ def __init__(self, name, constants=None):
"""
if not constants:
constants = ParsedName.constants
if without_titles:
constants.titles = []

if isinstance(name, HumanName):
self._parsed_name = name
else:
self._parsed_name = HumanName(name, constants=constants)

if not self._parsed_name.first:
self._parsed_name.first = self._parsed_name.title
self._parsed_name.title = ''

self._parsed_name.capitalize()

if ',' not in name and (not self.first_list or (self.first_list and '.' not in self.first_list[-1])):
self.maybe_only_last_name = True
else:
Expand Down Expand Up @@ -474,7 +479,7 @@ def _update_name_variations_with_product(set_a, set_b):
return list(name_variations)


def format_name(name, initials_only=False):
def format_name(name, initials_only=False, without_titles=False):
"""Format a schema-compliant name string in a human-friendy format.
This is a convenience wrapper around :ref:`ParsedName`, which should be
Expand All @@ -492,4 +497,4 @@ def format_name(name, initials_only=False):
>>> format_name('Downey, Robert Jr.', initials_only=True)
u'R. Downey Jr.'
"""
return ParsedName.loads(name).pprint(initials_only)
return ParsedName(name=name, without_titles=without_titles).loads(name).pprint(initials_only)
13 changes: 13 additions & 0 deletions tests/test_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,19 @@ def test_parsed_name_initials():
assert expected == parsed_name.first_initials_list


@pytest.mark.parametrize(
"input_author_name,expected",
[("Lieber, Ed", "E. Lieber"),
('Lieber, Ed Viktor', "E. V. Lieber"),
('Lieber, Ed Jr.', "E. Lieber, Jr."),
('Lieber, Ed Victor Jr.', "E. V. Lieber, Jr."),
],
)
def test_format_author_name_with_initials_when_first_name_is_similar_to_title(input_author_name, expected):

assert expected == format_name(input_author_name, initials_only=True, without_titles=True)


def test_parsed_wrong_names_and_not_fail():
names = [
(u"Proffesor.M.", u"Proffesor.M."),
Expand Down

0 comments on commit b239570

Please sign in to comment.