-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Add multi-sentence title formatting to sentence case and title case #6872
Add multi-sentence title formatting to sentence case and title case #6872
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welcome to JabRef development! I am very happy to see an ADR. Regarding the code, I just have some minor comments.
docs/adr/0017-use-regular-expression-to-split-multiple-sentence-titles.md
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/logic/formatter/casechanger/SentenceCaseFormatter.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/logic/formatter/casechanger/SentenceCaseFormatter.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jabref/logic/formatter/casechanger/TitleCaseFormatter.java
Outdated
Show resolved
Hide resolved
@@ -25,6 +25,36 @@ public void test() { | |||
assertEquals("Upper {N}ot first", formatter.format("upper {N}OT FIRST")); | |||
} | |||
|
|||
@Test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While you are on it, I propose to rewrite to parameterized tests:
package org.jabref.logic.formatter.casechanger;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Tests in addition to the general tests from {@link org.jabref.logic.formatter.FormatterTest}
*/
public class SentenceCaseFormatterTest {
private SentenceCaseFormatter formatter = new SentenceCaseFormatter();
private static Stream<Arguments> testData() {
return Stream.of(
Arguments.of("Upper first", "upper First"),
Arguments.of("Upper first", "uPPER FIRST"),
Arguments.of("Upper {NOT} first", "upper {NOT} FIRST"),
Arguments.of("Upper {N}ot first", "upper {N}OT FIRST"),
Arguments.of("Whose music? A sociology of musical language",
"Whose music? a sociology of musical language"),
Arguments.of("Bibliographic software. A comparison.",
"bibliographic software. a comparison."),
Arguments.of("England’s monitor; The history of the separation",
"England’s Monitor; the History of the Separation"),
Arguments.of("Dr. schultz: a dentist turned bounty hunter.",
"Dr. schultz: a dentist turned bounty hunter."),
Arguments.of("Example case. {EXCLUDED SENTENCE.}",
"Example case. {EXCLUDED SENTENCE.}"),
Arguments.of("I have {Aa} dream", new SentenceCaseFormatter().getExampleInput())
);
}
@ParameterizedTest
@MethodSource("testData")
public void test(String expected, String input) {
assertEquals(expected, formatter.format(input));
}
}
OK, the descriptions are lost. Maybe, the description could be added as first paramter to the test
method.
Thank you for working on it - could you fix checkstyle? 😇
Even though there are many failing tests, we should at least try to keep the essential tests green. "Checkstyle" and "Unit tests" are essential. "Unit tests" go through; just checkstyle is it. |
Done. How can I test for checkstyle issues? I am using |
If you use intellij you can install the checkstyle plug-in and also import the jabref code style for the formatter. |
assertEquals(expected, formatter.format(input)); | ||
} | ||
|
||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why these tests are commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are redundant as I already added them as parameterized tests but I didn't know if I should delete them yet since they contain the descriptions of the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then just remove them. I think it's clear from the arguments what is tested
@tmrd993 Thanks again for your contribution! |
Fixes #6759
Added support for multiple-sentence title formatting for the "Sentence Case" and "Title Case" options by using a regular expression to first split the input into sentences, and afterwards processing those sentences individually. A RegEx might not be the best choice for natural language processing but since most titles are only 1 sentence long, the proposed RegEx should cover the vast majority of cases. Also added additional test cases for Sentence Case and Title Case formatting. The old tests are assuming one sentence titles but are still applicable.