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;
}
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());
}
Aggregations