Search in sources :

Example 11 with SpanTree

use of com.yahoo.document.annotation.SpanTree in project vespa by vespa-engine.

the class DocumentGenPluginTest method newBookConcrete.

private Book newBookConcrete(int i) {
    Book book = new Book(new DocumentId("doc:book:" + i));
    book.setAuthor("Melville");
    Date date = new Date().setExacttime(99l);
    book.setTitleSpanTrees(new HashMap<String, SpanTree>());
    SpanTree t = new SpanTree().annotate(date);
    book.titleSpanTrees().put(t.getName(), t);
    book.setTitle("Moby Dick");
    book.setYear(1851);
    // .setAl1(myAs1));
    book.setMystruct(new Ss1().setSs01(new Ss0().setS0("My s0").setD0(99d)).setS1("My s1").setL1(89l));
    Map<Float, Integer> wsFloat = new HashMap<>();
    wsFloat.put(56f, 55);
    wsFloat.put(57f, 54);
    book.setMywsfloat(wsFloat);
    Array<IntegerFieldValue> intArr1 = new Array<>(DataType.getArray(DataType.INT));
    intArr1.add(new IntegerFieldValue(1));
    intArr1.add(new IntegerFieldValue(2));
    intArr1.add(new IntegerFieldValue(3));
    Array intArr1Arr = new Array(DataType.getArray(intArr1.getDataType()));
    intArr1Arr.add(intArr1);
    Array intArr1ArrArr = new Array(DataType.getArray(intArr1Arr.getDataType()));
    intArr1ArrArr.add(intArr1Arr);
    book.setMytriplearray(intArr1ArrArr);
    return book;
}
Also used : Date(com.yahoo.vespa.documentgen.test.annotation.Date) Ss1(com.yahoo.vespa.documentgen.test.Book.Ss1) Ss0(com.yahoo.vespa.documentgen.test.Book.Ss0) SpanTree(com.yahoo.document.annotation.SpanTree)

Example 12 with SpanTree

use of com.yahoo.document.annotation.SpanTree in project vespa by vespa-engine.

the class DocumentGenPluginTest method testFactory.

@Test
public void testFactory() {
    Book b = (Book) ConcreteDocumentFactory.getDocument("book", new DocumentId("doc:book:10"));
    b.setAuthor("Per Ulv");
    final Date d = (Date) ConcreteDocumentFactory.getAnnotation("date");
    d.setExacttime(79l);
    b.setAuthorSpanTrees(new HashMap<String, SpanTree>() {

        {
            put("root", new SpanTree("root").annotate(d));
        }
    });
    StringFieldValue authorCheck = (StringFieldValue) b.getFieldValue("author");
    assertEquals(authorCheck.getWrappedValue(), "Per Ulv");
    SpanTree treeCheck = authorCheck.getSpanTrees().iterator().next();
    Annotation authorAnnCheck = treeCheck.iterator().next();
    assertEquals(((Struct) authorAnnCheck.getFieldValue()).getFieldValue("exacttime").getWrappedValue(), 79l);
    b.setMystruct(((Ss1) ConcreteDocumentFactory.getStruct("ss1")).setS1("Test s1!"));
    assertEquals(((Struct) b.getFieldValue("mystruct")).getFieldValue("s1").getWrappedValue(), "Test s1!");
    Ss1 fss1 = (Ss1) ConcreteDocumentFactory.getStruct("ss1");
    fss1.setD1(678d);
    b.setMystruct(fss1);
    assertEquals(b.getMystruct().getFieldValue("d1").getWrappedValue(), 678d);
    assertEquals(b.getMystruct().getD1(), (Double) 678d);
    assertEquals(ConcreteDocumentFactory.documentTypeObjects.size(), 10);
    assertEquals(ConcreteDocumentFactory.documentTypeObjects.get("music"), Music.type);
    assertEquals(ConcreteDocumentFactory.documentTypeObjects.get("parent"), Parent.type);
    assertEquals(ConcreteDocumentFactory.documentTypeObjects.get("common"), Common.type);
}
Also used : Ss1(com.yahoo.vespa.documentgen.test.Book.Ss1) Date(com.yahoo.vespa.documentgen.test.annotation.Date) Annotation(com.yahoo.document.annotation.Annotation) SpanTree(com.yahoo.document.annotation.SpanTree) Test(org.junit.Test)

Example 13 with SpanTree

use of com.yahoo.document.annotation.SpanTree in project vespa by vespa-engine.

the class SchemaMappingAndAccessesTest method testMappingSpanTrees.

public void testMappingSpanTrees() {
    Document doc = getDoc();
    Map<String, String> fieldMap = new HashMap<>();
    fieldMap.put("t", "title");
    fieldMap.put("a", "artist");
    fieldMap.put("g", "guitarist");
    ProxyDocument mapped = new ProxyDocument(new TestDocumentProcessor1(), doc, fieldMap);
    Iterator<SpanTree> itSpanTreesDoc = ((StringFieldValue) doc.getFieldValue("artist")).getSpanTrees().iterator();
    Iterator<Annotation> itAnnotDoc = itSpanTreesDoc.next().iterator();
    Iterator<SpanTree> itSpanTreesMapped = ((StringFieldValue) mapped.getFieldValue("artist")).getSpanTrees().iterator();
    Iterator<Annotation> itAnnotMapped = itSpanTreesMapped.next().iterator();
    assertEquals(itAnnotDoc.next().getType().getName(), "person");
    assertFalse(itAnnotDoc.hasNext());
    assertEquals(itAnnotMapped.next().getType().getName(), "person");
    assertFalse(itAnnotMapped.hasNext());
    AnnotationType guitaristType = new AnnotationType("guitarist");
    Annotation guitarist = new Annotation(guitaristType);
    StringFieldValue bona = new StringFieldValue("Bonamassa");
    bona.setSpanTree(new SpanTree("mytree").annotate(guitarist));
    StringFieldValue clapton = new StringFieldValue("Clapton");
    mapped.setFieldValue("a", bona);
    mapped.setFieldValue("g", clapton);
    itSpanTreesDoc = ((StringFieldValue) doc.getFieldValue("artist")).getSpanTrees().iterator();
    itAnnotDoc = itSpanTreesDoc.next().iterator();
    itSpanTreesMapped = ((StringFieldValue) mapped.getFieldValue("artist")).getSpanTrees().iterator();
    itAnnotMapped = itSpanTreesMapped.next().iterator();
    assertEquals(itAnnotDoc.next().getType().getName(), "guitarist");
    assertFalse(itAnnotDoc.hasNext());
    assertEquals(itAnnotMapped.next().getType().getName(), "guitarist");
    assertFalse(itAnnotMapped.hasNext());
    assertSame(((StringFieldValue) doc.getFieldValue("artist")).getSpanTrees().iterator().next(), ((StringFieldValue) mapped.getFieldValue("a")).getSpanTrees().iterator().next());
// assertSame(clapton, mapped.getFieldValue("g"));
// assertSame(bona, mapped.getFieldValue("a"));
}
Also used : HashMap(java.util.HashMap) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) TestDocumentProcessor1(com.yahoo.docproc.DocumentProcessingAbstractTestCase.TestDocumentProcessor1) Document(com.yahoo.document.Document) Annotation(com.yahoo.document.annotation.Annotation) AnnotationType(com.yahoo.document.annotation.AnnotationType) SpanTree(com.yahoo.document.annotation.SpanTree)

Example 14 with SpanTree

use of com.yahoo.document.annotation.SpanTree in project vespa by vespa-engine.

the class ExtendedStringField method setFieldValue.

@Override
public FieldValue setFieldValue(StructuredFieldValue doc, FieldValue fv) {
    FieldValue old = getFieldValue(doc);
    StringFieldValue sfv = (StringFieldValue) fv;
    super.setFieldValue(doc, sfv);
    Map<String, SpanTree> trees = null;
    if (sfv != null) {
        trees = sfv.getSpanTreeMap();
        if (trees == null) {
            trees = new HashMap<>();
        }
    }
    extractSpanTrees.set(doc, trees);
    return old;
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StructuredFieldValue(com.yahoo.document.datatypes.StructuredFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) SpanTree(com.yahoo.document.annotation.SpanTree)

Example 15 with SpanTree

use of com.yahoo.document.annotation.SpanTree in project vespa by vespa-engine.

the class ExtendedStringField method getFieldValue.

@Override
public FieldValue getFieldValue(StructuredFieldValue doc) {
    StringFieldValue sfv = (StringFieldValue) super.getFieldValue(doc);
    Map<String, SpanTree> trees = extractSpanTrees.get(doc);
    if (trees != null) {
        for (SpanTree tree : trees.values()) {
            sfv.setSpanTree(tree);
        }
    }
    return sfv;
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) SpanTree(com.yahoo.document.annotation.SpanTree)

Aggregations

SpanTree (com.yahoo.document.annotation.SpanTree)25 Annotation (com.yahoo.document.annotation.Annotation)17 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)15 Test (org.junit.Test)14 AnnotationType (com.yahoo.document.annotation.AnnotationType)6 TokenType (com.yahoo.language.process.TokenType)6 Document (com.yahoo.document.Document)3 SimpleToken (com.yahoo.language.simple.SimpleToken)3 TestDocumentProcessor1 (com.yahoo.docproc.DocumentProcessingAbstractTestCase.TestDocumentProcessor1)2 ProxyDocument (com.yahoo.docproc.proxy.ProxyDocument)2 DocumentType (com.yahoo.document.DocumentType)2 Span (com.yahoo.document.annotation.Span)2 SpanList (com.yahoo.document.annotation.SpanList)2 Linguistics (com.yahoo.language.Linguistics)2 Token (com.yahoo.language.process.Token)2 SimpleLinguistics (com.yahoo.language.simple.SimpleLinguistics)2 Ss1 (com.yahoo.vespa.documentgen.test.Book.Ss1)2 Date (com.yahoo.vespa.documentgen.test.annotation.Date)2 HashMap (java.util.HashMap)2 DocumentId (com.yahoo.document.DocumentId)1