Skip to content

Commit

Permalink
Rename to modern terms
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor committed Mar 17, 2024
1 parent 856cf83 commit 92a2024
Show file tree
Hide file tree
Showing 17 changed files with 170 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,28 @@ public String toString(Author author) {
if (autoCompLF) {
switch (autoCompleteFirstNameMode) {
case ONLY_ABBREVIATED:
return author.getLastFirst(true);
return author.getFamilyGiven(true);
case ONLY_FULL:
return author.getLastFirst(false);
return author.getFamilyGiven(false);
case BOTH:
return author.getLastFirst(true);
return author.getFamilyGiven(true);
default:
break;
}
}
if (autoCompFF) {
switch (autoCompleteFirstNameMode) {
case ONLY_ABBREVIATED:
return author.getFirstLast(true);
return author.getGivenFamily(true);
case ONLY_FULL:
return author.getFirstLast(false);
return author.getGivenFamily(false);
case BOTH:
return author.getFirstLast(true);
return author.getGivenFamily(true);
default:
break;
}
}
return author.getLastOnly();
return author.getNamePrefixAndFamilyName();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Stream<Author> getAuthors(BibEntry entry) {

@Override
protected Equivalence<Author> getEquivalence() {
return Equivalence.equals().onResultOf(Author::getLastOnly);
return Equivalence.equals().onResultOf(Author::getNamePrefixAndFamilyName);
}

@Override
Expand All @@ -58,7 +58,7 @@ protected Comparator<Author> getComparator() {

@Override
protected boolean isMatch(Author candidate, AutoCompletionBinding.ISuggestionRequest request) {
return StringUtil.containsIgnoreCase(candidate.getLastFirst(false), request.getUserText());
return StringUtil.containsIgnoreCase(candidate.getFamilyGiven(false), request.getUserText());
}

@Override
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/org/jabref/logic/bst/util/BstNameFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,10 @@ public static String formatName(Author author, String format) {
char type = control.charAt(0);

Optional<String> tokenS = switch (type) {
case 'f' ->
author.getFirst();
case 'v' ->
author.getVon();
case 'l' ->
author.getLast();
case 'j' ->
author.getJr();
case 'f' -> author.getGivenName();
case 'v' -> author.getNamePrefix();
case 'l' -> author.getFamilyName();
case 'j' -> author.getNameSuffix();
default ->
throw new BstVMException("Internal error");
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,17 +526,17 @@ private static AuthorList createAuthorList(String unparsedAuthors) {
return AuthorList.parse(unparsedAuthors).getAuthors().stream()
.map(author -> {
// If the author is an institution, use an institution key instead of the full name
String lastName = author.getLast()
String lastName = author.getFamilyName()
.map(lastPart -> isInstitution(author) ?
generateInstitutionKey(lastPart) :
LatexToUnicodeAdapter.format(lastPart))
.orElse(null);
return new Author(
author.getFirst().map(LatexToUnicodeAdapter::format).orElse(null),
author.getFirstAbbr().map(LatexToUnicodeAdapter::format).orElse(null),
author.getVon().map(LatexToUnicodeAdapter::format).orElse(null),
author.getGivenName().map(LatexToUnicodeAdapter::format).orElse(null),
author.getGivenNameAbbreviated().map(LatexToUnicodeAdapter::format).orElse(null),
author.getNamePrefix().map(LatexToUnicodeAdapter::format).orElse(null),
lastName,
author.getJr().map(LatexToUnicodeAdapter::format).orElse(null));
author.getNameSuffix().map(LatexToUnicodeAdapter::format).orElse(null));
})
.collect(AuthorList.collect());
}
Expand All @@ -548,9 +548,9 @@ private static AuthorList createAuthorList(String unparsedAuthors) {
* @return true if only the last name is present and it contains at least one whitespace character.
*/
private static boolean isInstitution(Author author) {
return author.getFirst().isEmpty() && author.getFirstAbbr().isEmpty() && author.getJr().isEmpty()
&& author.getVon().isEmpty() && author.getLast().isPresent()
&& WHITESPACE.matcher(author.getLast().get()).find();
return author.getGivenName().isEmpty() && author.getGivenNameAbbreviated().isEmpty() && author.getNameSuffix().isEmpty()
&& author.getNamePrefix().isEmpty() && author.getFamilyName().isPresent()
&& WHITESPACE.matcher(author.getFamilyName().get()).find();
}

/**
Expand Down Expand Up @@ -765,7 +765,7 @@ private static String keepLettersAndDigitsOnly(String in) {
private static String firstAuthor(AuthorList authorList) {
return authorList.getAuthors().stream()
.findFirst()
.flatMap(author -> author.getLast().isPresent() ? author.getLast() : author.getVon())
.flatMap(author -> author.getFamilyName().isPresent() ? author.getFamilyName() : author.getNamePrefix())
.orElse("");
}

Expand All @@ -779,7 +779,7 @@ private static String firstAuthor(AuthorList authorList) {
private static String firstAuthorForenameInitials(AuthorList authorList) {
return authorList.getAuthors().stream()
.findFirst()
.flatMap(Author::getFirstAbbr)
.flatMap(Author::getGivenNameAbbreviated)
.map(s -> s.substring(0, 1))
.orElse("");
}
Expand All @@ -793,7 +793,7 @@ private static String firstAuthorForenameInitials(AuthorList authorList) {
*/
private static String firstAuthorVonAndLast(AuthorList authorList) {
return authorList.isEmpty() ? "" :
authorList.getAuthor(0).getLastOnly().replace(" ", "");
authorList.getAuthor(0).getNamePrefixAndFamilyName().replace(" ", "");
}

/**
Expand All @@ -806,7 +806,7 @@ private static String lastAuthor(AuthorList authorList) {
if (authorList.isEmpty()) {
return "";
}
return authorList.getAuthors().get(authorList.getNumberOfAuthors() - 1).getLast().orElse("");
return authorList.getAuthors().get(authorList.getNumberOfAuthors() - 1).getFamilyName().orElse("");
}

/**
Expand All @@ -820,7 +820,7 @@ private static String lastAuthorForenameInitials(AuthorList authorList) {
if (authorList.isEmpty()) {
return "";
}
return authorList.getAuthor(authorList.getNumberOfAuthors() - 1).getFirstAbbr().map(s -> s.substring(0, 1))
return authorList.getAuthor(authorList.getNumberOfAuthors() - 1).getGivenNameAbbreviated().map(s -> s.substring(0, 1))
.orElse("");
}

Expand Down Expand Up @@ -857,7 +857,7 @@ static String authorsAlpha(AuthorList authorList) {
}

if (authorList.getNumberOfAuthors() == 1) {
String[] firstAuthor = authorList.getAuthor(0).getLastOnly()
String[] firstAuthor = authorList.getAuthor(0).getNamePrefixAndFamilyName()
.replaceAll("\\s+", " ").trim().split(" ");
// take first letter of any "prefixes" (e.g. van der Aalst -> vd)
for (int j = 0; j < (firstAuthor.length - 1); j++) {
Expand All @@ -873,7 +873,7 @@ static String authorsAlpha(AuthorList authorList) {
}
List<String> vonAndLastNames = authorList.getAuthors().stream()
.limit(maxAuthors)
.map(Author::getLastOnly)
.map(Author::getNamePrefixAndFamilyName)
.collect(Collectors.toList());
for (String vonAndLast : vonAndLastNames) {
// replace all whitespaces by " "
Expand Down Expand Up @@ -913,7 +913,7 @@ private static String joinAuthorsOnLastName(AuthorList authorList, int maxAuthor
return Optional.of(suffix);
}
} else {
return author.getLast();
return author.getFamilyName();
}
})
.flatMap(Optional::stream)
Expand Down Expand Up @@ -970,7 +970,7 @@ static String authEtal(AuthorList authorList, String delim, String append) {
// exception: If the second author is "and others", then do the appendix handling (in the other branch)
return joinAuthorsOnLastName(authorList, 2, delim, "");
} else {
return authorList.getAuthor(0).getLast().orElse("") + append;
return authorList.getAuthor(0).getFamilyName().orElse("") + append;
}
}

Expand All @@ -990,7 +990,7 @@ private static String authNofMth(AuthorList authorList, int n, int m) {
if (lastAuthor.equals(Author.OTHERS)) {
return "+";
}
String lastName = lastAuthor.getLast()
String lastName = lastAuthor.getFamilyName()
.map(CitationKeyGenerator::removeDefaultUnwantedCharacters).orElse("");
return lastName.length() > n ? lastName.substring(0, n) : lastName;
}
Expand All @@ -1010,7 +1010,7 @@ static String authShort(AuthorList authorList) {
final int numberOfAuthors = authorList.getNumberOfAuthors();

if (numberOfAuthors == 1) {
author.append(authorList.getAuthor(0).getLast().orElse(""));
author.append(authorList.getAuthor(0).getFamilyName().orElse(""));
} else if (numberOfAuthors >= 2) {
for (int i = 0; (i < numberOfAuthors) && (i < 3); i++) {
author.append(authNofMth(authorList, 1, i + 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public URL getURLForEntry(BibEntry entry) throws URISyntaxException, MalformedUR
// replace "and" by ";" as citation matching API uses ";" for separation
AuthorList authors = AuthorList.parse(entry.getFieldOrAlias(StandardField.AUTHOR).get());
String authorsWithSemicolon = authors.getAuthors().stream()
.map(author -> author.getLastFirst(false))
.map(author -> author.getFamilyGiven(false))
.collect(Collectors.joining(";"));
uriBuilder.addParameter("a", authorsWithSemicolon);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public String format(String fieldText) {
}
Author first = a.getAuthor(0);
StringBuilder sb = new StringBuilder();
sb.append(first.getLastFirst(true));
sb.append(first.getFamilyGiven(true));
for (int i = 1; i < a.getNumberOfAuthors(); i++) {
sb.append(", ").append(a.getAuthor(i).getFirstLast(true));
sb.append(", ").append(a.getAuthor(i).getGivenFamily(true));
}
return sb.toString();
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/org/jabref/logic/layout/format/Authors.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,21 +254,21 @@ public String format(String fieldText) {

private void addSingleName(StringBuilder sb, Author a, boolean firstFirst) {
StringBuilder lastNameSB = new StringBuilder();
a.getVon().filter(von -> !von.isEmpty()).ifPresent(von -> lastNameSB.append(von).append(' '));
a.getLast().ifPresent(lastNameSB::append);
a.getNamePrefix().filter(von -> !von.isEmpty()).ifPresent(von -> lastNameSB.append(von).append(' '));
a.getFamilyName().ifPresent(lastNameSB::append);
String jrSeparator = " ";
a.getJr().filter(jr -> !jr.isEmpty()).ifPresent(jr -> lastNameSB.append(jrSeparator).append(jr));
a.getNameSuffix().filter(jr -> !jr.isEmpty()).ifPresent(jr -> lastNameSB.append(jrSeparator).append(jr));

String firstNameResult = "";
if (a.getFirst().isPresent()) {
if (a.getGivenName().isPresent()) {
if (abbreviate) {
firstNameResult = a.getFirstAbbr().orElse("");
firstNameResult = a.getGivenNameAbbreviated().orElse("");

if (firstInitialOnly && (firstNameResult.length() > 2)) {
firstNameResult = firstNameResult.substring(0, 2);
} else if (middleInitial) {
String abbr = firstNameResult;
firstNameResult = a.getFirst().get();
firstNameResult = a.getGivenName().get();
int index = firstNameResult.indexOf(' ');
if (index >= 0) {
firstNameResult = firstNameResult.substring(0, index + 1);
Expand All @@ -284,7 +284,7 @@ private void addSingleName(StringBuilder sb, Author a, boolean firstFirst) {
firstNameResult = firstNameResult.replace(" ", "");
}
} else {
firstNameResult = a.getFirst().get();
firstNameResult = a.getGivenName().get();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ public void addBody(StringBuilder sb, AuthorList al, String tagName, DocBookVers
sb.append("<personname>");
}
Author a = al.getAuthor(i);
a.getFirst().filter(first -> !first.isEmpty()).ifPresent(first -> sb.append("<firstname>")
.append(XML_CHARS.format(first)).append("</firstname>"));
a.getVon().filter(von -> !von.isEmpty()).ifPresent(von -> sb.append("<othername>")
.append(XML_CHARS.format(von)).append("</othername>"));
a.getLast().filter(last -> !last.isEmpty()).ifPresent(last -> {
a.getGivenName().filter(first -> !first.isEmpty()).ifPresent(first -> sb.append("<firstname>")
.append(XML_CHARS.format(first)).append("</firstname>"));
a.getNamePrefix().filter(von -> !von.isEmpty()).ifPresent(von -> sb.append("<othername>")
.append(XML_CHARS.format(von)).append("</othername>"));
a.getFamilyName().filter(last -> !last.isEmpty()).ifPresent(last -> {
sb.append("<surname>").append(XML_CHARS.format(last));
a.getJr().filter(jr -> !jr.isEmpty())
a.getNameSuffix().filter(jr -> !jr.isEmpty())
.ifPresent(jr -> sb.append(' ').append(XML_CHARS.format(jr)));
sb.append("</surname>");
if (version == DocBookVersion.DOCBOOK_5) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/jabref/logic/msbib/MsBibAuthor.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public MsBibAuthor(Author author) {
this.author = author;

StringBuilder sb = new StringBuilder();
author.getFirst().ifPresent(firstNames -> {
author.getGivenName().ifPresent(firstNames -> {

String[] names = firstNames.split(" ");
for (int i = 1; i < names.length; i++) {
Expand All @@ -37,7 +37,7 @@ public String getFirstName() {
if (!"".equals(firstName)) {
return firstName;
}
return author.getFirst().orElse(null);
return author.getGivenName().orElse(null);
}

public String getMiddleName() {
Expand All @@ -48,15 +48,15 @@ public String getMiddleName() {
}

public String getLastName() {
return REMOVE_BRACES_FORMATTER.format(author.getLastOnly());
return REMOVE_BRACES_FORMATTER.format(author.getNamePrefixAndFamilyName());
}

public String getFirstLast() {
return author.getFirstLast(false);
return author.getGivenFamily(false);
}

public String getLastFirst() {
return author.getLastFirst(false);
return author.getFamilyGiven(false);
}

public boolean isCorporate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ private static String getAuthorLastName(AuthorList authorList, int number) {
if (authorList.getNumberOfAuthors() > number) {
Author author = authorList.getAuthor(number);
// "von " if von exists
Optional<String> von = author.getVon();
Optional<String> von = author.getNamePrefix();
if (von.isPresent() && !von.get().isEmpty()) {
stringBuilder.append(von.get());
stringBuilder.append(' ');
}
// last name if it exists
stringBuilder.append(author.getLast().map(last -> REMOVE_BRACES_FORMATTER.format(last)).orElse(""));
stringBuilder.append(author.getFamilyName().map(last -> REMOVE_BRACES_FORMATTER.format(last)).orElse(""));
}

return stringBuilder.toString();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/logic/xmp/DublinCoreExtractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public Optional<BibEntry> extractBibtexEntry() {
private void fillContributor(String authors) {
AuthorList list = AuthorList.parse(authors);
for (Author author : list.getAuthors()) {
dcSchema.addContributor(author.getFirstLast(false));
dcSchema.addContributor(author.getGivenFamily(false));
}
}

Expand All @@ -309,7 +309,7 @@ private void fillContributor(String authors) {
private void fillCreator(String creators) {
AuthorList list = AuthorList.parse(creators);
for (Author author : list.getAuthors()) {
dcSchema.addCreator(author.getFirstLast(false));
dcSchema.addCreator(author.getGivenFamily(false));
}
}

Expand Down
Loading

0 comments on commit 92a2024

Please sign in to comment.