Search in sources :

Example 26 with SimpleLinguistics

use of com.yahoo.language.simple.SimpleLinguistics in project vespa by vespa-engine.

the class TokenizeTestCase method requireThatExpressionCanBeVerified.

@Test
public void requireThatExpressionCanBeVerified() {
    Expression exp = new TokenizeExpression(new SimpleLinguistics(), new AnnotatorConfig());
    assertVerify(DataType.STRING, exp, DataType.STRING);
    assertVerifyThrows(null, exp, "Expected string input, got null.");
    assertVerifyThrows(DataType.INT, exp, "Expected string input, got int.");
}
Also used : SimpleLinguistics(com.yahoo.language.simple.SimpleLinguistics) AnnotatorConfig(com.yahoo.vespa.indexinglanguage.linguistics.AnnotatorConfig) Test(org.junit.Test)

Example 27 with SimpleLinguistics

use of com.yahoo.language.simple.SimpleLinguistics in project vespa by vespa-engine.

the class TokenizeTestCase method requireThatValueIsAnnotated.

@Test
public void requireThatValueIsAnnotated() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setValue(new StringFieldValue("foo"));
    new TokenizeExpression(new SimpleLinguistics(), new AnnotatorConfig()).execute(ctx);
    FieldValue val = ctx.getValue();
    assertTrue(val instanceof StringFieldValue);
    assertNotNull(((StringFieldValue) val).getSpanTree(SpanTrees.LINGUISTICS));
}
Also used : SimpleLinguistics(com.yahoo.language.simple.SimpleLinguistics) SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) AnnotatorConfig(com.yahoo.vespa.indexinglanguage.linguistics.AnnotatorConfig) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) Test(org.junit.Test)

Example 28 with SimpleLinguistics

use of com.yahoo.language.simple.SimpleLinguistics in project vespa by vespa-engine.

the class TokenizeTestCase method requireThatAccessorsWork.

@Test
public void requireThatAccessorsWork() {
    Linguistics linguistics = new SimpleLinguistics();
    AnnotatorConfig config = new AnnotatorConfig();
    TokenizeExpression exp = new TokenizeExpression(linguistics, config);
    assertSame(linguistics, exp.getLinguistics());
    assertSame(config, exp.getConfig());
}
Also used : SimpleLinguistics(com.yahoo.language.simple.SimpleLinguistics) AnnotatorConfig(com.yahoo.vespa.indexinglanguage.linguistics.AnnotatorConfig) Linguistics(com.yahoo.language.Linguistics) SimpleLinguistics(com.yahoo.language.simple.SimpleLinguistics) Test(org.junit.Test)

Example 29 with SimpleLinguistics

use of com.yahoo.language.simple.SimpleLinguistics in project vespa by vespa-engine.

the class LinguisticsAnnotatorTestCase method requireThatTokenizeCappingWorks.

@Test
public void requireThatTokenizeCappingWorks() {
    String shortString = "short string";
    SpanTree spanTree = new SpanTree(SpanTrees.LINGUISTICS);
    spanTree.setStringFieldValue(new StringFieldValue(shortString));
    spanTree.spanList().span(0, 5).annotate(new Annotation(AnnotationTypes.TERM));
    spanTree.spanList().span(6, 6).annotate(new Annotation(AnnotationTypes.TERM));
    StringFieldValue shortValue = new StringFieldValue(shortString);
    Linguistics linguistics = new SimpleLinguistics();
    LinguisticsAnnotator annotator = new LinguisticsAnnotator(linguistics, new AnnotatorConfig().setMaxTokenLength(12));
    assertTrue(annotator.annotate(shortValue));
    assertEquals(spanTree, shortValue.getSpanTree(SpanTrees.LINGUISTICS));
    assertEquals(shortString, shortValue.getSpanTree(SpanTrees.LINGUISTICS).getStringFieldValue().getString());
    StringFieldValue cappedValue = new StringFieldValue(shortString + " a longer string");
    assertTrue(annotator.annotate(cappedValue));
    assertEquals((shortString + " a longer string"), cappedValue.getSpanTree(SpanTrees.LINGUISTICS).getStringFieldValue().getString());
}
Also used : SimpleLinguistics(com.yahoo.language.simple.SimpleLinguistics) 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 30 with SimpleLinguistics

use of com.yahoo.language.simple.SimpleLinguistics in project vespa by vespa-engine.

the class ExpressionTestCase method assertExpression.

private static void assertExpression(Class expectedClass, String str) throws ParseException {
    Linguistics linguistics = new SimpleLinguistics();
    Expression foo = Expression.fromString(str, linguistics);
    assertEquals(expectedClass, foo.getClass());
    Expression bar = Expression.fromString(foo.toString(), linguistics);
    assertEquals(foo.hashCode(), bar.hashCode());
    assertEquals(foo, bar);
}
Also used : SimpleLinguistics(com.yahoo.language.simple.SimpleLinguistics) Linguistics(com.yahoo.language.Linguistics) SimpleLinguistics(com.yahoo.language.simple.SimpleLinguistics)

Aggregations

SimpleLinguistics (com.yahoo.language.simple.SimpleLinguistics)42 Test (org.junit.Test)37 Token (com.yahoo.prelude.query.parser.Token)17 Tokenizer (com.yahoo.prelude.query.parser.Tokenizer)17 Linguistics (com.yahoo.language.Linguistics)10 Index (com.yahoo.prelude.Index)7 IndexFacts (com.yahoo.prelude.IndexFacts)7 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)6 AnnotatorConfig (com.yahoo.vespa.indexinglanguage.linguistics.AnnotatorConfig)5 SpecialTokenRegistry (com.yahoo.prelude.query.parser.SpecialTokenRegistry)3 Query (com.yahoo.search.Query)3 Execution (com.yahoo.search.searchchain.Execution)3 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)3 InputExpression (com.yahoo.vespa.indexinglanguage.expressions.InputExpression)3 Pair (com.yahoo.collections.Pair)2 FieldValue (com.yahoo.document.datatypes.FieldValue)2 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)2 RendererRegistry (com.yahoo.search.rendering.RendererRegistry)2 ArithmeticExpression (com.yahoo.vespa.indexinglanguage.expressions.ArithmeticExpression)2 AttributeExpression (com.yahoo.vespa.indexinglanguage.expressions.AttributeExpression)2