From 4f1d362d184f753222ef8e417116dbcd87acf711 Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Fri, 12 Jan 2024 14:57:28 -0500 Subject: [PATCH 1/9] add `camelShort` citation key marker Add the ability to set a citation key marker `camelShort` that is identical to the `camel` marker but with a maximum of 7 words. --- .../citationkeypattern/BracketedPattern.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java b/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java index 4fd02d39c1f..c1714bb0f88 100644 --- a/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java +++ b/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java @@ -454,6 +454,8 @@ public static String getFieldValue(BibEntry entry, String pattern, Character key } else if ("veryshorttitle".equals(pattern)) { return getTitleWords(1, removeSmallWords(entry.getResolvedFieldOrAlias(StandardField.TITLE, database).orElse(""))); + } else if ("camelShort".equals(pattern)) { + return getCamelizedTitleShort(entry.getResolvedFieldOrAlias(StandardField.TITLE, database).orElse("")); } else if ("camel".equals(pattern)) { return getCamelizedTitle(entry.getResolvedFieldOrAlias(StandardField.TITLE, database).orElse("")); } else if ("shortyear".equals(pattern)) { @@ -662,6 +664,37 @@ private static String camelizeTitle(String title) { return stringBuilder.toString(); } + /** + * Capitalises and concatenates the words out of the "title" field in the given BibTeX entry, to a maximum of 7 words. + */ + public static String getCamelizedTitleShort(String title) { + return keepLettersAndDigitsOnly(camelizeTitleShort(title)); + } + + public static String camelizeTitleShort(String title) { + StringBuilder stringBuilder = new StringBuilder(); + String formattedTitle = formatTitle(title); + int count = 0; + try (Scanner titleScanner = new Scanner(formattedTitle)) { + while (titleScanner.hasNext()) { + if (count >= 7) {break} + + String word = titleScanner.next(); + + // Camelize the word + word = word.substring(0, 1).toUpperCase(Locale.ROOT) + word.substring(1); + + if (stringBuilder.length() > 0) { + stringBuilder.append(' '); + } + stringBuilder.append(word); + count += 1; + } + } + + return stringBuilder.toString(); + } + /** * Capitalises the significant words of the "title" field in the given BibTeX entry */ From 45e22cbdbef045760e5e6433198b210b92084e3b Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Fri, 12 Jan 2024 15:01:38 -0500 Subject: [PATCH 2/9] change name to `shortcamel` change name to `shortcamel` to match current naming scheme --- .../org/jabref/logic/citationkeypattern/BracketedPattern.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java b/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java index c1714bb0f88..1984943d0e0 100644 --- a/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java +++ b/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java @@ -454,7 +454,7 @@ public static String getFieldValue(BibEntry entry, String pattern, Character key } else if ("veryshorttitle".equals(pattern)) { return getTitleWords(1, removeSmallWords(entry.getResolvedFieldOrAlias(StandardField.TITLE, database).orElse(""))); - } else if ("camelShort".equals(pattern)) { + } else if ("shortcamel".equals(pattern)) { return getCamelizedTitleShort(entry.getResolvedFieldOrAlias(StandardField.TITLE, database).orElse("")); } else if ("camel".equals(pattern)) { return getCamelizedTitle(entry.getResolvedFieldOrAlias(StandardField.TITLE, database).orElse("")); From eadf5a71e1b8766197f4f3561c67fb38075d6aa3 Mon Sep 17 00:00:00 2001 From: Christoph Date: Fri, 12 Jan 2024 22:10:48 +0100 Subject: [PATCH 3/9] Update src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java --- .../org/jabref/logic/citationkeypattern/BracketedPattern.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java b/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java index 1984943d0e0..338c0847efc 100644 --- a/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java +++ b/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java @@ -677,7 +677,7 @@ public static String camelizeTitleShort(String title) { int count = 0; try (Scanner titleScanner = new Scanner(formattedTitle)) { while (titleScanner.hasNext()) { - if (count >= 7) {break} + if (count >= 7) { break; } String word = titleScanner.next(); From 137e8d42ea54b304451efd5a9fe01c1943b350a0 Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Mon, 19 Feb 2024 10:46:21 -0500 Subject: [PATCH 4/9] refactor [shortcamel] title to instead use [camelN] to select N words from camelCase title. Not functional yet. --- .../citationkeypattern/BracketedPattern.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java b/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java index 0ab9186695d..5701b961553 100644 --- a/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java +++ b/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java @@ -454,8 +454,9 @@ public static String getFieldValue(BibEntry entry, String pattern, Character key } else if ("veryshorttitle".equals(pattern)) { return getTitleWords(1, removeSmallWords(entry.getResolvedFieldOrAlias(StandardField.TITLE, database).orElse(""))); - } else if ("shortcamel".equals(pattern)) { - return getCamelizedTitleShort(entry.getResolvedFieldOrAlias(StandardField.TITLE, database).orElse("")); + } else if (pattern.matches("camel[\\d]+")) { + int num = Integer.parseInt(pattern.substring(5)); + return getCamelizedTitle_N(entry.getResolvedFieldOrAlias(StandardField.TITLE, database).orElse(""), num); } else if ("camel".equals(pattern)) { return getCamelizedTitle(entry.getResolvedFieldOrAlias(StandardField.TITLE, database).orElse("")); } else if ("shortyear".equals(pattern)) { @@ -665,20 +666,18 @@ private static String camelizeTitle(String title) { } /** - * Capitalises and concatenates the words out of the "title" field in the given BibTeX entry, to a maximum of 7 words. + * Capitalises and concatenates the words out of the "title" field in the given BibTeX entry, to a maximum of N words. */ - public static String getCamelizedTitleShort(String title) { - return keepLettersAndDigitsOnly(camelizeTitleShort(title)); + public static String getCamelizedTitle_N(String title, int number) { + return keepLettersAndDigitsOnly(camelizeTitle_N(title, number)); } - public static String camelizeTitleShort(String title) { + private static String camelizeTitle_N(String title, int number) { StringBuilder stringBuilder = new StringBuilder(); String formattedTitle = formatTitle(title); - int count = 0; + try (Scanner titleScanner = new Scanner(formattedTitle)) { while (titleScanner.hasNext()) { - if (count >= 7) { break; } - String word = titleScanner.next(); // Camelize the word @@ -688,7 +687,6 @@ public static String camelizeTitleShort(String title) { stringBuilder.append(' '); } stringBuilder.append(word); - count += 1; } } From 475001a271cfb58998c0c33c8d7ec6e867f8d391 Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Mon, 19 Feb 2024 10:47:32 -0500 Subject: [PATCH 5/9] refactor getTitleWordsWithSpaces to call getSomeWords so that the new function can be used for camelN --- .../jabref/logic/citationkeypattern/BracketedPattern.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java b/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java index 5701b961553..1380d34125d 100644 --- a/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java +++ b/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java @@ -735,7 +735,11 @@ public static String removeSmallWords(String title) { private static String getTitleWordsWithSpaces(int number, String title) { String formattedTitle = formatTitle(title); - try (Scanner titleScanner = new Scanner(formattedTitle)) { + return getSomeWords(number, formattedTitle); + } + + private static String getSomeWords(int number, String string) { + try (Scanner titleScanner = new Scanner(string)) { return titleScanner.tokens() .limit(number) .collect(Collectors.joining(" ")); From 17c41bf4b7d197030fe3d96def8ac7a26a3c451f Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Mon, 19 Feb 2024 10:48:18 -0500 Subject: [PATCH 6/9] add [camelN] functionality --- .../jabref/logic/citationkeypattern/BracketedPattern.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java b/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java index 1380d34125d..6d8206dc02e 100644 --- a/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java +++ b/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java @@ -690,9 +690,11 @@ private static String camelizeTitle_N(String title, int number) { } } - return stringBuilder.toString(); + String camelString = stringBuilder.toString(); + + return getSomeWords(number, camelString); } - + /** * Capitalises the significant words of the "title" field in the given BibTeX entry */ From 98440f442c4bca1549b8be96f0433fc586db5348 Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Mon, 19 Feb 2024 10:48:39 -0500 Subject: [PATCH 7/9] add test cases for [camelN] --- .../citationkeypattern/BracketedPatternTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/java/org/jabref/logic/citationkeypattern/BracketedPatternTest.java b/src/test/java/org/jabref/logic/citationkeypattern/BracketedPatternTest.java index 77c6b5d61ca..ace8b202723 100644 --- a/src/test/java/org/jabref/logic/citationkeypattern/BracketedPatternTest.java +++ b/src/test/java/org/jabref/logic/citationkeypattern/BracketedPatternTest.java @@ -543,6 +543,19 @@ void expandBracketsDoesNotTruncateWithoutAnArgumentToTruncateModifier() { BracketedPattern.expandBrackets("[fulltitle:truncate]", ';', dbentry, database)); } + /** + * Test the [camelN] title marker. + */ + @Test + void expandBracketsCamelNTitle() { + assertEquals("Open", + BracketedPattern.expandBrackets("[camel1]", ';', dbentry, database)); + assertEquals("OpenSourceSoftwareAnd", + BracketedPattern.expandBrackets("[camel4]", ';', dbentry, database)); + assertEquals("OpenSourceSoftwareAndThePrivateCollectiveInnovationModelIssues", + BracketedPattern.expandBrackets("[camel10]", ';', dbentry, database)); + } + @Test void expandBracketsWithAuthorStartingWithBrackets() { // Issue https://github.com/JabRef/jabref/issues/3920 From eadf6718260b6a26934d8c384b15fce216a9bc88 Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Mon, 19 Feb 2024 10:58:35 -0500 Subject: [PATCH 8/9] add `[camelN]` to changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0fb194442e..5cda58e8f89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We added ability to jump to an entry in the command line using `-j CITATIONKEY`. [koppor#540](https://github.com/koppor/jabref/issues/540) - We added a new boolean to the style files for Openoffice/Libreoffice integration to switch between ZERO_WIDTH_SPACE (default) and no space. [#10843](https://github.com/JabRef/jabref/pull/10843) - We added the possibility to redownload files that had been present but are no longer in the specified location. [#10848](https://github.com/JabRef/jabref/issues/10848) +- We added the citation key pattern `[camelN]`. Equivalent to the first N words of the `[camel]` pattern. ### Changed From 8e1a5b9797fa054ddbb545a14791406a1880db0c Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Mon, 19 Feb 2024 11:02:04 -0500 Subject: [PATCH 9/9] remove trailing whitespace --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cda58e8f89..88cb8fd45b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We added ability to jump to an entry in the command line using `-j CITATIONKEY`. [koppor#540](https://github.com/koppor/jabref/issues/540) - We added a new boolean to the style files for Openoffice/Libreoffice integration to switch between ZERO_WIDTH_SPACE (default) and no space. [#10843](https://github.com/JabRef/jabref/pull/10843) - We added the possibility to redownload files that had been present but are no longer in the specified location. [#10848](https://github.com/JabRef/jabref/issues/10848) -- We added the citation key pattern `[camelN]`. Equivalent to the first N words of the `[camel]` pattern. +- We added the citation key pattern `[camelN]`. Equivalent to the first N words of the `[camel]` pattern. ### Changed