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

Fixes RIS' data field #5101

Merged
merged 4 commits into from
Jul 11, 2019
Merged
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
52 changes: 34 additions & 18 deletions src/main/java/org/jabref/logic/importer/fileformat/RisImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
Expand All @@ -27,7 +28,7 @@ public class RisImporter extends Importer {

private static final Pattern RECOGNIZED_FORMAT_PATTERN = Pattern.compile("TY - .*");
private static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy");

@Override
public String getName() {
return "RIS";
Expand Down Expand Up @@ -59,9 +60,15 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException {
String[] entries = linesAsString.replace("\u2013", "-").replace("\u2014", "--").replace("\u2015", "--")
.split("ER -.*\\n");

//stores all the date tags from highest to lowest priority
List<String> dateTags = Arrays.asList("Y1", "PY", "DA", "Y2");

for (String entry1 : entries) {

boolean foundDate = false;
String dateTag = "";
String dateValue = "";
int datePriority = dateTags.size();
int tagPriority;

String type = "";
String author = "";
Expand Down Expand Up @@ -193,25 +200,19 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException {
}
} else if ("UR".equals(tag) || "L2".equals(tag) || "LK".equals(tag)) {
fields.put(FieldName.URL, value);
} else if (!foundDate && (("Y1".equals(tag) || "Y2".equals(tag) || "PY".equals(tag) || "DA".equals(tag)) && (value.length() >= 4))) {
String year = value.substring(0, 4);
} else if ((tagPriority = dateTags.indexOf(tag)) != -1 && value.length() >= 4) {

try {
Year.parse(year, formatter);
//if the year is parsebale we have found our date
fields.put(FieldName.YEAR, value.substring(0, 4));
foundDate = true;
} catch (DateTimeParseException ex) {
//We can't parse the year, we ignore it
}
if (tagPriority < datePriority) {
String year = value.substring(0, 4);

String[] parts = value.split("/");
if ((parts.length > 1) && !parts[1].isEmpty()) {
try {
int monthNumber = Integer.parseInt(parts[1]);
month = Month.getMonthByNumber(monthNumber);
} catch (NumberFormatException ex) {
// The month part is unparseable, so we ignore it.
Year.parse(year, formatter);
//if the year is parsebale we have found a higher priority date
dateTag = tag;
dateValue = value;
datePriority = tagPriority;
} catch (DateTimeParseException ex) {
//We can't parse the year, we ignore it
}
}
} else if ("KW".equals(tag)) {
Expand Down Expand Up @@ -277,6 +278,21 @@ else if ("AV".equals(tag)) {
fields.put(FieldName.PAGES, startPage + endPage);
}

// if we found a date
if (dateTag.length() > 0) {
fields.put(FieldName.YEAR, dateValue.substring(0, 4));

String[] parts = dateValue.split("/");
if ((parts.length > 1) && !parts[1].isEmpty()) {
try {
int monthNumber = Integer.parseInt(parts[1]);
month = Month.getMonthByNumber(monthNumber);
} catch (NumberFormatException ex) {
// The month part is unparseable, so we ignore it.
}
}
}

// Remove empty fields:
fields.entrySet().removeIf(key -> (key.getValue() == null) || key.getValue().trim().isEmpty());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ @incollection{
issn = {978-1-4822-5326-9},
journal = {Dermoscopy Image Analysis},
number = {0},
month = {#sep#},
pages = {1-22},
publisher = {CRC Press},
series = {Digital Imaging and Computer Vision},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@article{,
author = {Valle-Delgado, J. J. and Molina-Bolívar, J. A. and Galisteo-González, F. and Gálvez-Ruiz, M. J. and Feiler, A. and Rutland, M. W.},
comment = {doi: 10.1063/1.1954747},
doi = {10.1063/1.1954747},
issn = {0021-9606},
journal = {J. Chem. Phys.},
month = {#jul#},
number = {3},
pages = {034708},
publisher = {American Institute of Physics},
title = {Hydration forces between silica surfaces: Experimental data and predictions from different theories},
url = {https://doi.org/10.1063/1.1954747},
volume = {123},
year = {2005}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@


TY - JOUR
T1 - Hydration forces between silica surfaces: Experimental data and predictions from different theories
AU - Valle-Delgado,J. J.
AU - Molina-Bolívar,J. A.
AU - Galisteo-González,F.
AU - Gálvez-Ruiz,M. J.
AU - Feiler,A.
AU - Rutland,M. W.
Y2 - 2019/03/28
Y1 - 2005/07/15
PY - 2005
DA - 2005/07/15
N1 - doi: 10.1063/1.1954747
DO - 10.1063/1.1954747
T2 - The Journal of Chemical Physics
JF - The Journal of Chemical Physics
JO - J. Chem. Phys.
SP - 034708
VL - 123
IS - 3
PB - American Institute of Physics
SN - 0021-9606
M3 - doi: 10.1063/1.1954747
UR - https://doi.org/10.1063/1.1954747
ER -
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@article{,
author = {Valle-Delgado, J. J. and Molina-Bolívar, J. A. and Galisteo-González, F. and Gálvez-Ruiz, M. J. and Feiler, A. and Rutland, M. W.},
comment = {doi: 10.1063/1.1954747},
doi = {10.1063/1.1954747},
issn = {0021-9606},
journal = {J. Chem. Phys.},
month = {#jul#},
number = {3},
pages = {034708},
publisher = {American Institute of Physics},
title = {Hydration forces between silica surfaces: Experimental data and predictions from different theories},
url = {https://doi.org/10.1063/1.1954747},
volume = {123},
year = {2005}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@


TY - JOUR
T1 - Hydration forces between silica surfaces: Experimental data and predictions from different theories
AU - Valle-Delgado,J. J.
AU - Molina-Bolívar,J. A.
AU - Galisteo-González,F.
AU - Gálvez-Ruiz,M. J.
AU - Feiler,A.
AU - Rutland,M. W.
Y1 - 2005/07/15
PY - 2005
DA - 2005/07/15
Y2 - 2019/03/28
N1 - doi: 10.1063/1.1954747
DO - 10.1063/1.1954747
T2 - The Journal of Chemical Physics
JF - The Journal of Chemical Physics
JO - J. Chem. Phys.
SP - 034708
VL - 123
IS - 3
PB - American Institute of Physics
SN - 0021-9606
M3 - doi: 10.1063/1.1954747
UR - https://doi.org/10.1063/1.1954747
ER -