Verified Owner
Top Description Inners Fields Constructors Methods
org.jabref.logic.citationkeypattern

public Class BracketedPattern

extends Object
Class Inheritance
Known Direct Subclasses
org.jabref.logic.citationkeypattern.CitationKeyGenerator
Imports
java.math.BigInteger, java.util.ArrayList, .Arrays, .Comparator, .EnumSet, .Iterator, .List, .Locale, .Map, .Objects, .Optional, .Scanner, .StringJoiner, java.util.function.Function, .Predicate, java.util.regex.Matcher, .Pattern, java.util.stream.Collectors, org.jabref.logic.formatter.Formatter, .Formatters, org.jabref.logic.formatter.bibtexfields.RemoveEnclosingBracesFormatter, org.jabref.logic.formatter.casechanger.Word, org.jabref.logic.integrity.PagesChecker, org.jabref.logic.layout.format.RemoveLatexCommandsFormatter, org.jabref.logic.util.strings.StringUtil, org.jabref.model.database.BibDatabase, org.jabref.model.entry.Author, .AuthorList, .BibEntry, .Keyword, .KeywordList, org.jabref.model.entry.field.FieldFactory, .InternalField, .StandardField, org.jabref.model.strings.LatexToUnicodeAdapter, com.google.common.annotations.VisibleForTesting, org.jspecify.annotations.NonNull, .Nullable, org.slf4j.Logger, .LoggerFactory

This class provides methods to expand bracketed expressions, such as [year]_[author]_[firstpage], using information from a provided BibEntry. The above-mentioned expression would yield 2017_Kitsune_123 when expanded using the BibTeX entry @Article{ authors = {O. Kitsune}, year = {2017}, pages={123-6}}.

The embedding in JabRef is explained at Customize the citation key generator.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum

Field Summary

Modifier and TypeField and Description
private static final int
CHARS_OF_FIRST

The maximum number of characters in the first author's last name.

private static final Pattern
DEPARTMENTS

Matches with "dep"/"dip", case-insensitive

private static final Pattern
private static final RemoveEnclosingBracesFormatter
private static final Pattern
INLINE_ABBREVIATION

Matches uppercase english letters between "({" and "})", which should be used to abbreviate the name of an institution

private static final Logger
private static final int
MAX_ALPHA_AUTHORS

The maximum number of name abbreviations that can be used.

private static final Pattern
NOT_CAPITAL_CHARACTER

Matches everything that is not an uppercase ASCII letter.

private static final Pattern
private final String
private static final Map<Character, Integer>
private static final Pattern

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
pack-priv static String

Returns:

the surname of all authors/editors
allAuthors
(AuthorList authorList)

Gets the last name of all authors/editors.

private static void
appendQuote(StringBuilder
the StringBuilder to which tokens will be appended
stringBuilder
,
Iterator<String>
the tokenizer producing the tokens
tokenizer
)

Appends the content between, and including, two " to the provided StringBuilder.

pack-priv static String

Returns:

The modified label.
applyModifiers
(final String
The generated label.
label
,
final List<String>
String array containing the modifiers.
parts
,
final int
The number of initial items in the modifiers array to skip.
offset
,
Function<String, String>
a function to expand the content in the parentheses.
expandBracketContent
)

Applies modifiers to a label generated based on a field marker.

pack-priv static String
authAuthEa(AuthorList authorList)

pack-priv static String
authEtal(AuthorList authorList, String delim, String append)

auth.etal, authEtAl, ...

pack-priv static String
authIniN(AuthorList
The authors to format.
authorList
,
int
The maximum number of characters this string will be long. A negative number or zero will lead to "" be returned.
n
)

authIniN format

private static String
authN(AuthorList authorList, int num)

First N chars of the first author's last name.

private static String
authNofMth(AuthorList authorList, int n, int m)

The first N characters of the Mth author's or editor's last name.

public static String

Returns:

the initials of all authors' names
authorsAlpha
(AuthorList authorList)

Returns the authors according to the BibTeX-alpha-Style

public static String

Returns:

the initials of all authors' names
authorsAlphaLNI
(AuthorList authorList)

Returns the authors according to the BibTeX LNI template Examples: Examples from the tmplate Also see discussion at the pull request that introduced this.

pack-priv static String
authShort(AuthorList authorList)

authshort format

public static String
camelizeSignificantWordsInTitle(String title)

Capitalises the significant words of the "title" field in the given BibTeX entry

private static String
private static String
camelizeTitle_N(String title, int number)

private static String

Returns:

the content enclosed by brackets
contentBetweenBrackets
(Iterator<String>
the tokenizer producing the tokens
tokenizer
,
final String
pattern used by expandBrackets, used for logging
pattern
)

Returns the content enclosed between brackets, including enclosed quotes, and excluding the paired enclosing brackets.

private static AuthorList

Returns:

an AuthorList consisting of authors and institution keys with resolved latex.
createAuthorList
(String
a string representation of authors or editors
unparsedAuthors
)

Parses the provided string to an AuthorList, which are then formatted by LatexToUnicodeAdapter.

public String
expand(BibEntry bibentry)

public String

Returns:

The expanded pattern. The empty string is returned, if it could not be expanded.
expand
(@NonNull BibEntry
The bibentry to expand.
bibentry
,
BibDatabase
The database to use for string-lookups and cross-refs. May be null.
database
)

Expands the current pattern using the given bibentry and database.

public String

Returns:

The expanded pattern. The empty string is returned, if it could not be expanded.
expand
(@NonNull BibEntry
The bibentry to expand.
bibentry
,
Character
The keyword delimiter to use.
keywordDelimiter
,
BibDatabase
The database to use for string-lookups and cross-refs. May be null.
database
)

Expands the current pattern using the given bibentry, keyword delimiter, and database.

public static Function<String, String>

Returns:

a function accepting a bracketed expression and returning the result of expanding it
expandBracketContent
(Character
The keyword delimiter to use
keywordDelimiter
,
BibEntry
The BibEntry to use for expansion
entry
,
BibDatabase
The BibDatabase for field resolving. May be null.
database
)

Utility method creating a function taking the string representation of the content of a bracketed expression and expanding it.

public static String

Returns:

The expanded pattern. Not null.
expandBrackets
(@NonNull String
The pattern to expand
pattern
,
Character
The keyword delimiter to use
keywordDelimiter
,
@NonNull BibEntry
The bibEntry to use for expansion
entry
,
BibDatabase
The database for field resolving. May be null.
database
)

Expands a pattern

public static String

Returns:

The expanded pattern. Not null.
expandBrackets
(@NonNull String
The pattern to expand
pattern
,
Function<String, String>
A function taking the string representation of the content of a bracketed pattern and expanding it
bracketContentHandler
)

Expands a pattern.

private static String

Returns:

the surname of an author/editor or the von part if no lastname is prsent or "" if no author was found or both firstname+lastname are empty This method is guaranteed to never return null.
firstAuthor
(AuthorList authorList)

Gets the last name of the first author/editor

private static String

Returns:

the first name initial of an author/editor or "" if no author was found This method is guaranteed to never return null.
firstAuthorForenameInitials
(AuthorList authorList)

Gets the first name initials of the first author/editor

private static String

Returns:

the von part and surname of an author/editor or "" if no author was found. This method is guaranteed to never return null.
firstAuthorVonAndLast
(AuthorList authorList)

Gets the von part and the last name of the first author/editor.

public static String

Returns:

the first page number or "" if no number is found in the string
firstPage
(String
(may not be null) a pages string such as 42--111 or 7,41,73--97, 43+ or iv--xx
pages
)

Split the pages field into separate numbers and return the lowest

private static String
formatTitle(String title)

Removes any '-', unnecessary whitespace and latex commands formatting

pack-priv static @Nullable String

Returns:

  • the institution key, "" in the case of a failure, - null if content is null
generateInstitutionKey
(@Nullable String
the institution to generate a Bibtex key for
content
)

An author or editor may be an institution not a person.

public static String
getCamelizedTitle(String title)

Capitalises and concatenates the words out of the "title" field in the given BibTeX entry

public static String
getCamelizedTitle_N(String title, int number)

Capitalises and concatenates the words out of the "title" field in the given BibTeX entry, to a maximum of N words.

public static String

Returns:

String containing the evaluation result. Empty string if the pattern cannot be resolved.
getFieldValue
(BibEntry
The entry to get the field value from
entry
,
String
A pattern string (such as auth, pureauth, authorLast)
pattern
,
Character
The de
keywordDelimiter
,
BibDatabase
The database to use for field resolving. May be null.
database
)

Evaluates the given pattern to the given bibentry and database

private static String
private static List<String>
private static String
getSomeWords(int number, String string)

public static String
getTitleWords(int number, String title)

Determines "number" words out of the "title" field in the given BibTeX entry

private static String
getTitleWordsWithSpaces(int number, String title)

private static List<String>
private static boolean

Returns:

true if only the last name is present and it contains at least one whitespace character.
isInstitution
(Author
the checked author
author
)

Checks if an author is an institution which can get a citation key from generateInstitutionKey(String).

public static String

Returns:

a string consisting of authors' last names separated by a delimiter and with any authors excess of maxAuthors replaced with suffix
joinAuthorsOnLastName
(AuthorList
the list of authors
authorList
,
int
the maximum number of authors in the string
maxAuthors
,
String
delimiter separating the last names of the authors
delimiter
,
final String
to replace excess authors with. Also used to replace and others.
suffix
)

Creates a string with all last names separated by a delimiter.

private static String
pack-priv static String

Returns:

the surname of an author/editor
lastAuthor
(AuthorList authorList)

Gets the last name of the last author/editor

private static String

Returns:

the forename initial of an author/editor or "" if no author was found This method is guaranteed to never return null.
lastAuthorForenameInitials
(AuthorList authorList)

Gets the forename initials of the last author/editor

public static String

Returns:

the first page number or "" if no number is found in the string
lastPage
(String
(may not be null) a pages string such as 42--111 or 7,41,73--97, 43+ or iv--xx
pages
)

Split the pages field into separate numbers and return the highest

private static String

Returns:

Gets the surnames of the first N authors and appends EtAl if there are more than N authors
nAuthors
(AuthorList authorList, int
the number of desired authors
n
)

Gets the surnames of the first N authors and appends EtAl if there are more than N authors

private static boolean
pack-priv static String

Returns:

the surname of all authors/editors
oneAuthorPlusInitials
(AuthorList authorList)

Gets the first part of the last name of the first author/editor, and appends the last name initial of the remaining authors/editors.

public static String

Returns:

the non-digit prefix of pages (like "L" of L7) or "" if no non-digit prefix is found in the string
pagePrefix
(String
(may not be null) a pages string such as 42--111 or 7,41,73--97, 43+ or iv--xx
pages
)

Return the non-digit prefix of pages

private static Comparator<String>
protected static List<String>

Returns:

An array of strings representing the parts of the marker
parseFieldAndModifiers
(String
The argument string.
arg
)

Parse a field marker with modifiers, possibly containing a parenthesised modifier, as well as escaped colons and parentheses.

public static String
private static int
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait