Skip to content

Commit

Permalink
Shortittle bibtexkeypattern now also discards small words (#4030)
Browse files Browse the repository at this point in the history
* Shortittle bibtexkeypattern now also discards small words

Feature Request in the forum:
http://discourse.jabref.org/t/jabref-differences-in-shorttitle-between-versions-3-8-1-and-4-not-discounting-the-a-an-of-in-titles/1147

* fix test
  • Loading branch information
Siedlerchr authored May 12, 2018
1 parent dae1c81 commit 899d267
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
### Changed
- We added a text file export for 'Find Unlinked Files'. [#3341](https://github.com/JabRef/jabref/issues/3341)
- We added a fetcher based on RFC-IDs. [#3971](https://github.com/JabRef/jabref/issues/3971)
- We changed the implementation of the `[shorttitle]` key pattern. It now removes small words like `a`, `an`, `on`, `the` etc. Refer to the help page for a complete overview. [Feature request in the forum](http://discourse.jabref.org/t/jabref-differences-in-shorttitle-between-versions-3-8-1-and-4-not-discounting-the-a-an-of-in-titles/1147)

### Fixed
We fixed an issue where the export to clipboard functionality could not be invoked. [#3994](https://github.com/JabRef/jabref/issues/3994)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ else if (val.matches("edtr\\d+")) {
} else if ("fulltitle".equals(val)) {
return entry.getResolvedFieldOrAlias(FieldName.TITLE, database).orElse("");
} else if ("shorttitle".equals(val)) {
return getTitleWords(3, entry.getResolvedFieldOrAlias(FieldName.TITLE, database).orElse(""));
return getTitleWords(3,
removeSmallWords(entry.getResolvedFieldOrAlias(FieldName.TITLE, database).orElse("")));
} else if ("shorttitleINI".equals(val)) {
return keepLettersAndDigitsOnly(
applyModifiers(getTitleWordsWithSpaces(3, entry.getResolvedFieldOrAlias(FieldName.TITLE, database).orElse("")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -767,23 +767,30 @@ public void veryShortTitle() {
*/
@Test
public void shortTitle() {
// shortTitle is getTitleWords with "3" as count
// shortTitle is getTitleWords with "3" as count and removed small words
int count = 3;
assertEquals("application migration effort",
BibtexKeyGenerator.getTitleWords(count, TITLE_STRING_ALL_LOWER_FOUR_SMALL_WORDS_ONE_EN_DASH));
assertEquals("BPEL conformance in", BibtexKeyGenerator.getTitleWords(count,
TITLE_STRING_ALL_LOWER_FIRST_WORD_IN_BRACKETS_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON));
assertEquals("Process Viewing Patterns", BibtexKeyGenerator.getTitleWords(count, TITLE_STRING_CASED));
assertEquals("BPMN Conformance in",
BibtexKeyGenerator.getTitleWords(count, TITLE_STRING_CASED_ONE_UPPER_WORD_ONE_SMALL_WORD));
assertEquals("The Difference Between", BibtexKeyGenerator.getTitleWords(count,
TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AT_THE_BEGINNING));
assertEquals("Cloud Computing: The",
BibtexKeyGenerator.getTitleWords(count, TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON));
BibtexKeyGenerator.getTitleWords(count,
BibtexKeyGenerator.removeSmallWords(TITLE_STRING_ALL_LOWER_FOUR_SMALL_WORDS_ONE_EN_DASH)));
assertEquals("BPEL conformance open",
BibtexKeyGenerator.getTitleWords(count,
BibtexKeyGenerator.removeSmallWords(TITLE_STRING_ALL_LOWER_FIRST_WORD_IN_BRACKETS_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON)));
assertEquals("Process Viewing Patterns",
BibtexKeyGenerator.getTitleWords(count,
BibtexKeyGenerator.removeSmallWords(TITLE_STRING_CASED)));
assertEquals("BPMN Conformance Open",
BibtexKeyGenerator.getTitleWords(count,
BibtexKeyGenerator.removeSmallWords(TITLE_STRING_CASED_ONE_UPPER_WORD_ONE_SMALL_WORD)));
assertEquals("Difference Graph Based",
BibtexKeyGenerator.getTitleWords(count,
BibtexKeyGenerator.removeSmallWords(TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AT_THE_BEGINNING)));
assertEquals("Cloud Computing: Next",
BibtexKeyGenerator.getTitleWords(count,
BibtexKeyGenerator.removeSmallWords(TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON)));
assertEquals("Towards Choreography based",
BibtexKeyGenerator.getTitleWords(count, TITLE_STRING_CASED_TWO_SMALL_WORDS_ONE_CONNECTED_WORD));
assertEquals("On the Measurement",
BibtexKeyGenerator.getTitleWords(count, TITLE_STRING_CASED_FOUR_SMALL_WORDS_TWO_CONNECTED_WORDS));
BibtexKeyGenerator.getTitleWords(count, BibtexKeyGenerator.removeSmallWords(TITLE_STRING_CASED_TWO_SMALL_WORDS_ONE_CONNECTED_WORD)));
assertEquals("Measurement Design Time",
BibtexKeyGenerator.getTitleWords(count, BibtexKeyGenerator.removeSmallWords(TITLE_STRING_CASED_FOUR_SMALL_WORDS_TWO_CONNECTED_WORDS)));
}

/**
Expand Down Expand Up @@ -935,7 +942,7 @@ public void testApplyModifiers() {
BibEntry entry = new BibEntry();
entry.setField("title", "Green Scheduling of Whatever");
assertEquals("GSo", BibtexKeyGenerator.generateKey(entry, "shorttitleINI"));
assertEquals("GreenSchedulingof", BibtexKeyGenerator.generateKey(entry, "shorttitle",
assertEquals("GreenSchedulingWhatever", BibtexKeyGenerator.generateKey(entry, "shorttitle",
new BibDatabase()));
}

Expand All @@ -950,7 +957,7 @@ public void testcrossrefShorttitle() {
database.insertEntry(entry1);
entry2.setField("title", "Green Scheduling of Whatever");

assertEquals("GreenSchedulingof", BibtexKeyGenerator.generateKey(entry1, "shorttitle",
assertEquals("GreenSchedulingWhatever", BibtexKeyGenerator.generateKey(entry1, "shorttitle",
database));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,47 +231,47 @@ public void generateKeyTitleAbbr() {
public void generateKeyShorttitle() {
bibtexKeyPattern.setDefaultValue("[shorttitle]");
new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry);
assertEquals(Optional.of("Anawesomepaper"), entry.getCiteKeyOptional());
assertEquals(Optional.of("awesomepaperJabRef"), entry.getCiteKeyOptional());
}

@Test
public void generateKeyShorttitleLowerModified() {
bibtexKeyPattern.setDefaultValue("[shorttitle:lower]");
entry.setField("title", "An aweSOme Paper on JabRef");
new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry);
assertEquals(Optional.of("anawesomepaper"), entry.getCiteKeyOptional());
assertEquals(Optional.of("awesomepaperjabref"), entry.getCiteKeyOptional());
}

@Test
public void generateKeyShorttitleUpperModified() {
bibtexKeyPattern.setDefaultValue("[shorttitle:upper]");
entry.setField("title", "An aweSOme Paper on JabRef");
new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry);
assertEquals(Optional.of("ANAWESOMEPAPER"), entry.getCiteKeyOptional());
assertEquals(Optional.of("AWESOMEPAPERJABREF"), entry.getCiteKeyOptional());
}

@Test
public void generateKeyShorttitleTitleCaseModified() {
bibtexKeyPattern.setDefaultValue("[shorttitle:title_case]");
entry.setField("title", "An aweSOme Paper on JabRef");
new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry);
assertEquals(Optional.of("AnAwesomePaper"), entry.getCiteKeyOptional());
assertEquals(Optional.of("AwesomePaperJabref"), entry.getCiteKeyOptional());
}

@Test
public void generateKeyShorttitleSentenceCaseModified() {
bibtexKeyPattern.setDefaultValue("[shorttitle:sentence_case]");
entry.setField("title", "An aweSOme Paper on JabRef");
new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry);
assertEquals(Optional.of("Anawesomepaper"), entry.getCiteKeyOptional());
assertEquals(Optional.of("Awesomepaperjabref"), entry.getCiteKeyOptional());
}

@Test
public void generateKeyShorttitleCapitalizeModified() {
bibtexKeyPattern.setDefaultValue("[shorttitle:capitalize]");
entry.setField("title", "An aweSOme Paper on JabRef");
new BibtexKeyGenerator(bibtexKeyPattern, database, preferences).generateAndSetKey(entry);
assertEquals(Optional.of("AnAwesomePaper"), entry.getCiteKeyOptional());
assertEquals(Optional.of("AwesomePaperJabref"), entry.getCiteKeyOptional());
}

@Test
Expand Down

0 comments on commit 899d267

Please sign in to comment.