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

Fixes RIS' data field #5101

merged 4 commits into from
Jul 11, 2019

Conversation

victorjof
Copy link
Contributor

This pull resquest fixes issue #4816.

When importing RIS files Jabref checks for date fields (Y1,PY,DA and Y2) and uses the first one it finds. The problem is that Y2 refers to access date, DA in most cases is a generic date, and PY is the publication year(reliable field)*.

} else if (!foundDate && (("Y1".equals(tag) || "Y2".equals(tag) || "PY".equals(tag) || "DA".equals(tag)) && (value.length() >= 4))) {
String year = value.substring(0, 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;

We couldn't find references to Y1('primary date'?). However, as already cited in #4816, and by doing some exports we found Y1 to be PY's synonym, furthermore, when PY received a higher priority than Y1, some tests cases didn't pass as there were a missing month field in .bib.

We established a priority system indicated by the dateTags (lowest index higher priority)

https://github.com/VMichelan/jabref/blob/2f243c16f08f2cfeba6f1ab4651970d90eb55546/src/main/java/org/jabref/logic/importer/fileformat/RisImporter.java#L31

We added 2 test cases for this and changed one of the old ones adding the month field.

*https://web.archive.org/web/20120717122530/http://refman.com/support/direct%20export.zip
** nicely displayed in: https://github.com/aurimasv/translators/wiki/RIS-Tag-Map


  • Change in CHANGELOG.md described
  • Tests created for changes
  • Manually tested changed features in running JabRef
  • Screenshots added in PR description (for bigger UI changes)
  • Ensured that the git commit message is a good one
  • Check documentation status (Issue created for outdated help page at help.jabref.org?)

@Siedlerchr Siedlerchr added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Jul 4, 2019
Copy link
Member

@Siedlerchr Siedlerchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! 👍
Only some minor code improvements, but in general it looks fine. and the tests are also a good thing!

Abbreviates  isDateTag() and getDatePriority()
@VMichelan
Copy link
Contributor

Thanks for the feedback @Siedlerchr!

Those are great suggestions, using a List is much better, and since indexOf returns -1 if it doesn't find the element, we can use it to find out if the element is in dateTags and to get its index like this:

} else if ((tagPriority = dateTags.indexOf(tag)) != -1 && value.length() >= 4) {

    if (tagPriority < datePriority) {

I think this is a good solution, the problem is that like isDateTag it's also O(n), I don't know if that's really a problem, but if it is maybe we should use a HashMap?

Also, since finding out if a tag is a date is a one liner now, I will remove the isDateTag and getDatePriority methods, and because we don't need to pass dateTags to these methods anymore I think we should move it from the class to the method importDatabase.

I would like to hear what you think about these considerations, I think with this out of the way we can make the final version and fix the failed check to make it ready for merge, thanks.

@@ -193,25 +198,20 @@ 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 (isDateTag(tag) && value.length() >= 4) {
Copy link
Member

@Siedlerchr Siedlerchr Jul 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have an even better idea, you can omit one search in the list,
If you directly use the indexOf before the if/else cases and init it e.g. next to the month initialisation
you can then simply reuse the value here if it's <0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I coudn't figure out what you meant here, the month initialization is outside of the loop

            Optional<Month> month = Optional.empty();
            Map<String, String> fields = new HashMap<>();

            String[] lines = entry1.split("\n");

            for (int j = 0; j < lines.length; j++) {

but the tag variable is only declared and used inside of the loop, so I couldn't use indexOf(tag) at this point in the code, so I kept the if statement that way.

@Siedlerchr
Copy link
Member

If your ArrayList is ordered/sorted, you can use Collections,binarySearch, but I think in this case it's over engineering ;)

Premature optimization is the root of all evil ~ Donald Knuth

The complexity really is only for large N.
But I think you can omit one time searching the list, see my comment at the code.

Copy link
Member

@Siedlerchr Siedlerchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick follow up, looks good now!

@koppor koppor merged commit 95f6c1e into JabRef:master Jul 11, 2019
@koppor
Copy link
Member

koppor commented Jul 11, 2019

Thank you for your work!

github-actions bot pushed a commit that referenced this pull request Dec 1, 2020
a20406d Added name of the editors of a given edition (#5140)
9881fc5 Ping on push, not PR, document role of dist-updater (#5137)
04668cc Create nouvelles-perspectives-en-sciences-sociales.csl (#5063)
1d94e21 Update bursa-uludag-universitesi-saglik-bilimleri-enstitusu.csl (#5047)
84f3893 Add Harvard style for Metropolia University of Applied Sciences (#5086)
8e43e79 Create opto-electronic-advances.csl (#5135)
36e4fba Update society-for-american-archaeology.csl (#5124)
69ca360 St. Paul Canon Law new style (#5138)
b490ab0 Update and rename st-paul-university-faculty-of-canon-law.csl to saint-paul-university-faculty-of-canon-law.csl
b498116 There is no en-CA locale
3c35f28 Metadata
7059cca Create tu-dortmund-agvm.csl (#5088)
c321c98 Create new Citation type (#5093)
a7edc8d Update international-organization.csl (#5103)
3d1a052 The AWS load balancer is messing things up (#5133)
ca3839b Fix sort by a single macro (#5136)
5d1a7e8 Update chungara-revista-de-antropologia-chilena.csl (#5123)
cd75d5d ping distribution-updater (#5132)
dcf473a Update wirtschaftsuniversitat-wien-health-care-management.csl (#5125)
a87085e Fix Harvard Praxisforschung Editors (#5130)
d4176ca Switch automated tests to Github Actions (#5111)
726d0d8 Radiology, MPP, CORR -- small fixes: https://forums.zotero.org/discussion/85883/doi-radiology#latest https://forums.zotero.org/discussion/51058/style-request-molecular-plant-pathology#latest https://forums.zotero.org/discussion/85678/citing-style-clinical-orthopaedics-and-related-research#latest
e23db68 Update to la-trobe-university-harvard style (#5119)
c54b278 Create wirtschaftsuniversitat-wien-health-care-management.csl (#5110)
62fb019 Create austral-entomology.csl (#5118)
afa328c Update iso690-author-date-en.csl (#5113)
5468dce Update iso690-author-date-fr-no-abstract.csl (#5112)
98af86c Update iso690-numeric-fr.csl (#5115)
09f84c4 Update iso690-author-date-fr.csl (#5114)
178a9e4 Fix current biology to superscript
1fa5ce7 Create droit-belge-centre-de-droit-prive-ulb.csl (#5107)
3a6a4bc Fix file modes (#5106)
48f50e5 Create chungara-revista-de-antropologia-chilena.csl (#5096)
1e848f8 Create the-journal-of-the-indian-law-institute.csl (#5100)
856524c Create molecular-biology.csl (#5101)
eeebbf4 Create harvard-harper-adams-university.csl (#5104)
d90993d Fix tests
d4037bf WIP: St Paul Canon Law style

git-subtree-dir: src/main/resources/csl-styles
git-subtree-split: a20406d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants