Skip to content

Commit

Permalink
Fixes citation key generation when authors list has "and others" at t…
Browse files Browse the repository at this point in the history
…he end

#626
Remove the statement "and others" at the end of authors list in order to generate a correct citation key.
  • Loading branch information
morganteg committed Mar 25, 2023
1 parent 52eed3e commit ce07ba1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/main/java/org/jabref/logic/importer/AuthorListParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Optional;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.jabref.model.entry.Author;
import org.jabref.model.entry.AuthorList;

Expand Down Expand Up @@ -96,6 +97,9 @@ private static StringBuilder buildWithAffix(Collection<Integer> indexArray, List
public AuthorList parse(String listOfNames) {
Objects.requireNonNull(listOfNames);

// Handle the statement "and others" at the end, removing it
listOfNames = StringUtils.removeEndIgnoreCase(listOfNames.trim(), " AND OTHERS");

// Handle case names in order lastname, firstname and separated by ","
// E.g., Ali Babar, M., Dingsøyr, T., Lago, P., van der Vliet, H.
final boolean authorsContainAND = listOfNames.toUpperCase(Locale.ENGLISH).contains(" AND ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1150,4 +1150,11 @@ void generateKeyWithLowercaseAuthorWithVonAndLastname() {
entry.setField(StandardField.YEAR, "2021");
assertEquals("Brekel2021", generateKey(entry, "[auth][year]"));
}

@Test
void generateKeyCorrectKeyWithAndOthersAtTheEnd() {
BibEntry entry = createABibEntryAuthor("Alexander Artemenko and others");
entry.setField(StandardField.YEAR, "2019");
assertEquals("Artemenko2019", generateKey(entry, "[auth][year]"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ private static Stream<Arguments> data() {
Arguments.of("de la Vallée Poussin, J. C. G.", new Author("J. C. G.", "J. C. G.", "de la", "Vallée Poussin", null)),
Arguments.of("{K}ent-{B}oswell, E. S.", new Author("E. S.", "E. S.", null, "{K}ent-{B}oswell", null)),
Arguments.of("Uhlenhaut, N Henriette", new Author("N Henriette", "N. H.", null, "Uhlenhaut", null)),
Arguments.of("Nu{\\~{n}}ez, Jose", new Author("Jose", "J.", null, "Nu{\\~{n}}ez", null))
Arguments.of("Nu{\\~{n}}ez, Jose", new Author("Jose", "J.", null, "Nu{\\~{n}}ez", null)),
Arguments.of("Alexander Artemenko and others", new Author("Alexander", "A.", null, "Artemenko", null))
);
}

Expand Down

0 comments on commit ce07ba1

Please sign in to comment.