Search in sources :

Example 1 with StringFieldValue

use of com.yahoo.document.datatypes.StringFieldValue in project vespa by vespa-engine.

the class Rot13DocumentProcessor method process.

@Override
public Progress process(Processing processing) {
    int oldVal = counter.getAndIncrement();
    if ((oldVal % 3) != 0) {
        return Progress.LATER;
    }
    for (DocumentOperation op : processing.getDocumentOperations()) {
        if (op instanceof DocumentPut) {
            Document document = ((DocumentPut) op).getDocument();
            StringFieldValue oldTitle = (StringFieldValue) document.getFieldValue(FIELD_NAME);
            if (oldTitle != null) {
                document.setFieldValue(FIELD_NAME, rot13(oldTitle.getString()));
            }
        }
    }
    return Progress.DONE;
}
Also used : DocumentOperation(com.yahoo.document.DocumentOperation) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentPut(com.yahoo.document.DocumentPut) Document(com.yahoo.document.Document)

Example 2 with StringFieldValue

use of com.yahoo.document.datatypes.StringFieldValue in project vespa by vespa-engine.

the class LinguisticsAnnotatorTestCase method requireThatCompositeTokensAreFlattened.

@Test
public void requireThatCompositeTokensAreFlattened() {
    SpanTree expected = new SpanTree(SpanTrees.LINGUISTICS);
    expected.spanList().span(0, 3).annotate(new Annotation(AnnotationTypes.TERM, new StringFieldValue("foo")));
    expected.spanList().span(3, 3).annotate(new Annotation(AnnotationTypes.TERM, new StringFieldValue("bar")));
    expected.spanList().span(6, 3).annotate(new Annotation(AnnotationTypes.TERM, new StringFieldValue("baz")));
    SimpleToken token = newToken("FOOBARBAZ", "foobarbaz", TokenType.ALPHABETIC).addComponent(newToken("FOO", "foo", TokenType.ALPHABETIC).setOffset(0)).addComponent(newToken("BARBAZ", "barbaz", TokenType.ALPHABETIC).setOffset(3).addComponent(newToken("BAR", "bar", TokenType.ALPHABETIC).setOffset(3)).addComponent(newToken("BAZ", "baz", TokenType.ALPHABETIC).setOffset(6)));
    assertAnnotations(expected, "foobarbaz", token);
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) SimpleToken(com.yahoo.language.simple.SimpleToken) Annotation(com.yahoo.document.annotation.Annotation) SpanTree(com.yahoo.document.annotation.SpanTree) Test(org.junit.Test)

Example 3 with StringFieldValue

use of com.yahoo.document.datatypes.StringFieldValue in project vespa by vespa-engine.

the class LinguisticsAnnotatorTestCase method requireThatExistingAnnotationsAreKept.

@Test
public void requireThatExistingAnnotationsAreKept() {
    SpanTree spanTree = new SpanTree(SpanTrees.LINGUISTICS);
    spanTree.spanList().span(0, 3).annotate(new Annotation(AnnotationTypes.TERM, new StringFieldValue("baz")));
    StringFieldValue val = new StringFieldValue("foo");
    val.setSpanTree(spanTree);
    Linguistics linguistics = newLinguistics(Arrays.asList(newToken("foo", "bar", TokenType.ALPHABETIC, false)), Collections.<String, String>emptyMap());
    new LinguisticsAnnotator(linguistics, CONFIG).annotate(val);
    assertTrue(new LinguisticsAnnotator(linguistics, CONFIG).annotate(val));
    assertEquals(spanTree, val.getSpanTree(SpanTrees.LINGUISTICS));
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) Linguistics(com.yahoo.language.Linguistics) SimpleLinguistics(com.yahoo.language.simple.SimpleLinguistics) Annotation(com.yahoo.document.annotation.Annotation) SpanTree(com.yahoo.document.annotation.SpanTree) Test(org.junit.Test)

Example 4 with StringFieldValue

use of com.yahoo.document.datatypes.StringFieldValue in project vespa by vespa-engine.

the class LinguisticsAnnotatorTestCase method assertAnnotations.

private static void assertAnnotations(SpanTree expected, String str, Linguistics linguistics) {
    StringFieldValue val = new StringFieldValue(str);
    assertEquals(expected != null, new LinguisticsAnnotator(linguistics, CONFIG).annotate(val));
    assertEquals(expected, val.getSpanTree(SpanTrees.LINGUISTICS));
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue)

Example 5 with StringFieldValue

use of com.yahoo.document.datatypes.StringFieldValue in project vespa by vespa-engine.

the class LinguisticsAnnotatorTestCase method requireThatCompositeSpecialTokensAreNotFlattened.

@Test
public void requireThatCompositeSpecialTokensAreNotFlattened() {
    SpanTree expected = new SpanTree(SpanTrees.LINGUISTICS);
    expected.spanList().span(0, 9).annotate(new Annotation(AnnotationTypes.TERM, new StringFieldValue("foobarbaz")));
    SimpleToken token = newToken("FOOBARBAZ", "foobarbaz", TokenType.ALPHABETIC).setSpecialToken(true).addComponent(newToken("FOO", "foo", TokenType.ALPHABETIC).setOffset(0)).addComponent(newToken("BARBAZ", "barbaz", TokenType.ALPHABETIC).setOffset(3).addComponent(newToken("BAR", "bar", TokenType.ALPHABETIC).setOffset(3)).addComponent(newToken("BAZ", "baz", TokenType.ALPHABETIC).setOffset(6)));
    assertAnnotations(expected, "foobarbaz", token);
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) SimpleToken(com.yahoo.language.simple.SimpleToken) Annotation(com.yahoo.document.annotation.Annotation) SpanTree(com.yahoo.document.annotation.SpanTree) Test(org.junit.Test)

Aggregations

StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)210 Test (org.junit.Test)136 FieldValue (com.yahoo.document.datatypes.FieldValue)49 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)40 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)37 Document (com.yahoo.document.Document)30 Array (com.yahoo.document.datatypes.Array)25 DocumentType (com.yahoo.document.DocumentType)21 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)21 Struct (com.yahoo.document.datatypes.Struct)21 DocumentPut (com.yahoo.document.DocumentPut)20 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)20 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)18 SpanTree (com.yahoo.document.annotation.SpanTree)15 FieldUpdate (com.yahoo.document.update.FieldUpdate)15 DocumentUpdate (com.yahoo.document.DocumentUpdate)12 Field (com.yahoo.document.Field)12 Annotation (com.yahoo.document.annotation.Annotation)12 FloatFieldValue (com.yahoo.document.datatypes.FloatFieldValue)12 HashMap (java.util.HashMap)12