Created
December 23, 2011 09:25
-
-
Save renaud/1513709 to your computer and use it in GitHub Desktop.
UIMA Annotation Engine for Python, using Jython
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@TypeCapability(inputs = { TypeSystem.TOKEN }, outputs = { TypeSystem.BIO_ENTITY_MENTION }) | |
public class JythonAE extends JCasAnnotator_ImplBase { | |
public static final String SCRIPT_PATH = "script_path"; | |
@ConfigurationParameter(name = SCRIPT_PATH) | |
private String scriptPath; | |
private PythonInterpreter interp; | |
private String scriptFile; | |
@Override | |
public void initialize(UimaContext context) | |
throws ResourceInitializationException { | |
super.initialize(context); | |
interp = new PythonInterpreter(); | |
try { | |
scriptFile = ResourceHelper.getFile(scriptPath).getAbsolutePath(); | |
} catch (Exception e) { | |
throw new ResourceInitializationException( | |
ResourceInitializationException.NO_RESOURCE_FOR_PARAMETERS, | |
new Object[] { scriptPath }); | |
} | |
} | |
@Override | |
public void process(JCas jcas) throws AnalysisEngineProcessException { | |
try { | |
interp.set("jcas", jcas); // make jcas available in script | |
interp.execfile(scriptFile); | |
} catch (Exception e) { | |
throw new AnalysisEngineProcessException( | |
AnalysisEngineProcessException.ANNOTATOR_EXCEPTION, | |
new Object[] {}, e); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment