Search in sources :

Example 1 with JournalAbbreviationPreferences

use of org.jabref.logic.journals.JournalAbbreviationPreferences in project jabref by JabRef.

the class IEEEXploreFetcher method cleanup.

private BibEntry cleanup(BibEntry entry) {
    if (entry == null) {
        return null;
    }
    // clean up title
    entry.getField(FieldName.TITLE).ifPresent(dirtyTitle -> {
        String title = dirtyTitle.replaceAll("[ ]?img src=[^ ]+ alt=\"([^\"]+)\">[ ]?", "\\$$1\\$");
        title = title.replaceAll("/sub /spl infin//", "\\$_\\\\infty\\$");
        title = title.replaceAll("/sup /spl infin//", "\\$\\^\\\\infty\\$");
        title = title.replaceAll("/[sS]pl ([^/]+)/", "\\$\\\\$1\\$");
        title = SUPER_DETECTION_1.matcher(title).replaceAll(SUPER_TEXT_RESULT);
        title = SUB_DETECTION_1.matcher(title).replaceAll(SUB_TEXT_RESULT);
        title = SUPER_DETECTION_2.matcher(title).replaceAll(SUPER_TEXT_RESULT);
        title = SUB_DETECTION_2.matcher(title).replaceAll(SUB_TEXT_RESULT);
        title = title.replaceAll("\\\\infin", "\\\\infty");
        if (Globals.prefs.getBoolean(JabRefPreferences.USE_UNIT_FORMATTER_ON_SEARCH)) {
            title = unitsToLatexFormatter.format(title);
        }
        if (Globals.prefs.getBoolean(JabRefPreferences.USE_CASE_KEEPER_ON_SEARCH)) {
            title = protectTermsFormatter.format(title);
        }
        entry.setField(FieldName.TITLE, title);
    });
    // clean up author
    entry.getField(FieldName.AUTHOR).ifPresent(dirtyAuthor -> {
        String author = dirtyAuthor.replaceAll("\\s+", " ");
        String[] authorSplit = author.split("(^\\s*|\\s*$|\\s+and\\s+)");
        List<String> authorResult = new ArrayList<>();
        for (String authorSplitPart : authorSplit) {
            authorResult.add(authorSplitPart.replaceAll("(.+?),(.+?),(.+)", "$1,$3,$2"));
        }
        author = String.join(" and ", authorResult);
        author = author.replace(".", ". ").replace("  ", " ").replace(". -", ".-").replace("; ", " and ").replace(" ,", ",").replace("  ", " ");
        author = author.replaceAll("[ ,;]+$", "");
        entry.setField(FieldName.AUTHOR, author);
    });
    // clean up month
    entry.getField(FieldName.MONTH).filter(month -> !month.isEmpty()).ifPresent(dirtyMonth -> {
        String month = dirtyMonth.replace(".", "");
        month = month.toLowerCase(Locale.ROOT);
        Matcher mm = MONTH_PATTERN.matcher(month);
        StringBuilder date = new StringBuilder(month);
        if (mm.find()) {
            if (mm.group(3).isEmpty()) {
                if (mm.group(2).isEmpty()) {
                    date = new StringBuilder().append(mm.group(1)).append(',');
                } else {
                    date = new StringBuilder().append('#').append(mm.group(2).substring(0, 3)).append('#');
                    if (!mm.group(1).isEmpty()) {
                        date.append(' ').append(mm.group(1)).append(',');
                    }
                }
            } else if (mm.group(2).isEmpty()) {
                if (mm.group(4).isEmpty()) {
                    date.append(',');
                } else {
                    date = new StringBuilder().append('#').append(mm.group(4).substring(0, 3)).append('#').append(mm.group(1)).append("--").append(mm.group(3)).append(',');
                }
            } else {
                date = new StringBuilder().append('#').append(mm.group(2).substring(0, 3)).append('#').append(mm.group(1)).append("--#").append(mm.group(4).substring(0, 3)).append('#').append(mm.group(3)).append(',');
            }
        }
        entry.setField(FieldName.MONTH, date.toString());
    });
    // clean up pages
    entry.getField(FieldName.PAGES).ifPresent(pages -> {
        String[] pageNumbers = pages.split("-");
        if (pageNumbers.length == 2) {
            if (pageNumbers[0].equals(pageNumbers[1])) {
                entry.setField(FieldName.PAGES, pageNumbers[0]);
            } else {
                entry.setField(FieldName.PAGES, pages.replace("-", "--"));
            }
        }
    });
    // clean up publication field
    String type = entry.getType();
    String sourceField = "";
    if ("article".equals(type)) {
        sourceField = FieldName.JOURNAL;
        entry.clearField(FieldName.BOOKTITLE);
    } else if ("inproceedings".equals(type)) {
        sourceField = FieldName.BOOKTITLE;
    }
    if (entry.hasField(sourceField)) {
        String fullName = entry.getField(sourceField).get();
        if ("article".equals(type)) {
            int ind = fullName.indexOf(": Accepted for future publication");
            if (ind > 0) {
                fullName = fullName.substring(0, ind);
                entry.setField(FieldName.YEAR, "to be published");
                entry.clearField(FieldName.MONTH);
                entry.clearField(FieldName.PAGES);
                entry.clearField(FieldName.NUMBER);
            }
            //[see also...], [legacy...]
            String[] parts = fullName.split("[\\[\\]]");
            fullName = parts[0];
            if (parts.length == 3) {
                fullName += parts[2];
            }
            entry.getField(FieldName.NOTE).filter(note -> "Early Access".equals(note)).ifPresent(note -> {
                entry.setField(FieldName.YEAR, "to be published");
                entry.clearField(FieldName.MONTH);
                entry.clearField(FieldName.PAGES);
                entry.clearField(FieldName.NUMBER);
            });
        } else {
            fullName = fullName.replace("Conference Proceedings", "Proceedings").replace("Proceedings of", "Proceedings").replace("Proceedings.", "Proceedings");
            fullName = fullName.replace("International", "Int.");
            fullName = fullName.replace("Symposium", "Symp.");
            fullName = fullName.replace("Conference", "Conf.");
            fullName = fullName.replace(" on", " ").replace("  ", " ");
        }
        Matcher m1 = PUBLICATION_PATTERN.matcher(fullName);
        String abrvPattern = ".*[^,] '?\\d+\\)?";
        if (m1.find()) {
            String prefix = m1.group(2).trim();
            String postfix = m1.group(1).trim();
            String abrv = "";
            String[] parts = prefix.split("\\. ", 2);
            if (parts.length == 2) {
                if (parts[0].matches(abrvPattern)) {
                    prefix = parts[1];
                    abrv = parts[0];
                } else {
                    prefix = parts[0];
                    abrv = parts[1];
                }
            }
            if (prefix.matches(abrvPattern)) {
                fullName = postfix + " " + prefix;
            } else {
                fullName = prefix + " " + postfix + " " + abrv;
                fullName = fullName.trim();
            }
        }
        if ("article".equals(type)) {
            //IEE Proceedings-
            fullName = fullName.replace(" - ", "-");
            fullName = fullName.trim();
            JournalAbbreviationPreferences journalAbbreviationPreferences = Globals.prefs.getJournalAbbreviationPreferences();
            if (journalAbbreviationPreferences.useIEEEAbbreviations()) {
                fullName = abbreviationLoader.getRepository(journalAbbreviationPreferences).getMedlineAbbreviation(fullName).orElse(fullName);
            }
        }
        if ("inproceedings".equals(type)) {
            Matcher m2 = PROCEEDINGS_PATTERN.matcher(fullName);
            if (m2.find()) {
                String prefix = m2.group(2);
                String postfix = m2.group(1).replaceAll("\\.$", "");
                if (prefix.matches(abrvPattern)) {
                    fullName = postfix.trim() + " " + prefix.trim();
                } else {
                    String abrv = "";
                    String[] parts = postfix.split("\\. ", 2);
                    if (parts.length == 2) {
                        if (parts[0].matches(abrvPattern)) {
                            postfix = parts[1];
                            abrv = parts[0];
                        } else {
                            postfix = parts[0];
                            abrv = parts[1];
                        }
                    }
                    fullName = prefix.trim() + " " + postfix.trim() + " " + abrv;
                }
            }
            fullName = fullName.trim();
            fullName = fullName.replaceAll("^[tT]he ", "").replaceAll("^\\d{4} ", "").replaceAll("[,.]$", "");
            Optional<String> year = entry.getField(FieldName.YEAR);
            if (year.isPresent()) {
                fullName = fullName.replaceAll(", " + year.get() + "\\.?", "");
            }
            if (!fullName.contains("Abstract") && !fullName.contains("Summaries") && !fullName.contains("Conference Record")) {
                fullName = "Proc. " + fullName;
            }
        }
        entry.setField(sourceField, fullName);
    }
    // clean up abstract
    entry.getField(FieldName.ABSTRACT).ifPresent(dirtyAbstr -> {
        String abstr = dirtyAbstr.replaceAll("/sub /spl infin//", "\\$_\\\\infty\\$");
        abstr = abstr.replaceAll("/sup /spl infin//", "\\$\\^\\\\infty\\$");
        abstr = abstr.replaceAll("/[sS]pl ([^/]+)/", "\\$\\\\$1\\$");
        abstr = SUPER_DETECTION_1.matcher(abstr).replaceAll(SUPER_TEXT_RESULT);
        abstr = SUB_DETECTION_1.matcher(abstr).replaceAll(SUB_TEXT_RESULT);
        abstr = SUPER_DETECTION_2.matcher(abstr).replaceAll(SUPER_TEXT_RESULT);
        abstr = SUB_DETECTION_2.matcher(abstr).replaceAll(SUB_TEXT_RESULT);
        abstr = abstr.replace("\\infin", "\\infty");
        entry.setField(FieldName.ABSTRACT, abstr);
    });
    // Clean up url
    entry.getField(FieldName.URL).ifPresent(url -> entry.setField(FieldName.URL, "http://ieeexplore.ieee.org" + url.replace("tp=&", "")));
    // Replace ; as keyword separator
    entry.getField(FieldName.KEYWORDS).ifPresent(keys -> entry.setField(FieldName.KEYWORDS, keys.replace(";", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR))));
    return entry;
}
Also used : FieldName(org.jabref.model.entry.FieldName) HtmlToLatexFormatter(org.jabref.logic.formatter.bibtexfields.HtmlToLatexFormatter) OutputPrinter(org.jabref.logic.importer.OutputPrinter) JabRefPreferences(org.jabref.preferences.JabRefPreferences) JournalAbbreviationLoader(org.jabref.logic.journals.JournalAbbreviationLoader) ArrayList(java.util.ArrayList) URLDownload(org.jabref.logic.net.URLDownload) JSONException(org.json.JSONException) Matcher(java.util.regex.Matcher) JSONObject(org.json.JSONObject) CookieHandler(java.net.CookieHandler) Locale(java.util.Locale) BibtexParser(org.jabref.logic.importer.fileformat.BibtexParser) Localization(org.jabref.logic.l10n.Localization) BorderLayout(java.awt.BorderLayout) ImportInspectionDialog(org.jabref.gui.importer.ImportInspectionDialog) ProtectTermsFormatter(org.jabref.logic.formatter.casechanger.ProtectTermsFormatter) HelpFile(org.jabref.logic.help.HelpFile) Iterator(java.util.Iterator) Collection(java.util.Collection) BibEntry(org.jabref.model.entry.BibEntry) IOException(java.io.IOException) JournalAbbreviationPreferences(org.jabref.logic.journals.JournalAbbreviationPreferences) JOptionPane(javax.swing.JOptionPane) Globals(org.jabref.Globals) Objects(java.util.Objects) ParseException(org.jabref.logic.importer.ParseException) List(java.util.List) CookieManager(java.net.CookieManager) JCheckBox(javax.swing.JCheckBox) Optional(java.util.Optional) Log(org.apache.commons.logging.Log) Pattern(java.util.regex.Pattern) UnitsToLatexFormatter(org.jabref.logic.formatter.bibtexfields.UnitsToLatexFormatter) ImportInspector(org.jabref.logic.importer.ImportInspector) LogFactory(org.apache.commons.logging.LogFactory) JPanel(javax.swing.JPanel) JSONArray(org.json.JSONArray) Matcher(java.util.regex.Matcher) JournalAbbreviationPreferences(org.jabref.logic.journals.JournalAbbreviationPreferences) ArrayList(java.util.ArrayList)

Example 2 with JournalAbbreviationPreferences

use of org.jabref.logic.journals.JournalAbbreviationPreferences in project jabref by JabRef.

the class AdvancedTab method storeSettings.

@Override
public void storeSettings() {
    JournalAbbreviationPreferences journalAbbreviationPreferences = Globals.prefs.getJournalAbbreviationPreferences();
    if (journalAbbreviationPreferences.useIEEEAbbreviations() != useIEEEAbrv.isSelected()) {
        journalAbbreviationPreferences.setUseIEEEAbbreviations(useIEEEAbrv.isSelected());
        Globals.prefs.storeJournalAbbreviationPreferences(journalAbbreviationPreferences);
        Globals.journalAbbreviationLoader.update(journalAbbreviationPreferences);
    }
    storeRemoteSettings();
    preferences.putBoolean(JabRefPreferences.USE_CASE_KEEPER_ON_SEARCH, useCaseKeeperOnSearch.isSelected());
    preferences.putBoolean(JabRefPreferences.USE_UNIT_FORMATTER_ON_SEARCH, useUnitFormatterOnSearch.isSelected());
}
Also used : JournalAbbreviationPreferences(org.jabref.logic.journals.JournalAbbreviationPreferences)

Aggregations

JournalAbbreviationPreferences (org.jabref.logic.journals.JournalAbbreviationPreferences)2 BorderLayout (java.awt.BorderLayout)1 IOException (java.io.IOException)1 CookieHandler (java.net.CookieHandler)1 CookieManager (java.net.CookieManager)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Locale (java.util.Locale)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 JCheckBox (javax.swing.JCheckBox)1 JOptionPane (javax.swing.JOptionPane)1 JPanel (javax.swing.JPanel)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1 Globals (org.jabref.Globals)1