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

import PMID field in Pubmed #11513

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
- 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)

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException {

// store the fields in a map
Map<String, Field> hashMap = new HashMap<>();
hashMap.put("PMID", StandardField.PMID);
hashMap.put("PG", StandardField.PAGES);
hashMap.put("PL", StandardField.ADDRESS);
hashMap.put("PHST", new UnknownField("history"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down Expand Up @@ -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<BibEntry> 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);
}
}
Expand All @@ -184,6 +216,7 @@ void keyWords() throws IOException {
List<BibEntry> 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);
Expand All @@ -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<BibEntry> entries = importer.importDatabase(file).getDatabase().getEntries();
Expand Down Expand Up @@ -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<BibEntry> 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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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},
}
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@TechReport{,
doi = {10.1016/j.cpr.2005.02.002}
doi = {10.1016/j.cpr.2005.02.002},
pmid = {22664220},
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@InProceedings{,
Booktitle = {Inproceedings book title}
Booktitle = {Inproceedings book title},
pmid = {22664238},

}
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down