/** * Convenience method for adding an annotation to this span, same as * <code>getSpanTree().{@link SpanTree#annotate(SpanNode,Annotation) spanTree.annotate(this,annotation)}</code> * * @param annotation the annotation to add * @return this for chaining * @throws NullPointerException if this span is not attached to a tree */ public SpanNode annotate(Annotation annotation) { getNonNullSpanTree().annotate(this, annotation); return this; }
/** * Convenience method for adding an annotation with no value to this span, same as * <code>getSpanTree().{@link SpanTree#annotate(SpanNode,AnnotationType) spanTree.annotate(this,type)}</code> * * @param type the type of the annotation to add * @return this for chaining * @throws NullPointerException if this span is not attached to a tree */ public SpanNode annotate(AnnotationType type) { getNonNullSpanTree().annotate(this,type); return this; }
/** * Convenience method for adding an annotation to this span, same as * <code>getSpanTree().{@link SpanTree#annotate(SpanNode,AnnotationType,FieldValue) spanTree.annotate(this,type,value)}</code> * * @param type the type of the annotation to add * @param value the value of the annotation to add * @return this for chaining * @throws NullPointerException if this span is not attached to a tree */ public SpanNode annotate(AnnotationType type,FieldValue value) { getNonNullSpanTree().annotate(this,type,value); return this; }
/** * Adds an Annotation. * Convenience shorthand for <code>annotate(node,new Annotation(type,value)</code> * * @param node the node to annotate * @param type the type of the Annotation to add * @param value the value of the Annotation to add * @return this, for chaining * @see com.yahoo.document.annotation.Annotation */ public SpanTree annotate(SpanNode node, AnnotationType type,FieldValue value) { return annotate(node, new Annotation(type, value)); }
/** * Adds an Annotation to the internal list of annotations for this SpanTree. Use this when * adding an Annotation that shall annotate a SpanNode. Upon return, Annotation.getSpanNode() * returns the given node. * * @param node the node to annotate * @param annotation the Annotation to add * @return this, for chaining * @see com.yahoo.document.annotation.Annotation */ public SpanTree annotate(SpanNode node, Annotation annotation) { annotation.setSpanNode(node); return annotate(annotation); }
/** * Creates an Annotation based on the given AnnotationType, and adds it to the internal list of * annotations for this SpanTree (convenience method). Use this when * adding an Annotation (that does not have a FieldValue) that shall annotate a SpanNode. * Upon return, Annotation.getSpanNode() * returns the given node. * * @param node the node to annotate * @param type the AnnotationType to create an Annotation from * @return this, for chaining * @see com.yahoo.document.annotation.Annotation * @see com.yahoo.document.annotation.AnnotationType */ public SpanTree annotate(SpanNode node, AnnotationType type) { Annotation a = new Annotation(type); return annotate(node, a); }
/** * Convenience method for adding an annotation to this span, same as * <code>getSpanTree().{@link SpanTree#annotate(SpanNode,AnnotationType,FieldValue) spanTree.annotate(this,type,new IntegerFieldValue(value))}</code> * * @param type the type of the annotation to add * @param value the integer value of the annotation to add * @return this for chaining * @throws NullPointerException if this span is not attached to a tree */ public SpanNode annotate(AnnotationType type,Integer value) { getNonNullSpanTree().annotate(this, type, new IntegerFieldValue(value)); return this; }
/** * Convenience method for adding an annotation to this span, same as * <code>getSpanTree().{@link SpanTree#annotate(SpanNode,AnnotationType,FieldValue) spanTree.annotate(this,type,new StringFieldValue(value))}</code> * * @param type the type of the annotation to add * @param value the string value of the annotation to add * @return this for chaining * @throws NullPointerException if this span is not attached to a tree */ public SpanNode annotate(AnnotationType type,String value) { getNonNullSpanTree().annotate(this, type, new StringFieldValue(value)); return this; }
@Override protected void doExecute(ExecutionContext ctx) { StringFieldValue input = (StringFieldValue)ctx.getValue(); if (input.getString().isEmpty()) { return; } StringFieldValue output = input.clone(); ctx.setValue(output); String prev = output.getString(); String next = toLowerCase(prev); SpanList root = new SpanList(); SpanTree tree = new SpanTree(SpanTrees.LINGUISTICS, root); SpanNode node = new Span(0, prev.length()); tree.annotate(node, new Annotation(AnnotationTypes.TERM, next.equals(prev) ? null : new StringFieldValue(next))); tree.annotate(node, new Annotation(AnnotationTypes.TOKEN_TYPE, new IntegerFieldValue(TokenType.ALPHABETIC.getValue()))); root.add(node); output.setSpanTree(tree); }