Skip to content

Commit

Permalink
Dynamic context loading for backbone
Browse files Browse the repository at this point in the history
  • Loading branch information
qqndrew committed Jan 26, 2022
1 parent 2d4da10 commit d21f0dc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,12 @@ public void init() throws IOException, InvalidXMLException, URISyntaxException,
// Tokenization, Sentence Splitting, Section Detection, etc.
ae.add(createEngineDescription("desc.backbone.aes.PreConceptExtractionAE"));
// Add the appropriate NER/normalization component depending on run mode
URI uri = null;
switch (mode) {
case OHNLPTK_DEFINED: // Ruleset from a web service
throw new UnsupportedOperationException("Remote Served IE Rulesets not yet implemented");
case STANDALONE:
final URI uri = MedTaggerPipelineFunction.class.getResource("/resources/" + this.resourceFolder).toURI();
uri = MedTaggerPipelineFunction.class.getResource("/resources/" + this.resourceFolder).toURI();
Map<String, String> env = new HashMap<>();
env.put("create", "true");
try {
Expand All @@ -111,7 +112,11 @@ public void init() throws IOException, InvalidXMLException, URISyntaxException,
}

// Add Context handling
ae.add(AnalysisEngineFactory.createEngineDescription(RuleContextAnnotator.class));
if (uri != null) {
ae.add(AnalysisEngineFactory.createEngineDescription(RuleContextAnnotator.class, "context_ruleset", uri.toString()));
} else {
ae.add(AnalysisEngineFactory.createEngineDescription(RuleContextAnnotator.class));
}

this.resMgr = ResourceManagerFactory.newResourceManager();
this.aae = UIMAFramework.produceAnalysisEngine(ae.createAggregateDescription(), resMgr, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
import org.ohnlp.typesystem.type.textspan.Sentence;

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

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

0 comments on commit d21f0dc

Please sign in to comment.