Skip to content

Commit

Permalink
Fix parsing of single Uppercase author last name (#11339)
Browse files Browse the repository at this point in the history
* Add test for author parsing with single letter lastname

* Fix AuthorListParser for single letter last names

* Fix CHANGELOG.md

---------

Co-authored-by: Oliver Kopp <[email protected]>
  • Loading branch information
Siedlerchr and koppor authored May 27, 2024
1 parent 6155551 commit e23d286
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We fixed an issue where a new entry was not added to the selected group [#8933](https://github.com/JabRef/jabref/issues/8933)
- We fixed an issue where the horizontal position of the Entry Preview inside the entry editor was not remembered across restarts [#11281](https://github.com/JabRef/jabref/issues/11281)
- We fixed an issue where the search index was not updated after linking PDF files. [#11317](https://github.com/JabRef/jabref/pull/11317)
- We fixed rendering of (first) author with a single letter surname. [forum#4330](https://discourse.jabref.org/t/correct-rendering-of-first-author-with-a-single-letter-surname/4330)
- We fixed an issue where the entry editor context menu was not shown correctly when JabRef is opened on a second, extended screen [#11323](https://github.com/JabRef/jabref/issues/11323), [#11174](https://github.com/JabRef/jabref/issues/11174)

### Removed
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/org/jabref/logic/importer/AuthorListParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private static String checkNamesCommaSeparated(String listOfNames) {
* @return Preformatted author name; <CODE>Optional.empty()</CODE> if author name is empty.
*/
private Optional<Author> getAuthor() {
List<Object> tokens = new ArrayList<>(); // initialization
List<Object> tokens = new ArrayList<>();
int vonStart = -1;
int lastStart = -1;
int commaFirst = -1;
Expand Down Expand Up @@ -267,10 +267,10 @@ private Optional<Author> getAuthor() {
}
}

// Second step: split name into parts (here: calculate indices
// of parts in 'tokens' Vector)
// Second step: split name into parts (here: calculate indices of parts in 'tokens' Vector)
if (tokens.isEmpty()) {
return Optional.empty(); // no author information
// no author information
return Optional.empty();
}

// the following negatives indicate absence of the corresponding part
Expand Down Expand Up @@ -364,9 +364,11 @@ private Optional<Author> getAuthor() {
String lastPart = lastPartStart < 0 ? null : concatTokens(tokens, lastPartStart, lastPartEnd, OFFSET_TOKEN, false);
String jrPart = jrPartStart < 0 ? null : concatTokens(tokens, jrPartStart, jrPartEnd, OFFSET_TOKEN, false);

if ((firstPart != null) && (lastPart != null) && lastPart.equals(lastPart.toUpperCase(Locale.ROOT)) && (lastPart.length() < 5)
if ((commaFirst < 0) && (firstPart != null) && (lastPart != null) && lastPart.equals(lastPart.toUpperCase(Locale.ROOT)) && (lastPart.length() < 5)
&& (Character.UnicodeScript.of(lastPart.charAt(0)) != Character.UnicodeScript.HAN)) {
// The last part is a small string in complete upper case, so interpret it as initial of the first name
// In case there is NO comma (e.g., Obama B) AND
// the last part is a small string in complete upper case,
// we interpret it as initial of the first name
// This is the case for example in "Smith SH" which we think of as lastname=Smith and firstname=SH
// The length < 5 constraint should allow for "Smith S.H." as input
return Optional.of(new Author(lastPart, lastPart, vonPart, firstPart, jrPart));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ private static Stream<Arguments> parseMultipleCorrectly() {
new Author("A.", "A.", null, "Ibarra", null),
new Author("J.", "J.", null, "Molla", null)
),
"I. Podadera, J. M. Carmona, A. Ibarra, and J. Molla")
"I. Podadera, J. M. Carmona, A. Ibarra, and J. Molla"),
Arguments.of(AuthorList.of(
new Author("Vivian", "V.", null, "U", null),
new Author("Thomas", "T.", null, "Lai", null)
),
"U, Vivian and Lai, Thomas"
)
);
}

Expand Down

0 comments on commit e23d286

Please sign in to comment.