/** * Creates annotations for each node in parse tree <CODE>node</NODE>. * These annotations are added to the parse tree; in addition, if * Document <CODE>doc</CODE> is non-empty, they are added to the document. * <P> * Note that this method does not set the "children" attribute. * * @param node * @param doc */ private void setAnnotations(ParseTreeNode node, Document doc) { Span span = new Span(node.start, node.end); FeatureSet attrs = new FeatureSet(); attrs.put("cat", node.category); if (node.head != 0) { attrs.put("head", node.head); } if (node.function != null) { attrs.put("func", node.function); } node.ann = new Annotation("constit", span, attrs); if (doc != null) { doc.addAnnotation(node.ann); } if (node.children != null) { for (ParseTreeNode child : node.children) { setAnnotations(child, doc); } } }
public void apply(Document doc, List<Object> values, Span span, DateTime ref) { Map params = getParameters(); String value = (String) params.get("value"); String diff = (String) params.get("diff"); String dir = (String) params.get("dir"); DateTime val = ref; if (value != null) { value = assignValues(value, values); val = new DateTime(value); } else if (diff != null) { diff = assignValues(diff, values); Period period = new Period(diff); if (dir == null || dir.equals("plus")) { val = ref.plus(period); } else if (dir.equals("minus")) { val = ref.minus(period); } } else { val = ref; // use set_xxx for (Map.Entry entry : (Set<Map.Entry>) params.entrySet()) { Matcher m = Pattern.compile("set_(.*)").matcher((String) entry.getKey()); if (m.matches()) { String field = assignValues((String) entry.getValue(), values); String fieldName = m.group(1); if (fieldName.equals("month")) { int month = Integer.parseInt(field); val = getTimeAnnotator().normalizeMonth(val, month); } else if (fieldName.equals("day")) { int day = Integer.parseInt(field); val = val.withField(DateTimeFieldType.dayOfMonth(), day); } else { throw new InternalError(); } } } } String formattedDate = formatter.print(val); FeatureSet attrs = new FeatureSet(); attrs.put("VAL", formattedDate); doc.annotate("TIMEX2", span, attrs); }