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

Added check for "camel" option to makeLabel in BibtexKeyPatternUtil #2

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ public static String applyModifiers(final String label, final List<String> parts
Optional<Formatter> formatter = Formatters.getFormatterForModifier(modifier);
if (formatter.isPresent()) {
resultingLabel = formatter.get().format(label);
} else if (!modifier.isEmpty() && modifier.length()>= 2 && (modifier.charAt(0) == '(') && modifier.endsWith(")")) {
} else if (!modifier.isEmpty() && (modifier.length()>= 2) && (modifier.charAt(0) == '(') && modifier.endsWith(")")) {
// Alternate text modifier in parentheses. Should be inserted if
// the label is empty:
if (label.isEmpty() && (modifier.length() > 2)) {
Expand Down Expand Up @@ -640,6 +640,8 @@ else if (val.matches("edtr\\d+")) {
Collections.singletonList("abbr"), 0));
} else if ("veryshorttitle".equals(val)) {
return getTitleWords(1, entry.getField(FieldName.TITLE).orElse(""));
} else if ("camel".equals(val)) {
return getCamelizedTitle(entry.getField(FieldName.TITLE).orElse(""));
} else if ("shortyear".equals(val)) {
String yearString = entry.getFieldOrAlias(FieldName.YEAR).orElse("");
if (yearString.isEmpty()) {
Expand Down Expand Up @@ -759,6 +761,47 @@ private static String getTitleWordsWithSpaces(int number, String title) {
return stringBuilder.toString();
}

/**
* Capitalises and concatenates the words out of the "title" field in the given BibTeX entry
*/
public static String getCamelizedTitle(String title) {
return keepLettersAndDigitsOnly(getCamelizedTitleWithSpaces(title));
}

private static String getCamelizedTitleWithSpaces(String title) {
String ss = new RemoveLatexCommandsFormatter().format(title);
StringBuilder stringBuilder = new StringBuilder();
StringBuilder current;
int piv = 0;

// sorry for being English-centric. I guess these
// words should really be an editable preference.
while (piv < ss.length()) {
current = new StringBuilder();
// Get the next word:
while ((piv < ss.length()) && !Character.isWhitespace(ss.charAt(piv))
&& (ss.charAt(piv) != '-')) {
current.append(ss.charAt(piv));
piv++;
}
piv++;
// Check if it is ok:
String word = current.toString().trim();
if (word.isEmpty()) {
continue;
}
word = word.substring(0, 1).toUpperCase() + word.substring(1);

// If we get here, the word was accepted.
if (stringBuilder.length() > 0) {
stringBuilder.append(' ');
}
stringBuilder.append(word);
}

return stringBuilder.toString();
}

private static String keepLettersAndDigitsOnly(String in) {
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < in.length(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ public void veryShortTitle() {
*/
@Test
public void shortTitle() {
// veryShortTitle is getTitleWords with "3" as count
// shortTitle is getTitleWords with "3" as count
int count = 3;
assertEquals("applicationmigrationeffort",
BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_ALL_LOWER_FOUR_SMALL_WORDS_ONE_EN_DASH));
Expand All @@ -659,6 +659,31 @@ public void shortTitle() {
BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED_FOUR_SMALL_WORDS_TWO_CONNECTED_WORDS));
}

/**
* Tests [camel]
*/
@Test
public void camel() {
// camel capitalises and concatenates all the words of the title
assertEquals("ApplicationMigrationEffortInTheCloudTheCaseOfCloudPlatforms",
BibtexKeyPatternUtil.getCamelizedTitle(TITLE_STRING_ALL_LOWER_FOUR_SMALL_WORDS_ONE_EN_DASH));
assertEquals("BPELConformanceInOpenSourceEnginesTheCaseOfStaticAnalysis",
BibtexKeyPatternUtil.getCamelizedTitle(
TITLE_STRING_ALL_LOWER_FIRST_WORD_IN_BRACKETS_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON));
assertEquals("ProcessViewingPatterns", BibtexKeyPatternUtil.getCamelizedTitle(TITLE_STRING_CASED));
assertEquals("BPMNConformanceInOpenSourceEngines",
BibtexKeyPatternUtil.getCamelizedTitle(TITLE_STRING_CASED_ONE_UPPER_WORD_ONE_SMALL_WORD));
assertEquals("TheDifferenceBetweenGraphBasedAndBlockStructuredBusinessProcessModellingLanguages",
BibtexKeyPatternUtil.getCamelizedTitle(
TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AT_THE_BEGINNING));
assertEquals("CloudComputingTheNextRevolutionInIT",
BibtexKeyPatternUtil.getCamelizedTitle(TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON));
assertEquals("TowardsChoreographyBasedProcessDistributionInTheCloud",
BibtexKeyPatternUtil.getCamelizedTitle(TITLE_STRING_CASED_TWO_SMALL_WORDS_ONE_CONNECTED_WORD));
assertEquals("OnTheMeasurementOfDesignTimeAdaptabilityForProcessBasedSystems",
BibtexKeyPatternUtil.getCamelizedTitle(TITLE_STRING_CASED_FOUR_SMALL_WORDS_TWO_CONNECTED_WORDS));
}

@Test
public void keywordNKeywordsSeparatedBySpace() {
BibEntry entry = new BibEntry();
Expand Down