Search in sources :

Example 46 with SimpleTestAdapter

use of com.yahoo.vespa.indexinglanguage.SimpleTestAdapter in project vespa by vespa-engine.

the class NGramTestCase method testNGrams.

@Test
public void testNGrams() {
    ExecutionContext context = new ExecutionContext(new SimpleTestAdapter());
    context.setValue(new StringFieldValue("en gul Bille sang... "));
    new NGramExpression(new SimpleLinguistics(), 3).execute(context);
    StringFieldValue value = (StringFieldValue) context.getValue();
    assertEquals("Grams are pure annotations - field value is unchanged", "en gul Bille sang... ", value.getString());
    SpanTree gramTree = value.getSpanTree(SpanTrees.LINGUISTICS);
    assertNotNull(gramTree);
    SpanList grams = (SpanList) gramTree.getRoot();
    Iterator<SpanNode> i = grams.childIterator();
    // en
    assertSpan(0, 2, true, i, gramTree);
    // <space>
    assertSpan(2, 1, false, i, gramTree);
    // gul
    assertSpan(3, 3, true, i, gramTree);
    // <space>
    assertSpan(6, 1, false, i, gramTree);
    // Bil
    assertSpan(7, 3, true, i, gramTree, "bil");
    assertSpan(8, 3, true, i, gramTree);
    assertSpan(9, 3, true, i, gramTree);
    // <space>
    assertSpan(12, 1, false, i, gramTree);
    assertSpan(13, 3, true, i, gramTree);
    assertSpan(14, 3, true, i, gramTree);
    // <...space>
    assertSpan(17, 4, false, i, gramTree);
    assertFalse(i.hasNext());
}
Also used : SimpleLinguistics(com.yahoo.language.simple.SimpleLinguistics) SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) Test(org.junit.Test)

Example 47 with SimpleTestAdapter

use of com.yahoo.vespa.indexinglanguage.SimpleTestAdapter in project vespa by vespa-engine.

the class ToArrayTestCase method requireThatValueIsConverted.

@Test
public void requireThatValueIsConverted() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setValue(new StringFieldValue("69")).execute(new ToArrayExpression());
    FieldValue val = ctx.getValue();
    assertEquals(Array.class, val.getClass());
    Array arr = (Array) val;
    ArrayDataType type = arr.getDataType();
    assertEquals(DataType.STRING, type.getNestedType());
    assertEquals(1, arr.size());
    assertEquals(new StringFieldValue("69"), arr.get(0));
}
Also used : Array(com.yahoo.document.datatypes.Array) SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) ArrayDataType(com.yahoo.document.ArrayDataType) Test(org.junit.Test)

Example 48 with SimpleTestAdapter

use of com.yahoo.vespa.indexinglanguage.SimpleTestAdapter in project vespa by vespa-engine.

the class ToPositionTestCase method requireThatPositionIsParsed.

@Test
public void requireThatPositionIsParsed() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setValue(new StringFieldValue("6;9")).execute(new ToPositionExpression());
    FieldValue out = ctx.getValue();
    assertTrue(out instanceof StructuredFieldValue);
    assertEquals(PositionDataType.INSTANCE, out.getDataType());
    FieldValue val = ((StructuredFieldValue) out).getFieldValue("x");
    assertTrue(val instanceof IntegerFieldValue);
    assertEquals(6, ((IntegerFieldValue) val).getInteger());
    val = ((StructuredFieldValue) out).getFieldValue("y");
    assertTrue(val instanceof IntegerFieldValue);
    assertEquals(9, ((IntegerFieldValue) val).getInteger());
}
Also used : StructuredFieldValue(com.yahoo.document.datatypes.StructuredFieldValue) SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) StructuredFieldValue(com.yahoo.document.datatypes.StructuredFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Test(org.junit.Test)

Example 49 with SimpleTestAdapter

use of com.yahoo.vespa.indexinglanguage.SimpleTestAdapter in project vespa by vespa-engine.

the class ThisTestCase method requireThatValueIsPreserved.

@Test
public void requireThatValueIsPreserved() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setValue(new StringFieldValue("69"));
    new ThisExpression().execute(ctx);
    assertEquals(new StringFieldValue("69"), ctx.getValue());
}
Also used : SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) Test(org.junit.Test)

Example 50 with SimpleTestAdapter

use of com.yahoo.vespa.indexinglanguage.SimpleTestAdapter in project vespa by vespa-engine.

the class ToByteTestCase method requireThatValueIsConverted.

@Test
public void requireThatValueIsConverted() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setValue(new StringFieldValue("69")).execute(new ToByteExpression());
    FieldValue val = ctx.getValue();
    assertTrue(val instanceof ByteFieldValue);
    assertEquals(69, ((ByteFieldValue) val).getByte());
}
Also used : SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) ByteFieldValue(com.yahoo.document.datatypes.ByteFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) ByteFieldValue(com.yahoo.document.datatypes.ByteFieldValue) Test(org.junit.Test)

Aggregations

SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)67 Test (org.junit.Test)59 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)42 FieldValue (com.yahoo.document.datatypes.FieldValue)30 Field (com.yahoo.document.Field)14 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)14 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)7 Array (com.yahoo.document.datatypes.Array)4 StructDataType (com.yahoo.document.StructDataType)3 SimpleLinguistics (com.yahoo.language.simple.SimpleLinguistics)3 Pair (com.yahoo.collections.Pair)1 ArrayDataType (com.yahoo.document.ArrayDataType)1 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)1 ByteFieldValue (com.yahoo.document.datatypes.ByteFieldValue)1 DoubleFieldValue (com.yahoo.document.datatypes.DoubleFieldValue)1 FloatFieldValue (com.yahoo.document.datatypes.FloatFieldValue)1 StructuredFieldValue (com.yahoo.document.datatypes.StructuredFieldValue)1 WeightedSet (com.yahoo.document.datatypes.WeightedSet)1 AnnotatorConfig (com.yahoo.vespa.indexinglanguage.linguistics.AnnotatorConfig)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1