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

Readability for citation key patterns #6706

Merged
merged 45 commits into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
360cfda
Drop `authEtal` dependence on alphabetization
k3KAW8Pnf7mkmdSMPHz27 Jul 10, 2020
aa30930
Drop use of deprecated method
k3KAW8Pnf7mkmdSMPHz27 Jul 14, 2020
4126163
Drop unnecessary method call
k3KAW8Pnf7mkmdSMPHz27 Jul 14, 2020
09f3ca2
Fix test using `nio.file.Path`
k3KAW8Pnf7mkmdSMPHz27 Jul 14, 2020
facada6
Refactor if-else block to switch
k3KAW8Pnf7mkmdSMPHz27 Jul 17, 2020
9e93fe9
Add parsing of authors as an AuthorList
k3KAW8Pnf7mkmdSMPHz27 Jul 17, 2020
ddf3c6f
Merge branch 'master' into fix-for-issue-3920
k3KAW8Pnf7mkmdSMPHz27 Jul 17, 2020
812b9ac
Fix handling of list of authors
k3KAW8Pnf7mkmdSMPHz27 Jul 21, 2020
15770de
Refactor variable name
k3KAW8Pnf7mkmdSMPHz27 Jul 21, 2020
d456d1e
Fix adding institutions twice
k3KAW8Pnf7mkmdSMPHz27 Jul 21, 2020
53f705c
Fix attempting to improve readability
k3KAW8Pnf7mkmdSMPHz27 Jul 21, 2020
e62481a
Fix types and readability
k3KAW8Pnf7mkmdSMPHz27 Jul 23, 2020
e0c7507
Refactor `firstAuthorVonAndLast`
k3KAW8Pnf7mkmdSMPHz27 Jul 23, 2020
a86ce94
Fix access modifiers
k3KAW8Pnf7mkmdSMPHz27 Aug 7, 2020
6a836f2
Merge branch 'master' into fix-for-issue-3920
k3KAW8Pnf7mkmdSMPHz27 Aug 7, 2020
8d1774b
Add test case
k3KAW8Pnf7mkmdSMPHz27 Aug 7, 2020
cf203c9
Drop unused methods
k3KAW8Pnf7mkmdSMPHz27 Aug 7, 2020
715364d
Add tests for truncated Unicode
k3KAW8Pnf7mkmdSMPHz27 Aug 18, 2020
ee94869
Fix missing bracket in test case
k3KAW8Pnf7mkmdSMPHz27 Aug 18, 2020
ed66bb2
Add convenience method for cleaning cite keys
k3KAW8Pnf7mkmdSMPHz27 Aug 27, 2020
5b1312f
Fix incorrect number of characters in cite key
k3KAW8Pnf7mkmdSMPHz27 Aug 27, 2020
864c0ba
Fix incorrect number of characters in cite key
k3KAW8Pnf7mkmdSMPHz27 Aug 27, 2020
9cac2db
Merge remote-tracking branch 'origin/fix-for-issue-3920' into fix-for…
k3KAW8Pnf7mkmdSMPHz27 Aug 27, 2020
25de361
Merge branch 'master' into fix-for-issue-3920
k3KAW8Pnf7mkmdSMPHz27 Aug 27, 2020
472537c
Fix readability in BracketedPattern.expandBrackets
k3KAW8Pnf7mkmdSMPHz27 Aug 28, 2020
0b3a58c
Fix names in BracketedPattern.expandBrackets
k3KAW8Pnf7mkmdSMPHz27 Aug 31, 2020
4fe9774
Add JavaDoc to constants
k3KAW8Pnf7mkmdSMPHz27 Aug 31, 2020
a1a737b
Fix readability in BracketedPattern#authorsAlpha
k3KAW8Pnf7mkmdSMPHz27 Aug 31, 2020
4d19a51
Fix reformatting of file and readability
k3KAW8Pnf7mkmdSMPHz27 Aug 31, 2020
70a9fde
Fix simplifying camelizeSignificantWordsInTitle
k3KAW8Pnf7mkmdSMPHz27 Aug 31, 2020
663a836
Fix construction of BibEntry
k3KAW8Pnf7mkmdSMPHz27 Aug 31, 2020
4cba99c
Fix removing a null variable
k3KAW8Pnf7mkmdSMPHz27 Aug 31, 2020
bde6303
Add test for parsing of brackets in regex
k3KAW8Pnf7mkmdSMPHz27 Sep 3, 2020
4f72ef5
Merge branch 'fix-for-issue-3920' of https://github.com/k3KAW8Pnf7mkm…
k3KAW8Pnf7mkmdSMPHz27 Sep 3, 2020
11cbc14
Fix construction of BibEntries
k3KAW8Pnf7mkmdSMPHz27 Sep 3, 2020
7c2bcd0
Fix new line in JavaDoc
k3KAW8Pnf7mkmdSMPHz27 Sep 3, 2020
9b68687
Fix inconsistent bracket use in test patterns
k3KAW8Pnf7mkmdSMPHz27 Sep 3, 2020
de93751
Fix more BibEntries constructions
k3KAW8Pnf7mkmdSMPHz27 Sep 3, 2020
609caa7
Merge branch 'master' into fix-for-issue-3920
k3KAW8Pnf7mkmdSMPHz27 Sep 14, 2020
2c73301
Fix mistake in merge
k3KAW8Pnf7mkmdSMPHz27 Sep 14, 2020
23764b4
Fix use of withCiteKey
k3KAW8Pnf7mkmdSMPHz27 Sep 21, 2020
aca6fb1
Fix logger output
k3KAW8Pnf7mkmdSMPHz27 Sep 21, 2020
7b89653
Fix logger output
k3KAW8Pnf7mkmdSMPHz27 Sep 21, 2020
eac7293
Fix logger output
k3KAW8Pnf7mkmdSMPHz27 Sep 21, 2020
d598f41
Drop test-case outside of PR scope
k3KAW8Pnf7mkmdSMPHz27 Sep 21, 2020
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,029 changes: 467 additions & 562 deletions src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class CitationKeyGenerator extends BracketedPattern {
private final AbstractCitationKeyPattern citeKeyPattern;
private final BibDatabase database;
private final CitationKeyPatternPreferences citationKeyPatternPreferences;
private final String unwantedCharacters;

public CitationKeyGenerator(BibDatabaseContext bibDatabaseContext, CitationKeyPatternPreferences citationKeyPatternPreferences) {
this(bibDatabaseContext.getMetaData().getCiteKeyPattern(citationKeyPatternPreferences.getKeyPattern()),
Expand All @@ -43,6 +44,7 @@ public CitationKeyGenerator(AbstractCitationKeyPattern citeKeyPattern, BibDataba
this.citeKeyPattern = Objects.requireNonNull(citeKeyPattern);
this.database = Objects.requireNonNull(database);
this.citationKeyPatternPreferences = Objects.requireNonNull(citationKeyPatternPreferences);
this.unwantedCharacters = citationKeyPatternPreferences.getUnwantedCharacters();
}

@Deprecated
Expand Down Expand Up @@ -84,6 +86,10 @@ private static String getAppendix(int number) {
}
}

public static String removeDefaultUnwantedCharacters(String key) {
return removeUnwantedCharacters(key, DEFAULT_UNWANTED_CHARACTERS);
}

public static String removeUnwantedCharacters(String key, String unwantedCharacters) {
String newKey = key.chars()
.filter(c -> unwantedCharacters.indexOf(c) == -1)
Expand Down Expand Up @@ -124,13 +130,13 @@ public String generateKey(BibEntry entry) {
List<String> parts = parseFieldMarker(typeListEntry);
Character delimiter = citationKeyPatternPreferences.getKeywordDelimiter();
String pattern = "[" + parts.get(0) + "]";
String label = expandBrackets(pattern, delimiter, entry, database);
String label = removeUnwantedCharacters(expandBrackets(pattern, delimiter, entry, database), unwantedCharacters);
// apply modifier if present
if (parts.size() > 1) {
label = applyModifiers(label, parts, 1);
label = removeUnwantedCharacters(applyModifiers(label, parts, 1), unwantedCharacters);
}
// Remove all illegal characters from the label.
label = cleanKey(label, citationKeyPatternPreferences.getUnwantedCharacters());
label = cleanKey(label, unwantedCharacters);
stringBuilder.append(label);
} else {
stringBuilder.append(typeListEntry);
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/jabref/model/entry/BibEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,10 @@ private Optional<String> genericGetResolvedFieldOrAlias(Field field, BibDatabase
}
}
}
return result.map(resultText -> BibDatabase.getText(resultText, database));

return (database == null || result.isEmpty()) ?
result :
Optional.of(database.resolveForStrings(result.get()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,23 @@ class BracketedPatternTest {

@BeforeEach
void setUp() {
bibentry = new BibEntry();
bibentry.setField(StandardField.AUTHOR, "O. Kitsune");
bibentry.setField(StandardField.YEAR, "2017");
bibentry.setField(StandardField.PAGES, "213--216");

dbentry = new BibEntry();
dbentry.setType(StandardEntryType.Article);
dbentry.setCitationKey("HipKro03");
dbentry.setField(StandardField.AUTHOR, "Eric von Hippel and Georg von Krogh");
dbentry.setField(StandardField.TITLE, "Open Source Software and the \"Private-Collective\" Innovation Model: Issues for Organization Science");
dbentry.setField(StandardField.JOURNAL, "Organization Science");
dbentry.setField(StandardField.YEAR, "2003");
dbentry.setField(StandardField.VOLUME, "14");
dbentry.setField(StandardField.PAGES, "209--223");
dbentry.setField(StandardField.NUMBER, "2");
dbentry.setField(StandardField.ADDRESS, "Institute for Operations Research and the Management Sciences (INFORMS), Linthicum, Maryland, USA");
dbentry.setField(StandardField.DOI, "http://dx.doi.org/10.1287/orsc.14.2.209.14992");
dbentry.setField(StandardField.ISSN, "1526-5455");
dbentry.setField(StandardField.PUBLISHER, "INFORMS");
bibentry = new BibEntry().withField(StandardField.AUTHOR, "O. Kitsune")
.withField(StandardField.YEAR, "2017")
.withField(StandardField.PAGES, "213--216");

dbentry = new BibEntry(StandardEntryType.Article)
.withCitationKey("HipKro03")
.withField(StandardField.AUTHOR, "Eric von Hippel and Georg von Krogh")
.withField(StandardField.TITLE, "Open Source Software and the \"Private-Collective\" Innovation Model: Issues for Organization Science")
.withField(StandardField.JOURNAL, "Organization Science")
.withField(StandardField.YEAR, "2003")
.withField(StandardField.VOLUME, "14")
.withField(StandardField.PAGES, "209--223")
.withField(StandardField.NUMBER, "2")
.withField(StandardField.ADDRESS, "Institute for Operations Research and the Management Sciences (INFORMS), Linthicum, Maryland, USA")
.withField(StandardField.DOI, "http://dx.doi.org/10.1287/orsc.14.2.209.14992")
.withField(StandardField.ISSN, "1526-5455")
.withField(StandardField.PUBLISHER, "INFORMS");

database = new BibDatabase();
database.insertEntry(dbentry);
Expand Down Expand Up @@ -102,10 +100,10 @@ void databaseWithStringsExpansionTest() {
BibDatabase another_database = new BibDatabase();
BibtexString string = new BibtexString("sgr", "Saulius Gražulis");
another_database.addString(string);
bibentry = new BibEntry();
bibentry.setField(StandardField.AUTHOR, "#sgr#");
bibentry.setField(StandardField.YEAR, "2017");
bibentry.setField(StandardField.PAGES, "213--216");
bibentry = new BibEntry()
.withField(StandardField.AUTHOR, "#sgr#")
.withField(StandardField.YEAR, "2017")
.withField(StandardField.PAGES, "213--216");
BracketedPattern pattern = new BracketedPattern("[year]_[auth]_[firstpage]");
assertEquals("2017_Gražulis_213", pattern.expand(bibentry,
another_database));
Expand Down Expand Up @@ -139,10 +137,10 @@ void entryTypeExpansionLowercaseTest() {
void suppliedBibentryBracketExpansionTest() {
BibDatabase another_database = null;
BracketedPattern pattern = new BracketedPattern("[year]_[auth]_[firstpage]");
BibEntry another_bibentry = new BibEntry();
another_bibentry.setField(StandardField.AUTHOR, "Gražulis, Saulius");
another_bibentry.setField(StandardField.YEAR, "2017");
another_bibentry.setField(StandardField.PAGES, "213--216");
BibEntry another_bibentry = new BibEntry()
.withField(StandardField.AUTHOR, "Gražulis, Saulius")
.withField(StandardField.YEAR, "2017")
.withField(StandardField.PAGES, "213--216");
assertEquals("2017_Gražulis_213", pattern.expand(another_bibentry, ';', another_database));
}

Expand Down Expand Up @@ -208,8 +206,7 @@ void lowerFormatterWorksOnVonNamePrefixes() {

@Test
void testResolvedFieldAndFormat() {
BibEntry child = new BibEntry();
child.setField(StandardField.CROSSREF, "HipKro03");
BibEntry child = new BibEntry().withField(StandardField.CROSSREF, "HipKro03");
database.insertEntry(child);

Character separator = ';';
Expand All @@ -233,8 +230,8 @@ void testResolvedFieldAndFormat() {

@Test
void testResolvedParentNotInDatabase() {
BibEntry child = new BibEntry();
child.setField(StandardField.CROSSREF, "HipKro03");
BibEntry child = new BibEntry()
.withField(StandardField.CROSSREF, "HipKro03");
database.removeEntry(dbentry);
database.insertEntry(child);

Expand Down Expand Up @@ -273,4 +270,12 @@ void expandBracketsDoesNotTruncateWithoutAnArgumentToTruncateModifier() {
assertEquals("Open Source Software and the \"Private-Collective\" Innovation Model: Issues for Organization Science",
BracketedPattern.expandBrackets("[fulltitle:truncate]", ';', dbentry, database));
}

@Test
void expandBracketsWithAuthorStartingWithBrackets() {
// Issue https://github.com/JabRef/jabref/issues/3920
BibEntry bibEntry = new BibEntry()
.withField(StandardField.AUTHOR, "Patrik {\\v{S}}pan{\\v{e}}l and Kseniya Dryahina and David Smith");
assertEquals("ŠpanělEtAl", BracketedPattern.expandBrackets("[authEtAl:latex_to_unicode]", null, bibEntry, null));
}
}
Loading