Verified Owner
Top Inners Fields Constructors Methods
org.jabref.logic.importer

public Class AuthorListParser

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Arrays, .Collection, .HashSet, .List, .Locale, .Optional, .Set, java.util.regex.Matcher, .Pattern, java.util.stream.Collectors, org.jabref.logic.util.strings.StringUtil, org.jabref.model.entry.Author, .AuthorList, org.jspecify.annotations.NonNull

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static record
private static enum

Field Summary

Modifier and TypeField and Description
private static final Set<String>
private static final Pattern
private static final Pattern
private static final Pattern
private static final Pattern
private static final int
private static final int
private static final int
private String
original

the raw bibtex author/editor field

private static final Pattern
private static final Set<String>
private static final int
private int
tokenAbbrEnd

end of token abbreviation (always: tokenStart < tokenAbbrEnd <= tokenEnd), only valid if getToken returns Token.WORD

private boolean
tokenCase

true if upper-case token, false if lower-case

private int
tokenEnd

index of the end in original, for example to point to 'abc' in 'abc xyz', tokenEnd=5

private int
tokenStart

index of the start in original, for example to point to 'abc' in 'abc xyz', tokenStart=2

private char
tokenTerm

either space of dash

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static StringBuilder

Returns:

New string with correct separation
buildWithAffix
(Collection<Integer> indexArray, List<String> nameList)

Builds a new array of strings with stringbuilder.

private static String

Returns:

the original or patched version of listOfNames
checkNamesCommaSeparated
(String listOfNames)

Handle cases names in order Firstname Lastname, separated by "," and a final ", and " E.g, "I.

private String

Returns:

the result of concatenation.
concatTokens
(List<Object> tokens, int
index of the first token to be concatenated in 'tokens' Vector (always divisible by TOKEN_GROUP_LENGTH).
start
,
int
index of the first token not to be concatenated in 'tokens' Vector (always divisible by TOKEN_GROUP_LENGTH).
end
,
int
offset within token group (used to request concatenation of either full tokens or abbreviation).
offset
,
boolean
true`` -- add period after each token, false` do not add.
dotAfter
)

Concatenates list of tokens from 'tokens' Vector.

private Optional<Author>

Returns:

Preformatted author name; Optional.empty() if author name is empty.
getAuthor
()

Parses one author name and returns preformatted information.

private static AuthorListParser.SimpleNormalFormResult
private AuthorListParser.Token

Returns:

Token.EOF -- no more tokens, Token.COMMA -- token is comma, Token.AND -- token is the word "and" (or "And", or "aND", etc.) or a semicolon, Token.WORD -- token is a word; additional information is given in global variables token_start, token_end, token_abbr, token_term, and token_case.
getToken
()

Parses the next token.

public static Optional<String>

Returns:

Optional.empty if there was no normalization.
normalizeSimply
(String listOfNames)

Tries to get a simple BibTeX author list of the given string.

public AuthorList

Returns:

a parsed list of persons
parse
(@NonNull String
the String containing the person names to be parsed
listOfNames
)

Parses the String containing person names and returns a list of person information.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

AVOID_TERMS_IN_LOWER_CASEback to summary
private static final Set<String> AVOID_TERMS_IN_LOWER_CASE
COMMA_SEPARATORback to summary
private static final Pattern COMMA_SEPARATOR
ET_AL_SUFFIXback to summary
private static final Pattern ET_AL_SUFFIX
MULTIPLE_SPACE_PATTERNback to summary
private static final Pattern MULTIPLE_SPACE_PATTERN
NEW_LINE_PATTERNback to summary
private static final Pattern NEW_LINE_PATTERN
OFFSET_TOKENback to summary
private static final int OFFSET_TOKEN
OFFSET_TOKEN_ABBRback to summary
private static final int OFFSET_TOKEN_ABBR
OFFSET_TOKEN_TERMback to summary
private static final int OFFSET_TOKEN_TERM
originalback to summary
private String original

the raw bibtex author/editor field

STARTS_WITH_CAPITAL_LETTER_DOT_OR_DASHback to summary
private static final Pattern STARTS_WITH_CAPITAL_LETTER_DOT_OR_DASH
TEX_NAMESback to summary
private static final Set<String> TEX_NAMES
TOKEN_GROUP_LENGTHback to summary
private static final int TOKEN_GROUP_LENGTH
tokenAbbrEndback to summary
private int tokenAbbrEnd

end of token abbreviation (always: tokenStart < tokenAbbrEnd <= tokenEnd), only valid if getToken returns Token.WORD

tokenCaseback to summary
private boolean tokenCase

true if upper-case token, false if lower-case

tokenEndback to summary
private int tokenEnd

index of the end in original, for example to point to 'abc' in 'abc xyz', tokenEnd=5

tokenStartback to summary
private int tokenStart

index of the start in original, for example to point to 'abc' in 'abc xyz', tokenStart=2

tokenTermback to summary
private char tokenTerm

either space of dash

Constructor Detail

AuthorListParserback to summary
public AuthorListParser()

Method Detail

buildWithAffixback to summary
private static StringBuilder buildWithAffix(Collection<Integer> indexArray, List<String> nameList)

Builds a new array of strings with stringbuilder. Regarding to the name affixes.

Returns:StringBuilder

New string with correct separation

checkNamesCommaSeparatedback to summary
private static String checkNamesCommaSeparated(String listOfNames)

Handle cases names in order Firstname Lastname, separated by "," and a final ", and " E.g, "I. Podadera, J. M. Carmona, A. Ibarra, and J. Molla"

Returns:String

the original or patched version of listOfNames

concatTokensback to summary
private String concatTokens(List<Object> tokens, int start, int end, int offset, boolean dotAfter)

Concatenates list of tokens from 'tokens' Vector. Tokens are separated by spaces or dashes, depending on stored in 'tokens'. Callers always ensure that start < end; thus, there exists at least one token to be concatenated.

Parameters
start:int

index of the first token to be concatenated in 'tokens' Vector (always divisible by TOKEN_GROUP_LENGTH).

end:int

index of the first token not to be concatenated in 'tokens' Vector (always divisible by TOKEN_GROUP_LENGTH).

offset:int

offset within token group (used to request concatenation of either full tokens or abbreviation).

dotAfter:boolean

true`` -- add period after each token, false` do not add.

Returns:String

the result of concatenation.

getAuthorback to summary
private Optional<Author> getAuthor()

Parses one author name and returns preformatted information.

Returns:Optional<Author>

Preformatted author name; Optional.empty() if author name is empty.

getSimpleNormalFormback to summary
private static AuthorListParser.SimpleNormalFormResult getSimpleNormalForm(String listOfNames)
getTokenback to summary
private AuthorListParser.Token getToken()

Parses the next token.

The string being parsed is stored in global variable original, and position which parsing has to start from is stored in global variable token_end; thus, token_end has to be set to 0 before the first invocation. Procedure updates token_end; thus, subsequent invocations do not require any additional variable settings.

The type of the token is returned; if it is Token.WORD, additional information is given in global variables token_start, token_end, token_abbr, token_term, and token_case; namely: original.substring(token_start,token_end) is the text of the token, original.substring(token_start,token_abbr) is the token abbreviation, token_term contains token terminator (space or dash), and token_case is true, if token is upper-case and false if token is lower-case.

Returns:AuthorListParser.Token

Token.EOF -- no more tokens, Token.COMMA -- token is comma, Token.AND -- token is the word "and" (or "And", or "aND", etc.) or a semicolon, Token.WORD -- token is a word; additional information is given in global variables token_start, token_end, token_abbr, token_term, and token_case.

normalizeSimplyback to summary
public static Optional<String> normalizeSimply(String listOfNames)

Tries to get a simple BibTeX author list of the given string.

This is an intermediate step in parse. Since parse does not work in all cases, this method can be used to get more valid BibTeX.

Returns:Optional<String>

Optional.empty if there was no normalization.

parseback to summary
public AuthorList parse(@NonNull String listOfNames)

Parses the String containing person names and returns a list of person information.

Parameters
listOfNames:@NonNull String

the String containing the person names to be parsed

Returns:AuthorList

a parsed list of persons

org.jabref.logic.importer back to summary

private final Record AuthorListParser.SimpleNormalFormResult

extends Record
Class Inheritance
Record Components
authors:String 
andOthersPresent:boolean 

Field Summary

Modifier and TypeField and Description
private final boolean
andOthersPresent

Record Component accessed by andOthersPresent().

private final String
authors

Record Component accessed by authors().

Constructor Summary

AccessConstructor and Description
private
SimpleNormalFormResult(String authors, boolean andOthersPresent)

Method Summary

Modifier and TypeMethod and Description
public boolean
andOthersPresent()

Record Component getter of andOthersPresent.

public String
authors()

Record Component getter of authors.

public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

andOthersPresentback to summary
private final boolean andOthersPresent

Record Component accessed by andOthersPresent().

authorsback to summary
private final String authors

Record Component accessed by authors().

Constructor Detail

SimpleNormalFormResultback to summary
private SimpleNormalFormResult(String authors, boolean andOthersPresent)

Method Detail

andOthersPresentback to summary
public boolean andOthersPresent()

Record Component getter of andOthersPresent.

authorsback to summary
public String authors()

Record Component getter of authors.

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

org.jabref.logic.importer back to summary

private final Enum AuthorListParser.Token

extends Enum<AuthorListParser.Token>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final AuthorListParser.Token
public static final AuthorListParser.Token
public static final AuthorListParser.Token
public static final AuthorListParser.Token

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static AuthorListParser.Token
public static AuthorListParser.Token[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ANDback to summary
public static final AuthorListParser.Token AND
COMMAback to summary
public static final AuthorListParser.Token COMMA
EOFback to summary
public static final AuthorListParser.Token EOF
WORDback to summary
public static final AuthorListParser.Token WORD

Constructor Detail

Tokenback to summary
private Token()

Method Detail

valueOfback to summary
public static AuthorListParser.Token valueOf(String name)
valuesback to summary
public static AuthorListParser.Token[] values()