Search in sources :

Example 16 with StringFieldValue

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

the class ExecutionContextTestCase method requireThatExplicitLanguagePreventsDetection.

@Test
public void requireThatExplicitLanguagePreventsDetection() {
    ExecutionContext ctx = new ExecutionContext();
    ctx.setLanguage(Language.ARABIC);
    ctx.setValue(new StringFieldValue("\u3072\u3089\u304c\u306a"));
    assertEquals(Language.ARABIC, ctx.resolveLanguage(new SimpleLinguistics()));
    ctx.setValue(new StringFieldValue("\ud55c\uae00\uacfc"));
    assertEquals(Language.ARABIC, ctx.resolveLanguage(new SimpleLinguistics()));
}
Also used : SimpleLinguistics(com.yahoo.language.simple.SimpleLinguistics) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) Test(org.junit.Test)

Example 17 with StringFieldValue

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

the class FlattenTestCase method requireThatNonSpanAnnotationsAreIgnored.

@Test
public void requireThatNonSpanAnnotationsAreIgnored() {
    SpanTree tree = new SpanTree(SpanTrees.LINGUISTICS);
    tree.annotate(new Annotation(AnnotationTypes.TERM, new StringFieldValue("oof")));
    StringFieldValue val = new StringFieldValue("foo");
    val.setSpanTree(tree);
    assertEquals(new StringFieldValue("foo"), new FlattenExpression().execute(val));
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) Test(org.junit.Test)

Example 18 with StringFieldValue

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

the class FlattenTestCase method requireThatAnnotationsAreFlattened.

@Test
public void requireThatAnnotationsAreFlattened() {
    SpanTree tree = new SpanTree(SpanTrees.LINGUISTICS);
    tree.annotate(new Span(0, 3), new Annotation(AnnotationTypes.TERM, new StringFieldValue("oof")));
    tree.annotate(new Span(4, 3), new Annotation(AnnotationTypes.TERM, new StringFieldValue("rab")));
    tree.annotate(new Span(8, 3), new Annotation(AnnotationTypes.TERM, new StringFieldValue("zab")));
    StringFieldValue val = new StringFieldValue("foo bar baz");
    val.setSpanTree(tree);
    assertEquals(new StringFieldValue("foo[oof] bar[rab] baz[zab]"), new FlattenExpression().execute(val));
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) Test(org.junit.Test)

Example 19 with StringFieldValue

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

the class FlattenTestCase method requireThatAnnotationsAreSorted.

@Test
public void requireThatAnnotationsAreSorted() {
    SpanTree tree = new SpanTree(SpanTrees.LINGUISTICS);
    tree.annotate(new Span(0, 3), new Annotation(AnnotationTypes.TERM, new StringFieldValue("cox")));
    tree.annotate(new Span(0, 3), new Annotation(AnnotationTypes.TERM, new StringFieldValue("baz")));
    tree.annotate(new Span(0, 3), new Annotation(AnnotationTypes.TERM, new StringFieldValue("bar")));
    StringFieldValue val = new StringFieldValue("foo");
    val.setSpanTree(tree);
    assertEquals(new StringFieldValue("foo[bar, baz, cox]"), new FlattenExpression().execute(val));
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) Test(org.junit.Test)

Example 20 with StringFieldValue

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

the class GuardTestCase method requireThatInputFieldsAreIncludedByUpdate.

@Test
public void requireThatInputFieldsAreIncludedByUpdate() throws ParseException {
    DocumentType docType = new DocumentType("my_input");
    docType.addField(new Field("my_lng", DataType.LONG));
    docType.addField(new Field("my_str", DataType.STRING));
    DocumentUpdate docUpdate = new DocumentUpdate(docType, "doc:scheme:");
    docUpdate.addFieldUpdate(FieldUpdate.createAssign(docType.getField("my_str"), new StringFieldValue("69")));
    assertNotNull(docUpdate = Expression.execute(Expression.fromString("guard { input my_str | to_int | attribute my_lng }"), docUpdate));
    assertEquals(0, docUpdate.getFieldPathUpdates().size());
    assertEquals(1, docUpdate.getFieldUpdates().size());
    FieldUpdate fieldUpd = docUpdate.getFieldUpdate(0);
    assertNotNull(fieldUpd);
    assertEquals(docType.getField("my_lng"), fieldUpd.getField());
    assertEquals(1, fieldUpd.getValueUpdates().size());
    ValueUpdate valueUpd = fieldUpd.getValueUpdate(0);
    assertNotNull(valueUpd);
    assertTrue(valueUpd instanceof AssignValueUpdate);
    assertEquals(new LongFieldValue(69), valueUpd.getValue());
}
Also used : ValueUpdate(com.yahoo.document.update.ValueUpdate) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldUpdate(com.yahoo.document.update.FieldUpdate) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) 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