/** * Selects a single TreebankNode leaf that has the same span as the given annotation. * * @param jCas * The JCas containing the TreebankNodes. * @param annotation * The Annotation whose span should match a TreebankNode leaf. * @return The single TreebankNode leaf that matches the annotation, or null if no such annotation * exists. */ public static TreebankNode selectMatchingLeaf(JCas jCas, Annotation annotation) { TreebankNode leaf = null; for (TreebankNode node : JCasUtil.selectCovered(jCas, TreebankNode.class, annotation)) { if (node.getLeaf() && node.getBegin() == annotation.getBegin() && node.getEnd() == annotation.getEnd()) { if (leaf == null) { leaf = node; } else { throw new IllegalArgumentException(String.format( "expected one leaf matching annotation %s, found %s", annotation, Arrays.asList(leaf, node))); } } } return leaf; }
private Event getOrCreateEvent(JCas jCas, Anchor anchor, TreebankNode node) { if (anchor != null && anchor instanceof Event) { return (Event) anchor; } else if (this.createEvents) { Event event = new Event(jCas, node.getBegin(), node.getEnd()); event.setId("e" + this.eventID); this.eventID++; event.addToIndexes(); return event; } else { return null; } }
/** * Selects the highest TreebankNode in the parse tree that is at least partially covered by the * given annotation. * * @param jCas * The JCas containing the TreebankNodes. * @param annotation * The Annotation whose span should be matched. * @return The highest TreebankNode at least partially covered by the given span, or null if no * such annotation exists. */ public static TreebankNode selectHighestCoveredTreebankNode(JCas jCas, Annotation annotation) { TreebankNode highestNode = null; int smallestDepth = Integer.MAX_VALUE; for (TreebankNode node : JCasUtil.selectCovered(jCas, TreebankNode.class, annotation)) { if (annotation.getBegin() <= node.getBegin() && node.getEnd() <= annotation.getEnd()) { int depth = getDepth(node); if (depth < smallestDepth) { highestNode = node; smallestDepth = depth; } } } return highestNode; }
/** * Selects the highest TreebankNode in the parse tree that has the same span as the given * annotation. * * @param jCas * The JCas containing the TreebankNodes. * @param annotation * The Annotation whose span should be matched. * @return The highest TreebankNode matching the given span, or null if no such annotation exists. */ public static TreebankNode selectHighestMatchingTreebankNode(JCas jCas, Annotation annotation) { TreebankNode highestNode = null; int smallestDepth = Integer.MAX_VALUE; for (TreebankNode node : JCasUtil.selectCovered(jCas, TreebankNode.class, annotation)) { if (node.getBegin() == annotation.getBegin() && node.getEnd() == annotation.getEnd()) { int depth = getDepth(node); if (depth < smallestDepth) { highestNode = node; smallestDepth = depth; } } } return highestNode; }
/** * Create a branch TreebankNode in a JCas. The offsets of this node will be determined by its * children. * * @param jCas * The JCas which the annotation should be added to. * @param nodeType * The phrase type tag of the node. * @param children * The TreebankNode children of the node. * @return The TreebankNode which was added to the JCas. */ public static TreebankNode newNode(JCas jCas, String nodeType, TreebankNode... children) { int begin = children[0].getBegin(); int end = children[children.length - 1].getEnd(); TreebankNode node = new TreebankNode(jCas, begin, end); node.setNodeType(nodeType); node.addToIndexes(); FSArray fsArray = new FSArray(jCas, children.length); fsArray.copyFromArray(children, 0, 0, children.length); node.setChildren(fsArray); for (TreebankNode child : children) { child.setParent(node); } return node; }
leafNodes); int nodeBegin = uimaChildren.get(0).getBegin(); int nodeEnd = uimaChildren.get(uimaChildren.size() - 1).getEnd();