Skip to content

Instantly share code, notes, and snippets.

@renaud
Created December 23, 2011 09:54
Show Gist options
  • Save renaud/1513763 to your computer and use it in GitHub Desktop.
Save renaud/1513763 to your computer and use it in GitHub Desktop.
Python test script for UIMA Jython Annotation Engine
# Python imports. for now, only Python std library is possible
import re
# importing Java packages
# see http://wiki.python.org/jython/UserGuide#accessing-java-from-jython
from org.apache.uima.jcas.tcas import Annotation
# jcas object is made available to this script. use it like any python object.
text = jcas.getDocumentText();
regex = re.compile("Dave");
match = regex.search(text);
if (match):
# Create annotation and add it to jcas. This is then accessible from UIMA
annotation = Annotation(jcas, match.start(), match.end());
annotation.addToIndexes();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment