-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes miss-parsed names in
AutomaticPersonsGroup
(#7228)
- Loading branch information
1 parent
1d783b4
commit 31ced14
Showing
6 changed files
with
167 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.jabref.model.groups; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
import org.jabref.model.entry.Author; | ||
import org.jabref.model.entry.AuthorList; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.entry.field.Field; | ||
import org.jabref.model.strings.LatexToUnicodeAdapter; | ||
|
||
/** | ||
* Matches based on a latex free last name in a specified field. The field is parsed as an author list and the last names are resolved of latex. | ||
*/ | ||
public class LastNameGroup extends KeywordGroup { | ||
public LastNameGroup(String groupName, GroupHierarchyType context, Field searchField, String lastName) { | ||
super(groupName, context, searchField, LatexToUnicodeAdapter.format(lastName), true); | ||
} | ||
|
||
static List<String> getAsLastNamesLatexFree(Field field, BibEntry bibEntry) { | ||
return bibEntry.getField(field).stream() | ||
.map(AuthorList::parse) | ||
.map(AuthorList::getAuthors) | ||
.flatMap(Collection::stream) | ||
.map(Author::getLastLatexFree) | ||
.flatMap(Optional::stream) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public boolean contains(BibEntry entry) { | ||
return getAsLastNamesLatexFree(getSearchField(), entry).stream().anyMatch(name -> name.equals(getSearchExpression())); | ||
} | ||
|
||
@Override | ||
public AbstractGroup deepCopy() { | ||
return new LastNameGroup(getName(), getHierarchicalContext(), getSearchField(), getSearchExpression()); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/test/java/org/jabref/model/groups/AutomaticPersonsGroupTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.jabref.model.groups; | ||
|
||
import java.util.Arrays; | ||
import java.util.stream.Collectors; | ||
|
||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.entry.field.StandardField; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.contains; | ||
import static org.hamcrest.Matchers.containsInAnyOrder; | ||
|
||
class AutomaticPersonsGroupTest { | ||
private static GroupTreeNode[] createPersonSubGroupFrom(String... lastNames) { | ||
return Arrays.stream(lastNames) | ||
.map(lastName -> | ||
new LastNameGroup(lastName, GroupHierarchyType.INDEPENDENT, StandardField.AUTHOR, lastName)) | ||
.map(GroupTreeNode::new) | ||
.collect(Collectors.toList()) | ||
.toArray(GroupTreeNode[]::new); | ||
} | ||
|
||
@Test | ||
void createSubgroupsFromCommaSeparatedLastNames() { | ||
BibEntry bibEntry = new BibEntry().withField(StandardField.AUTHOR, "Turing, Alan and Hopper, Grace"); | ||
var subgroups = new AutomaticPersonsGroup("", GroupHierarchyType.INDEPENDENT, StandardField.AUTHOR).createSubgroups(bibEntry); | ||
var expectedSubgroups = createPersonSubGroupFrom("Turing", "Hopper"); | ||
assertThat(subgroups, containsInAnyOrder(expectedSubgroups)); | ||
} | ||
|
||
@Test | ||
void createSubgroupsContainingSpaceSeparatedNames() { | ||
BibEntry bibEntry = new BibEntry().withField(StandardField.AUTHOR, "Alan Turing and Grace Hopper"); | ||
var subgroups = new AutomaticPersonsGroup("", GroupHierarchyType.INDEPENDENT, StandardField.AUTHOR).createSubgroups(bibEntry); | ||
var expectedSubgroups = createPersonSubGroupFrom("Turing", "Hopper"); | ||
assertThat(subgroups, containsInAnyOrder(expectedSubgroups)); | ||
} | ||
|
||
@Test | ||
void createSubgroupFromLatex() { | ||
BibEntry bibEntry = new BibEntry().withField(StandardField.AUTHOR, "Kurt G{\\\"{o}}del"); | ||
var subgroup = new AutomaticPersonsGroup("", GroupHierarchyType.INDEPENDENT, StandardField.AUTHOR).createSubgroups(bibEntry); | ||
var expectedSubgroup = createPersonSubGroupFrom("Gödel"); | ||
assertThat(subgroup, contains(expectedSubgroup)); | ||
} | ||
|
||
@Test | ||
void createSubgroupFromUnicode() { | ||
BibEntry bibEntry = new BibEntry().withField(StandardField.AUTHOR, "Kurt Gödel"); | ||
var subgroup = new AutomaticPersonsGroup("", GroupHierarchyType.INDEPENDENT, StandardField.AUTHOR).createSubgroups(bibEntry); | ||
var expectedSubgroup = createPersonSubGroupFrom("Gödel"); | ||
assertThat(subgroup, contains(expectedSubgroup)); | ||
} | ||
} |