Skip to content

Commit

Permalink
Fix default resource loading from jarfile
Browse files Browse the repository at this point in the history
  • Loading branch information
qqndrew committed Feb 2, 2022
1 parent eb0d8f1 commit 16a2744
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.ohnlp.medtagger</groupId>
<artifactId>medtagger</artifactId>
<version>1.0.21</version>
<version>1.0.22</version>
<description>The MedTagger biomedical information extraction pipeline</description>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,22 @@ public void initialize(UimaContext aContext)
lvg = new LvgLookup(aContext);
String dictfile = (String) aContext
.getConfigParameterValue("dict_file");
InputStream is;
if (dictfile == null) {
dictfile = AhoCorasickLookupAnnotator.class.getResource("/medtaggerresources/lookup/PASC.lookup.dict")
.toURI().toString();
is = AhoCorasickLookupAnnotator.class.getResourceAsStream("/medtaggerresources/lookup/PASC.lookup.dict");
} else {
is = Files.newInputStream(Paths.get(URI.create(dictfile)));
}
btac = new AhoCorasickDict(Files.newInputStream(Paths.get(URI.create(dictfile))));
btac = new AhoCorasickDict(is);
String stpfile = (String) aContext
.getConfigParameterValue("stop_file");
if (stpfile == null) {
stpfile = AhoCorasickLookupAnnotator.class.getResource("/medtaggerresources/lookup/stop.615")
.toURI().toString();
}
is = AhoCorasickLookupAnnotator.class.getResourceAsStream("/medtaggerresources/lookup/stop.615");
} else {
is = Files.newInputStream(Paths.get(URI.create(stpfile)));
}
stop = new HashSet<String>();
BufferedReader br = new BufferedReader(new InputStreamReader(
Files.newInputStream(Paths.get(URI.create(stpfile)))
));
BufferedReader br = new BufferedReader(new InputStreamReader(is));
while (br.ready()) {
String line = br.readLine();
if (line.startsWith("#")) continue;
Expand All @@ -107,12 +108,11 @@ public void initialize(UimaContext aContext)
String abrfile = (String) aContext
.getConfigParameterValue("abbr_file");
if (abrfile == null) {
abrfile = AhoCorasickLookupAnnotator.class.getResource("/medtaggerresources/lookup/OHNLP_ohdsi.abbr")
.toURI().toString();
}
br = new BufferedReader(new InputStreamReader(
Files.newInputStream(Paths.get(URI.create(abrfile)))
));
is = AhoCorasickLookupAnnotator.class.getResourceAsStream("/medtaggerresources/lookup/OHNLP_ohdsi.abbr");
} else {
is = Files.newInputStream(Paths.get(URI.create(abrfile)));
}
br = new BufferedReader(new InputStreamReader(is));
while (br.ready()) {
String line = br.readLine();
if (line.startsWith("#")) continue;
Expand All @@ -123,7 +123,7 @@ public void initialize(UimaContext aContext)
}
br.close();

} catch (ResourceAccessException | IOException | URISyntaxException e) {
} catch (ResourceAccessException | IOException e) {
throw new ResourceInitializationException(e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.FileSystem;
import java.nio.file.FileSystemNotFoundException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.spi.FileSystemProvider;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.MatchResult;
Expand All @@ -68,21 +72,19 @@ public class RuleContextAnnotator extends JCasAnnotator_ImplBase {
public void initialize(UimaContext ctxt) throws ResourceInitializationException {
super.initialize(ctxt);
String ruleset = (String) ctxt.getConfigParameterValue("context_ruleset");

InputStream is = null;
try {
if (ruleset == null) {
ruleset = ConTexTSettings.class.getResource("/medtaggerresources/context/contextRule.txt").toURI().toString();
is = ConTexTSettings.class.getResourceAsStream("/medtaggerresources/context/contextRule.txt");
} else {
ruleset = Paths.get(URI.create(ruleset)).resolve("context").resolve("contextRule.txt").toUri().toString();
is = Files.newInputStream(Paths.get(URI.create(ruleset)).resolve("context").resolve("contextRule.txt"));
}
contextSettings = new LinkedList<>();
for (int priority : RULE_PRIORITIES) {
contextSettings.add(new ConTexTSettings(Files.newInputStream(Paths.get(URI.create(ruleset))), priority));
contextSettings.add(new ConTexTSettings(is, priority));
}
} catch (FileNotFoundException | URISyntaxException e) {
throw new ResourceInitializationException(e);
} catch (IOException e) {
e.printStackTrace();
throw new ResourceInitializationException(e);
}
}

Expand Down

0 comments on commit 16a2744

Please sign in to comment.