Skip to content

Commit

Permalink
Handle case of Medline journal data missing parenthesis
Browse files Browse the repository at this point in the history
  • Loading branch information
markpatton committed Jan 19, 2024
1 parent 0c6a2e7 commit c025bb4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ private Journal read(BufferedReader reader) {
} else if (line.startsWith(ISSN_FIELD)) {
final String issn = extract(line);
final String type = extractType(line);
if (issn.length() > 0) {

if (issn.length() > 0 && type != null) {
j.getIssns().add(String.join(":", type, issn));
}
} else if (line.startsWith(ABBR_FIELD)) {
Expand All @@ -104,7 +105,14 @@ private String extract(String line) {
}

private String extractType(String line) {
return line.substring(line.indexOf("(") + 1, line.indexOf(")")).trim();
int open = line.indexOf("(");
int close = line.indexOf(")");

if (open == -1 || close == -1) {
return null;
}

return line.substring(open + 1, close).trim();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ public void medlineIssnTest() throws Exception {

final List<Journal> records = toTest.readJournals(in, UTF_8).collect(Collectors.toList());

assertEquals(3, records.size());
assertEquals(4, records.size());

assertEquals(records.get(0).getIssns(), Collections.singletonList("Print:0000-0001"));
assertEquals(records.get(1).getIssns(), Collections.singletonList("Online:0000-0002"));
assertEquals(records.get(2).getIssns(), Arrays.asList("Print:0000-0003", "Online:0000-0004"));
assertEquals(records.get(3).getIssns(), Collections.EMPTY_LIST);
}
}

Expand All @@ -57,15 +58,17 @@ public void medlineTitlesAndAbbreviationsTest() throws Exception {

final List<Journal> records = toTest.readJournals(in, UTF_8).collect(Collectors.toList());

assertEquals(3, records.size());
assertEquals(4, records.size());

assertEquals("First Journal", records.get(0).getJournalName());
assertEquals("Second Journal", records.get(1).getJournalName());
assertEquals("Third Journal", records.get(2).getJournalName());
assertEquals("Fourth Journal", records.get(3).getJournalName());

assertEquals("1jr", records.get(0).getNlmta());
assertEquals("2jr", records.get(1).getNlmta());
assertEquals("3jr", records.get(2).getNlmta());
assertEquals("4jr", records.get(3).getNlmta());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ ISSN (Online): 0000-0004
IsoAbbr: 3jr
NlmId: abc1232
--------------------------------------------------------
JrId: 4
JournalTitle: Fourth Journal
MedAbbr: 4jr
ISSN: 0000-0005
IsoAbbr: 3jr
NlmId: abc1233
--------------------------------------------------------

0 comments on commit c025bb4

Please sign in to comment.