Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

considering multiple spaces as separate user block by replacing it with " and " #12757

Merged
merged 12 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We added an integrity check if a URL appears in a title. [#12354](https://github.com/JabRef/jabref/issues/12354)
- We added a feature for enabling drag-and-drop of files into groups [#12540](https://github.com/JabRef/jabref/issues/12540)
- We added support for reordering keywords via drag and drop, automatic alphabetical ordering, and improved pasting and editing functionalities in the keyword editor. [#10984](https://github.com/JabRef/jabref/issues/10984)
- We added a new functionality where author names having multiple spaces in-between will be considered as separate user block as it does for " and ". [#12701](https://github.com/JabRef/jabref/issues/12701)

### Changed

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/jabref/logic/importer/AuthorListParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public class AuthorListParser {

private static final Pattern STARTS_WITH_CAPITAL_LETTER_DOT_OR_DASH = Pattern.compile("^[A-Z](\\.[ -]| ?-)");

private static final Pattern MULTIPLE_SPACE_PATTERN = Pattern.compile("\\s{2,}");

private static final Pattern NEW_LINE_PATTERN = Pattern.compile("\\s*\\n\\s*");

/**
* the raw bibtex author/editor field
*/
Expand Down Expand Up @@ -100,6 +104,10 @@ private record SimpleNormalFormResult(String authors, boolean andOthersPresent)

private static SimpleNormalFormResult getSimpleNormalForm(String listOfNames) {
listOfNames = listOfNames.replace(" -", "-").trim();
if (!listOfNames.contains(",") && (MULTIPLE_SPACE_PATTERN.matcher(listOfNames).find() || listOfNames.contains("\n"))) {
listOfNames = NEW_LINE_PATTERN.matcher(listOfNames).replaceAll(" and ");
listOfNames = MULTIPLE_SPACE_PATTERN.matcher(listOfNames).replaceAll(" and ");
}

// Handling of "and others"
// Remove it from the list; it will be added at the very end of this method as special Author.OTHERS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,37 @@ private static Stream<Arguments> parseMultipleCorrectly() {
new Author("Thomas", "T.", null, "Lai", null)
),
"U, Vivian and Lai, Thomas"
)
),
Arguments.of(
AuthorList.of(
new Author("I.", "I.", null, "Podadera", null),
new Author("J. M.", "J. M.", null, "Carmona", null),
new Author("A.", "A.", null, "Ibarra", null),
new Author("J.", "J.", null, "Molla", null)
),
"I. Podadera J. M. Carmona A. Ibarra J. Molla"),
Arguments.of(
AuthorList.of(
new Author("Alexander", "A.", null, "Artemenko", null),
new Author("I.", "I.", null, "Podadera", null),
new Author("J. M.", "J. M.", null, "Carmona", null)
),
"""
Alexander Artemenko
I. Podadera
J. M. Carmona
"""),
Arguments.of(
AuthorList.of(
new Author("First1", "F.", null, "Last1", null),
new Author("First2", "F.", null, "Last2", null),
new Author("First3", "F.", null, "Last3", null)
),
"""
First1 Last1
First2 Last2
First3 Last3
""")
);
}

Expand Down
Loading