Skip to content

Commit 234ee2e

Browse files
Siedlerchrcalixtus
andauthored
import PMID field in Pubmed (#11513)
* import PMID field in Pubmed Fixes #11488 * fix tests --------- Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com>
1 parent 714abd1 commit 234ee2e

File tree

8 files changed

+71
-22
lines changed

8 files changed

+71
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
1717

1818
### Changed
1919

20+
- The Pubmed/Medline Plain importer now imports the PMID field as well [#11488](https://github.com/JabRef/jabref/issues/11488)
2021
- The 'Check for updates' menu bar button is now always enabled. [#11485](https://github.com/JabRef/jabref/pull/11485)
2122
- 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)
2223

src/main/java/org/jabref/logic/importer/fileformat/MedlinePlainImporter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException {
149149

150150
// store the fields in a map
151151
Map<String, Field> hashMap = new HashMap<>();
152+
hashMap.put("PMID", StandardField.PMID);
152153
hashMap.put("PG", StandardField.PAGES);
153154
hashMap.put("PL", StandardField.ADDRESS);
154155
hashMap.put("PHST", new UnknownField("history"));

src/test/java/org/jabref/logic/importer/fileformat/MedlinePlainImporterTest.java

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,13 @@ void importMultipleEntriesInSingleFile() throws IOException, URISyntaxException
117117
assertEquals(Optional.of("Inproceedings book title"), testEntry.getField(StandardField.BOOKTITLE));
118118

119119
BibEntry expectedEntry5 = new BibEntry(StandardEntryType.Proceedings)
120-
.withField(StandardField.KEYWORDS, "Female");
120+
.withField(StandardField.KEYWORDS, "Female")
121+
.withField(StandardField.PMID, "96578310");
121122
assertEquals(expectedEntry5, entries.get(5));
122123

123124
BibEntry expectedEntry6 = new BibEntry(StandardEntryType.Misc)
124-
.withField(StandardField.KEYWORDS, "Female");
125+
.withField(StandardField.KEYWORDS, "Female")
126+
.withField(StandardField.PMID, "45984220");
125127
assertEquals(expectedEntry6, entries.get(6));
126128
}
127129

@@ -158,19 +160,49 @@ private void assertImportOfMedlineFileEqualsBibtexFile(String medlineFile, Strin
158160

159161
@Test
160162
void multiLineComments() throws IOException {
161-
try (BufferedReader reader = readerForString("PMID-22664220" + "\n" + "CON - Comment1" + "\n" + "CIN - Comment2"
162-
+ "\n" + "EIN - Comment3" + "\n" + "EFR - Comment4" + "\n" + "CRI - Comment5" + "\n" + "CRF - Comment6"
163-
+ "\n" + "PRIN- Comment7" + "\n" + "PROF- Comment8" + "\n" + "RPI - Comment9" + "\n" + "RPF - Comment10"
164-
+ "\n" + "RIN - Comment11" + "\n" + "ROF - Comment12" + "\n" + "UIN - Comment13" + "\n"
165-
+ "UOF - Comment14" + "\n" + "SPIN- Comment15" + "\n" + "ORI - Comment16")) {
163+
try (BufferedReader reader = readerForString("""
164+
PMID-22664220
165+
CON - Comment1
166+
CIN - Comment2\
167+
168+
EIN - Comment3
169+
EFR - Comment4
170+
CRI - Comment5
171+
CRF - Comment6\
172+
173+
PRIN- Comment7
174+
PROF- Comment8
175+
RPI - Comment9
176+
RPF - Comment10\
177+
178+
RIN - Comment11
179+
ROF - Comment12
180+
UIN - Comment13
181+
UOF - Comment14
182+
SPIN- Comment15
183+
ORI - Comment16""")) {
166184
List<BibEntry> actualEntries = importer.importDatabase(reader).getDatabase().getEntries();
167185
BibEntry expectedEntry = new BibEntry();
168186

187+
expectedEntry.setField(StandardField.PMID, "22664220");
169188
expectedEntry.setField(StandardField.COMMENT,
170-
"Comment1" + "\n" + "Comment2" + "\n" + "Comment3" + "\n" + "Comment4" + "\n" + "Comment5" + "\n"
171-
+ "Comment6" + "\n" + "Comment7" + "\n" + "Comment8" + "\n" + "Comment9" + "\n"
172-
+ "Comment10" + "\n" + "Comment11" + "\n" + "Comment12" + "\n" + "Comment13" + "\n"
173-
+ "Comment14" + "\n" + "Comment15" + "\n" + "Comment16");
189+
"""
190+
Comment1
191+
Comment2
192+
Comment3
193+
Comment4
194+
Comment5
195+
Comment6
196+
Comment7
197+
Comment8
198+
Comment9
199+
Comment10
200+
Comment11
201+
Comment12
202+
Comment13
203+
Comment14
204+
Comment15
205+
Comment16""");
174206
assertEquals(Collections.singletonList(expectedEntry), actualEntries);
175207
}
176208
}
@@ -184,6 +216,7 @@ void keyWords() throws IOException {
184216
List<BibEntry> actualEntries = importer.importDatabase(reader).getDatabase().getEntries();
185217

186218
BibEntry expectedEntry = new BibEntry();
219+
expectedEntry.setField(StandardField.PMID, "22664795");
187220
expectedEntry.setField(StandardField.KEYWORDS, "Female, Male");
188221

189222
assertEquals(Collections.singletonList(expectedEntry), actualEntries);
@@ -200,7 +233,7 @@ void withNbibFile() throws IOException, URISyntaxException {
200233
}
201234

202235
@Test
203-
void withMultipleEntries() throws IOException, URISyntaxException {
236+
void withMultipleEntriesInvalidFormat() throws IOException, URISyntaxException {
204237
Path file = Path.of(MedlinePlainImporter.class.getResource("MedlinePlainImporterStringOutOfBounds.txt").toURI());
205238

206239
List<BibEntry> entries = importer.importDatabase(file).getDatabase().getEntries();
@@ -229,14 +262,20 @@ void nullReader() throws IOException {
229262

230263
@Test
231264
void allArticleTypes() throws IOException {
232-
try (BufferedReader reader = readerForString("PMID-22664795" + "\n" + "MH - Female\n" + "PT - journal article"
233-
+ "\n" + "PT - classical article" + "\n" + "PT - corrected and republished article" + "\n"
234-
+ "PT - introductory journal article" + "\n" + "PT - newspaper article")) {
265+
try (BufferedReader reader = readerForString("""
266+
PMID-22664795
267+
MH - Female
268+
PT - journal article\
269+
270+
PT - classical article
271+
PT - corrected and republished article
272+
PT - introductory journal article
273+
PT - newspaper article""")) {
235274
List<BibEntry> actualEntries = importer.importDatabase(reader).getDatabase().getEntries();
236275

237-
BibEntry expectedEntry = new BibEntry();
238-
expectedEntry.setType(StandardEntryType.Article);
239-
expectedEntry.setField(StandardField.KEYWORDS, "Female");
276+
BibEntry expectedEntry = new BibEntry(StandardEntryType.Article)
277+
.withField(StandardField.KEYWORDS, "Female")
278+
.withField(StandardField.PMID, "22664795");
240279

241280
assertEquals(Collections.singletonList(expectedEntry), actualEntries);
242281
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
@misc{,
2-
title = {This is a test title}
2+
title = {This is a test title},
3+
pmid = {27433151 SO invalid line},
4+
35
}
46
@misc{,
5-
title = {This is also a test title}
7+
title = {This is also a test title},
8+
pmid = {27394443 SO- another invalid line},
69
}

src/test/resources/org/jabref/logic/importer/fileformat/MedlinePlainImporterTestCompleteEntry.bib

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ @article{
1515
other-id = {NLM: PMC4513071},
1616
owner = {NLM},
1717
pages = {454-81},
18+
pmid = {20481061},
1819
print-issn = {0955-2359},
1920
publication-status = {ppublish},
2021
revised = {20150731},
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
@TechReport{,
2-
doi = {10.1016/j.cpr.2005.02.002}
2+
doi = {10.1016/j.cpr.2005.02.002},
3+
pmid = {22664220},
34
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
@InProceedings{,
2-
Booktitle = {Inproceedings book title}
2+
Booktitle = {Inproceedings book title},
3+
pmid = {22664238},
4+
35
}

src/test/resources/org/jabref/logic/importer/fileformat/NbibImporterTest.bib

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ @article{
2929
other-abstract = {other abstract infos},
3030
owner = {NLM},
3131
pages = {67},
32+
pmid = {27169098},
3233
publication-status = {epublish},
3334
registry-number = {123456789},
3435
second-id = {12563},

0 commit comments

Comments
 (0)