@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {
for (Sentence sentence : JCasUtil.select(jCas, Sentence.class)) {
List<BaseToken> tokens = JCasUtil.selectCovered(jCas, BaseToken.class, sentence);
DepTree tree = new DepTree();
// Build map between CAS dependency node and id for later creation of
// ClearParser dependency node/tree
Map<ConllDependencyNode, Integer> depNodeToID = new HashMap<ConllDependencyNode, Integer>();
int nodeId = 1;
for (ConllDependencyNode depNode : JCasUtil.selectCovered(jCas, ConllDependencyNode.class, sentence)) {
//if (depNode instanceof TopDependencyNode) {
if (depNode.getHead() == null) {
// A node without the head is the head of the sentence
depNodeToID.put(depNode, 0);
} else {
depNodeToID.put(depNode, nodeId);
nodeId++;
}
}
// Initialize Token / Sentence info for the ClearParser Semantic Role Labeler
for (int i = 0; i < tokens.size(); i++) {
BaseToken token = tokens.get(i);
// Determine HeadId
DepNode node = new DepNode();
ConllDependencyNode casDepNode = JCasUtil.selectCovered(jCas, ConllDependencyNode.class, token).get(0);
casDepNode.getDeprel();
String headRelation = casDepNode.getDeprel();
ConllDependencyNode head = casDepNode.getHead();
// If there is no head, this is the head node, set node to 0
int headId = (head == null) ? 0 : depNodeToID.get(head);
// Populate Dependency Node / Tree information
node.id = i + 1;
node.form = token.getCoveredText();
node.pos = token.getPartOfSpeech();
node.lemma = useLemmatizer ? "" : token.getNormalizedForm();
node.setHead(headId, headRelation, 0);
tree.add(node);
}
tree.setPredicates(AbstractReader.LANG_EN);
// Run the SRL
parser.parse(tree);
// Convert ClearParser SRL output to CAS types