diff --git a/CHANGELOG.md b/CHANGELOG.md index b37788b3b76..d4d193ddab3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv ### Changed +- The Pubmed/Medline Plain importer now imports the PMID field as well [#11488](https://github.com/JabRef/jabref/issues/11488) - The 'Check for updates' menu bar button is now always enabled. [#11485](https://github.com/JabRef/jabref/pull/11485) - JabRef respects the [configuration for storing files relative to the .bib file](https://docs.jabref.org/finding-sorting-and-cleaning-entries/filelinks#directories-for-files) in more cases. [#11492](https://github.com/JabRef/jabref/pull/11492) diff --git a/src/main/java/org/jabref/logic/importer/fileformat/MedlinePlainImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/MedlinePlainImporter.java index c66aef80d45..d383377bd12 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/MedlinePlainImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/MedlinePlainImporter.java @@ -149,6 +149,7 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException { // store the fields in a map Map hashMap = new HashMap<>(); + hashMap.put("PMID", StandardField.PMID); hashMap.put("PG", StandardField.PAGES); hashMap.put("PL", StandardField.ADDRESS); hashMap.put("PHST", new UnknownField("history")); diff --git a/src/test/java/org/jabref/logic/importer/fileformat/MedlinePlainImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/MedlinePlainImporterTest.java index 0ac32eb8cc6..7871ef805b1 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/MedlinePlainImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/MedlinePlainImporterTest.java @@ -117,11 +117,13 @@ void importMultipleEntriesInSingleFile() throws IOException, URISyntaxException assertEquals(Optional.of("Inproceedings book title"), testEntry.getField(StandardField.BOOKTITLE)); BibEntry expectedEntry5 = new BibEntry(StandardEntryType.Proceedings) - .withField(StandardField.KEYWORDS, "Female"); + .withField(StandardField.KEYWORDS, "Female") + .withField(StandardField.PMID, "96578310"); assertEquals(expectedEntry5, entries.get(5)); BibEntry expectedEntry6 = new BibEntry(StandardEntryType.Misc) - .withField(StandardField.KEYWORDS, "Female"); + .withField(StandardField.KEYWORDS, "Female") + .withField(StandardField.PMID, "45984220"); assertEquals(expectedEntry6, entries.get(6)); } @@ -158,19 +160,49 @@ private void assertImportOfMedlineFileEqualsBibtexFile(String medlineFile, Strin @Test void multiLineComments() throws IOException { - try (BufferedReader reader = readerForString("PMID-22664220" + "\n" + "CON - Comment1" + "\n" + "CIN - Comment2" - + "\n" + "EIN - Comment3" + "\n" + "EFR - Comment4" + "\n" + "CRI - Comment5" + "\n" + "CRF - Comment6" - + "\n" + "PRIN- Comment7" + "\n" + "PROF- Comment8" + "\n" + "RPI - Comment9" + "\n" + "RPF - Comment10" - + "\n" + "RIN - Comment11" + "\n" + "ROF - Comment12" + "\n" + "UIN - Comment13" + "\n" - + "UOF - Comment14" + "\n" + "SPIN- Comment15" + "\n" + "ORI - Comment16")) { + try (BufferedReader reader = readerForString(""" + PMID-22664220 + CON - Comment1 + CIN - Comment2\ + + EIN - Comment3 + EFR - Comment4 + CRI - Comment5 + CRF - Comment6\ + + PRIN- Comment7 + PROF- Comment8 + RPI - Comment9 + RPF - Comment10\ + + RIN - Comment11 + ROF - Comment12 + UIN - Comment13 + UOF - Comment14 + SPIN- Comment15 + ORI - Comment16""")) { List actualEntries = importer.importDatabase(reader).getDatabase().getEntries(); BibEntry expectedEntry = new BibEntry(); + expectedEntry.setField(StandardField.PMID, "22664220"); expectedEntry.setField(StandardField.COMMENT, - "Comment1" + "\n" + "Comment2" + "\n" + "Comment3" + "\n" + "Comment4" + "\n" + "Comment5" + "\n" - + "Comment6" + "\n" + "Comment7" + "\n" + "Comment8" + "\n" + "Comment9" + "\n" - + "Comment10" + "\n" + "Comment11" + "\n" + "Comment12" + "\n" + "Comment13" + "\n" - + "Comment14" + "\n" + "Comment15" + "\n" + "Comment16"); + """ + Comment1 + Comment2 + Comment3 + Comment4 + Comment5 + Comment6 + Comment7 + Comment8 + Comment9 + Comment10 + Comment11 + Comment12 + Comment13 + Comment14 + Comment15 + Comment16"""); assertEquals(Collections.singletonList(expectedEntry), actualEntries); } } @@ -184,6 +216,7 @@ void keyWords() throws IOException { List actualEntries = importer.importDatabase(reader).getDatabase().getEntries(); BibEntry expectedEntry = new BibEntry(); + expectedEntry.setField(StandardField.PMID, "22664795"); expectedEntry.setField(StandardField.KEYWORDS, "Female, Male"); assertEquals(Collections.singletonList(expectedEntry), actualEntries); @@ -200,7 +233,7 @@ void withNbibFile() throws IOException, URISyntaxException { } @Test - void withMultipleEntries() throws IOException, URISyntaxException { + void withMultipleEntriesInvalidFormat() throws IOException, URISyntaxException { Path file = Path.of(MedlinePlainImporter.class.getResource("MedlinePlainImporterStringOutOfBounds.txt").toURI()); List entries = importer.importDatabase(file).getDatabase().getEntries(); @@ -229,14 +262,20 @@ void nullReader() throws IOException { @Test void allArticleTypes() throws IOException { - try (BufferedReader reader = readerForString("PMID-22664795" + "\n" + "MH - Female\n" + "PT - journal article" - + "\n" + "PT - classical article" + "\n" + "PT - corrected and republished article" + "\n" - + "PT - introductory journal article" + "\n" + "PT - newspaper article")) { + try (BufferedReader reader = readerForString(""" + PMID-22664795 + MH - Female + PT - journal article\ + + PT - classical article + PT - corrected and republished article + PT - introductory journal article + PT - newspaper article""")) { List actualEntries = importer.importDatabase(reader).getDatabase().getEntries(); - BibEntry expectedEntry = new BibEntry(); - expectedEntry.setType(StandardEntryType.Article); - expectedEntry.setField(StandardField.KEYWORDS, "Female"); + BibEntry expectedEntry = new BibEntry(StandardEntryType.Article) + .withField(StandardField.KEYWORDS, "Female") + .withField(StandardField.PMID, "22664795"); assertEquals(Collections.singletonList(expectedEntry), actualEntries); } diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/MedlinePlainImporterStringOutOfBounds.bib b/src/test/resources/org/jabref/logic/importer/fileformat/MedlinePlainImporterStringOutOfBounds.bib index cf5f8e920e8..74631a03b1f 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/MedlinePlainImporterStringOutOfBounds.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/MedlinePlainImporterStringOutOfBounds.bib @@ -1,6 +1,9 @@ @misc{, - title = {This is a test title} + title = {This is a test title}, + pmid = {27433151 SO invalid line}, + } @misc{, - title = {This is also a test title} + title = {This is also a test title}, + pmid = {27394443 SO- another invalid line}, } diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/MedlinePlainImporterTestCompleteEntry.bib b/src/test/resources/org/jabref/logic/importer/fileformat/MedlinePlainImporterTestCompleteEntry.bib index 02ebcde0152..c1cd9983aeb 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/MedlinePlainImporterTestCompleteEntry.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/MedlinePlainImporterTestCompleteEntry.bib @@ -15,6 +15,7 @@ @article{ other-id = {NLM: PMC4513071}, owner = {NLM}, pages = {454-81}, + pmid = {20481061}, print-issn = {0955-2359}, publication-status = {ppublish}, revised = {20150731}, diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/MedlinePlainImporterTestDOI.bib b/src/test/resources/org/jabref/logic/importer/fileformat/MedlinePlainImporterTestDOI.bib index c4e061c9f3d..8b18625dd22 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/MedlinePlainImporterTestDOI.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/MedlinePlainImporterTestDOI.bib @@ -1,3 +1,4 @@ @TechReport{, - doi = {10.1016/j.cpr.2005.02.002} + doi = {10.1016/j.cpr.2005.02.002}, + pmid = {22664220}, } diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/MedlinePlainImporterTestInproceeding.bib b/src/test/resources/org/jabref/logic/importer/fileformat/MedlinePlainImporterTestInproceeding.bib index 27745e9c3ec..5ffa3dcd3fb 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/MedlinePlainImporterTestInproceeding.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/MedlinePlainImporterTestInproceeding.bib @@ -1,3 +1,5 @@ @InProceedings{, - Booktitle = {Inproceedings book title} + Booktitle = {Inproceedings book title}, + pmid = {22664238}, + } diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/NbibImporterTest.bib b/src/test/resources/org/jabref/logic/importer/fileformat/NbibImporterTest.bib index f8f7210461f..81b3427c506 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/NbibImporterTest.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/NbibImporterTest.bib @@ -29,6 +29,7 @@ @article{ other-abstract = {other abstract infos}, owner = {NLM}, pages = {67}, + pmid = {27169098}, publication-status = {epublish}, registry-number = {123456789}, second-id = {12563},