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

Fix OutOfBoundsException when importing multiple entries in medline format #1611

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException {
}
}
String entry = current.toString();
if (!checkLineValidity(entry)) {
continue;
}

String label = entry.substring(0, entry.indexOf('-')).trim();
String value = entry.substring(entry.indexOf('-') + 1).trim();
Expand Down Expand Up @@ -227,13 +230,16 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException {
// create one here
b.setField(fields);
bibitems.add(b);

}

return new ParserResult(bibitems);

}

private boolean checkLineValidity(String line) {
return (line.length() >= 5) && (line.charAt(4) == '-');
}

private String addSourceType(String value, String type) {
String val = value.toLowerCase(Locale.ENGLISH);
String theType = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ public void testWithNbibFile() throws IOException, URISyntaxException {
BibEntryAssert.assertEquals(MedlinePlainImporter.class, "NbibImporterTest.bib", entries);
}

@Test
public void testWithMultipleEntries() throws IOException, URISyntaxException {
Path file = Paths
.get(MedlinePlainImporter.class.getResource("MedlinePlainImporterStringOutOfBounds.txt").toURI());
List<BibEntry> entries = importer.importDatabase(file, Charset.defaultCharset()).getDatabase().getEntries();
Copy link
Member

Choose a reason for hiding this comment

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

When the bib file is in UTF8, then please set the Charset explicit to UTF8, too. DefaultCharsets.UTF8 (or similar), otherwise test will fail on windows in gradle.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

BibEntryAssert.assertEquals(MedlinePlainImporter.class, "MedlinePlainImporterStringOutOfBounds.bib", entries);
}

@Test
public void testAllArticleTypes() throws IOException {
try (BufferedReader reader = readerForString("PMID-22664795" + "\n" +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
% Encoding: UTF-8

@Article{,
author = {Seo, Hyungil and Park, Sang Hyoung and Byeon, Jeong-Sik and Woo, Chang Gok and Hong, Seung-Mo and Chang, Kiju and So, Hoonsub and Kwak, Minseob and Kim, Wan Soo and Lee, Jeong-Mi and Yang, Dong-Hoon and Kim, Kyung-Jo and Ye, Byong Duk and Myung, Seung-Jae and Yang, Suk-Kyun},
title = {Chronic intractable diarrhea caused by gastrointestinal mastocytosis.},
journal = {Intestinal research},
year = {2016},
volume = {14},
pages = {280-4},
month = {Jul},
abstract = {just a dummy},
address = {Korea (South)},
article-doi = {10.5217/ir.2016.14.3.280},
completed = {20160719},
date-created = {20160719},
electronic-publication = {20160627},
history = {2016/06/27 [epublish]},
issue = {3},
keywords = {Diarrhea, Mast cells, Mastocytic enterocolitis},
language = {eng},
linking-issn = {1598-9100},
location-id = {10.5217/ir.2016.14.3.280 [doi]},
nlm-unique-id = {101572802},
owner = {NLM},
print-issn = {1598-9100},
publication-status = {ppublish},
source = {Intest Res. 2016 Jul;14(3):280-4. doi: 10.5217/ir.2016.14.3.280. Epub 2016 Jun 27.},
status = {PubMed-not-MEDLINE},
termowner = {NOTNLM},
title-abbreviation = {Intest Res},
}

@Article{,
author = {Cooper, Kyle J. and Pena, Constantino and Benenati, James},
title = {Determining End Points for Critical Limb Ischemia Interventions.},
journal = {Techniques in vascular and interventional radiology},
year = {2016},
volume = {19},
pages = {104-12},
month = {Jun},
abstract = {second dummy},
address = {United States},
article-doi = {10.1053/j.tvir.2016.04.003},
article-pii = {S1089-2516(16)30003-8},
date-created = {20160718},
electronic-issn = {1557-9808},
electronic-publication = {20160422},
history = {2016/04/22 [aheadofprint]},
issue = {2},
keywords = {Peripheral vascular disease, critical limb ischemia, postprocedural testing, therapeutic end points},
language = {eng},
linking-issn = {1557-9808},
location-id = {S1089-2516(16)30003-8 [pii]},
nlm-unique-id = {9806675},
owner = {NLM},
publication-status = {ppublish},
source = {Tech Vasc Interv Radiol. 2016 Jun;19(2):104-12. doi: 10.1053/j.tvir.2016.04.003. Epub 2016 Apr 22.},
status = {In-Data-Review},
subset = {IM},
termowner = {NOTNLM},
title-abbreviation = {Tech Vasc Interv Radiol},
}

@Article{,
author = {Shetty, Shilpa and Xing, Chao and Garg, Abhimanyu},
title = {Type 1 Hyperlipoproteinemia due to Compound Heterozygous Rare Variants in GCKR.},
journal = {The Journal of clinical endocrinology and metabolism},
year = {2016},
pages = {jc20162179},
month = {Jul},
abstract = {and another dummy},
article-doi = {10.1210/jc.2016-2179},
date-created = {20160712},
electronic-issn = {1945-7197},
electronic-publication = {20160712},
language = {ENG},
linking-issn = {0021-972X},
nlm-unique-id = {0375362},
owner = {NLM},
publication-status = {aheadofprint},
revised = {20160712},
source = {J Clin Endocrinol Metab. 2016 Jul 12:jc20162179.},
status = {Publisher},
title-abbreviation = {J Clin Endocrinol Metab},
}

@Article{,
author = {Li, Shaoheng and Yan, Yuhui and Jiao, Yanan and Gao, Zhong and Xia, Yang and Kong, Liang and Yao, Yingjia and Tao, Zhenyu and Song, Jie and Yan, Yaping and Zhang, Guangxian and Yang, Jingxian},
title = {Neuroprotective Effect of Osthole on Neuron Synapses in an Alzheimer's Disease Cell Model via Upregulation of MicroRNA-9.},
journal = {Journal of molecular neuroscience : MN},
year = {2016},
month = {Jul},
abstract = {here should stand an abstract},
article-doi = {10.1007/s12031-016-0793-9},
article-pii = {10.1007/s12031-016-0793-9},
date-created = {20160710},
electronic-issn = {1559-1166},
electronic-publication = {20160709},
history = {2016/07/09 [aheadofprint]},
keywords = {Alzheimer's disease, Amyloid precursor protein, CAMKK2-AMPK pathway, Neuron synapses, Osthole, miR-9},
language = {ENG},
linking-issn = {0895-8696},
nlm-unique-id = {9002991},
owner = {NLM},
publication-status = {aheadofprint},
revised = {20160710},
source = {J Mol Neurosci. 2016 Jul 9.},
status = {Publisher},
termowner = {NOTNLM},
title-abbreviation = {J Mol Neurosci},
}
Loading