private static List<Time> getSubordinateTimes(Event event, Sentence sentence, JCas jCas) { List<Time> times = new ArrayList<Time>(); TreebankNode eventNode = selectMatchingLeaf(jCas, event); for (Time time : JCasUtil.selectCovered(jCas, Time.class, sentence)) { TreebankNode timeNode = selectHighestCoveredTreebankNode(jCas, time); if (eventNode != null && timeNode != null) { String path = noLeavesPath(TreebankNodeUtil.getPath(eventNode, timeNode)); if (SUBORDINATE_PATH_PATTERN.matcher(path).matches()) { times.add(time); } } } return times; } }
private List<Event> getSubordinateEvents(JCas jCas, Event source, Sentence sentence) { List<Event> targets = new ArrayList<Event>(); TreebankNode sourceNode = TreebankNodeUtil.selectMatchingLeaf(jCas, source); for (Event target : JCasUtil.selectCovered(jCas, Event.class, sentence)) { if (!target.equals(source)) { TreebankNode targetNode = TreebankNodeUtil.selectMatchingLeaf(jCas, target); if (sourceNode != null && targetNode != null) { String path = noLeavesPath(TreebankNodeUtil.getPath(sourceNode, targetNode)); if (SUBORDINATE_PATH_PATTERN.matcher(path).matches()) { targets.add(target); } } } } return targets; } }
public List<Feature> extract(JCas jCas, T source, U target) { List<Feature> features = new ArrayList<Feature>(); TreebankNode sourceNode = TreebankNodeUtil.selectMatchingLeaf(jCas, source); TreebankNode targetNode = TreebankNodeUtil.selectMatchingLeaf(jCas, target); if (sourceNode != null && targetNode != null) { TreebankNodePath path = TreebankNodeUtil.getPath(sourceNode, targetNode); TreebankNode ancestor = path.getCommonAncestor(); features.add(new Feature("CommonAncestor", ancestor == null ? null : ancestor.getNodeType())); features.add(new Feature("SourceToAncestor", pathString(path.getSourceToAncestorPath()))); features.add(new Feature("TargetToAncestor", pathString(path.getTargetToAncestorPath()))); } return features; }