Search in sources :

Example 1 with NormalizePagesFormatter

use of org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter in project jabref by JabRef.

the class DoiFetcher method doPostCleanup.

private void doPostCleanup(BibEntry entry) {
    new FieldFormatterCleanup(FieldName.PAGES, new NormalizePagesFormatter()).cleanup(entry);
    new FieldFormatterCleanup(FieldName.URL, new ClearFormatter()).cleanup(entry);
}
Also used : FieldFormatterCleanup(org.jabref.model.cleanup.FieldFormatterCleanup) ClearFormatter(org.jabref.logic.formatter.bibtexfields.ClearFormatter) NormalizePagesFormatter(org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter)

Example 2 with NormalizePagesFormatter

use of org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter in project jabref by JabRef.

the class CleanupWorkerTest method cleanupPageNumbersConvertsSingleDashToDouble.

@Test
public void cleanupPageNumbersConvertsSingleDashToDouble() {
    CleanupPreset preset = new CleanupPreset(new FieldFormatterCleanups(true, Collections.singletonList(new FieldFormatterCleanup("pages", new NormalizePagesFormatter()))));
    BibEntry entry = new BibEntry();
    entry.setField("pages", "1-2");
    worker.cleanup(preset, entry);
    Assert.assertEquals(Optional.of("1--2"), entry.getField("pages"));
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) FieldFormatterCleanups(org.jabref.model.cleanup.FieldFormatterCleanups) FieldFormatterCleanup(org.jabref.model.cleanup.FieldFormatterCleanup) NormalizePagesFormatter(org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter) Test(org.junit.Test)

Example 3 with NormalizePagesFormatter

use of org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter in project jabref by JabRef.

the class IsbnViaEbookDeFetcher method doPostCleanup.

@Override
public void doPostCleanup(BibEntry entry) {
    // We MUST NOT clean the URL. this is the deal with ebook.de
    // DO NOT add following code:
    // new FieldFormatterCleanup(FieldName.URL, new ClearFormatter()).cleanup(entry);
    // Fetcher returns page numbers as "30 Seiten" -> remove every non-digit character in the PAGETOTAL field
    entry.getField(FieldName.PAGETOTAL).ifPresent(pages -> entry.setField(FieldName.PAGETOTAL, pages.replaceAll("[\\D]", "")));
    new FieldFormatterCleanup(FieldName.PAGETOTAL, new NormalizePagesFormatter()).cleanup(entry);
    new FieldFormatterCleanup(FieldName.AUTHOR, new NormalizeNamesFormatter()).cleanup(entry);
}
Also used : NormalizeNamesFormatter(org.jabref.logic.formatter.bibtexfields.NormalizeNamesFormatter) FieldFormatterCleanup(org.jabref.model.cleanup.FieldFormatterCleanup) NormalizePagesFormatter(org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter)

Example 4 with NormalizePagesFormatter

use of org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter in project jabref by JabRef.

the class FieldFormatterCleanupsTest method checkMultipleSaveActionsWithMultipleFormatters.

@Test
public void checkMultipleSaveActionsWithMultipleFormatters() {
    FieldFormatterCleanups actions = new FieldFormatterCleanups(true, Cleanups.parse("pages[normalize_page_numbers,normalize_date]title[lower_case]"));
    List<FieldFormatterCleanup> formatterCleanups = actions.getConfiguredActions();
    FieldFormatterCleanup normalizePages = new FieldFormatterCleanup("pages", new NormalizePagesFormatter());
    FieldFormatterCleanup normalizeDatesInPages = new FieldFormatterCleanup("pages", new NormalizeDateFormatter());
    FieldFormatterCleanup lowerCaseTitle = new FieldFormatterCleanup("title", new LowerCaseFormatter());
    assertEquals(Arrays.asList(normalizePages, normalizeDatesInPages, lowerCaseTitle), formatterCleanups);
    actions.applySaveActions(entry);
    assertEquals(Optional.of("educational session 1"), entry.getField("title"));
    assertEquals(Optional.of("1--7"), entry.getField("pages"));
}
Also used : NormalizeDateFormatter(org.jabref.logic.formatter.bibtexfields.NormalizeDateFormatter) FieldFormatterCleanups(org.jabref.model.cleanup.FieldFormatterCleanups) FieldFormatterCleanup(org.jabref.model.cleanup.FieldFormatterCleanup) NormalizePagesFormatter(org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter) LowerCaseFormatter(org.jabref.logic.formatter.casechanger.LowerCaseFormatter) Test(org.junit.Test)

Example 5 with NormalizePagesFormatter

use of org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter in project jabref by JabRef.

the class FieldFormatterCleanupsTest method checkMultipleSaveActions.

@Test
public void checkMultipleSaveActions() {
    FieldFormatterCleanups actions = new FieldFormatterCleanups(true, Cleanups.parse("pages[normalize_page_numbers]title[lower_case]"));
    List<FieldFormatterCleanup> formatterCleanups = actions.getConfiguredActions();
    FieldFormatterCleanup normalizePages = new FieldFormatterCleanup("pages", new NormalizePagesFormatter());
    FieldFormatterCleanup lowerCaseTitle = new FieldFormatterCleanup("title", new LowerCaseFormatter());
    assertEquals(Arrays.asList(normalizePages, lowerCaseTitle), formatterCleanups);
    actions.applySaveActions(entry);
    assertEquals(Optional.of("educational session 1"), entry.getField("title"));
    assertEquals(Optional.of("1--7"), entry.getField("pages"));
}
Also used : FieldFormatterCleanups(org.jabref.model.cleanup.FieldFormatterCleanups) FieldFormatterCleanup(org.jabref.model.cleanup.FieldFormatterCleanup) NormalizePagesFormatter(org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter) LowerCaseFormatter(org.jabref.logic.formatter.casechanger.LowerCaseFormatter) Test(org.junit.Test)

Aggregations

NormalizePagesFormatter (org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter)5 FieldFormatterCleanup (org.jabref.model.cleanup.FieldFormatterCleanup)5 FieldFormatterCleanups (org.jabref.model.cleanup.FieldFormatterCleanups)3 Test (org.junit.Test)3 LowerCaseFormatter (org.jabref.logic.formatter.casechanger.LowerCaseFormatter)2 ClearFormatter (org.jabref.logic.formatter.bibtexfields.ClearFormatter)1 NormalizeDateFormatter (org.jabref.logic.formatter.bibtexfields.NormalizeDateFormatter)1 NormalizeNamesFormatter (org.jabref.logic.formatter.bibtexfields.NormalizeNamesFormatter)1 BibEntry (org.jabref.model.entry.BibEntry)1