Search in sources :

Example 16 with AnnotationType

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

the class DocumentGenMojo method exportImportProvidedAnnotationRefs.

/**
 * Handle the case of an annotation reference with a type that is user provided, we need to know the class name then
 */
private String exportImportProvidedAnnotationRefs(AnnotationType annType) {
    String ret = "";
    if (annType.getDataType() == null)
        return ret;
    for (Field f : ((StructDataType) annType.getDataType()).getFields()) {
        if (f.getDataType() instanceof AnnotationReferenceDataType) {
            AnnotationReferenceDataType refType = (AnnotationReferenceDataType) f.getDataType();
            AnnotationType referenced = refType.getAnnotationType();
            String providedClass = provided(referenced.getName());
            if (providedClass != null) {
                // Annotationreference is to a type that is user-provided
                ret = ret + "import " + providedClass + ";\n";
            }
        }
    }
    return ret;
}
Also used : AnnotationReferenceDataType(com.yahoo.document.annotation.AnnotationReferenceDataType) AnnotationType(com.yahoo.document.annotation.AnnotationType)

Example 17 with AnnotationType

use of com.yahoo.document.annotation.AnnotationType 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 18 with AnnotationType

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

the class DocumentTypeManagerConfigurer method addAnnotationTypePayloads.

private static void addAnnotationTypePayloads(DocumentmanagerConfig config, DocumentTypeManager manager) {
    for (DocumentmanagerConfig.Annotationtype annType : config.annotationtype()) {
        AnnotationType annotationType = manager.getAnnotationTypeRegistry().getType(annType.id());
        DataType payload = manager.getDataType(annType.datatype(), "");
        if (!payload.equals(DataType.NONE)) {
            annotationType.setDataType(payload);
        }
    }
}
Also used : DocumentmanagerConfig(com.yahoo.document.config.DocumentmanagerConfig) AnnotationReferenceDataType(com.yahoo.document.annotation.AnnotationReferenceDataType) AnnotationType(com.yahoo.document.annotation.AnnotationType)

Example 19 with AnnotationType

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

the class DocumentGenPluginTest method newBookGeneric.

private Document newBookGeneric(DocumentType bookT, int i, DocumentTypeManager mgr) {
    Document bookGeneric = new Document(bookT, new DocumentId("doc:book:" + i));
    bookGeneric.setFieldValue("author", new StringFieldValue("Melville"));
    StringFieldValue title = new StringFieldValue("Moby Dick");
    SpanTree titleTree = new SpanTree();
    title.setSpanTree(titleTree);
    AnnotationType dateType = mgr.getAnnotationTypeRegistry().getType("date");
    Struct dateStruct = new Struct(mgr.getAnnotationTypeRegistry().getType("date").getDataType());
    dateStruct.setFieldValue("exacttime", new LongFieldValue(99l));
    Annotation date = new Annotation(dateType);
    date.setFieldValue(dateStruct);
    titleTree.annotate(date);
    bookGeneric.setFieldValue("title", title);
    bookGeneric.setFieldValue("year", new IntegerFieldValue(1851));
    Struct myS0 = new Struct(mgr.getDataType("ss0"));
    myS0.setFieldValue("s0", new StringFieldValue("My s0"));
    myS0.setFieldValue("d0", new DoubleFieldValue(99));
    Struct myS1 = new Struct(mgr.getDataType("ss1"));
    myS1.setFieldValue("s1", new StringFieldValue("My s1"));
    myS1.setFieldValue("l1", new LongFieldValue(89));
    Array<StringFieldValue> myAs1 = new Array<>(DataType.getArray(DataType.STRING));
    myAs1.add(new StringFieldValue("as1_1"));
    myAs1.add(new StringFieldValue("as1_2"));
    myS1.setFieldValue("as1", myAs1);
    myS1.setFieldValue("ss01", myS0);
    bookGeneric.setFieldValue("mystruct", myS1);
    WeightedSet<FloatFieldValue> wsFloat = new WeightedSet<>(DataType.getWeightedSet(DataType.FLOAT));
    wsFloat.put(new FloatFieldValue(56f), 55);
    wsFloat.put(new FloatFieldValue(57f), 54);
    bookGeneric.setFieldValue("mywsfloat", 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<Array<IntegerFieldValue>> intArr1Arr = new Array<>(DataType.getArray(intArr1.getDataType()));
    intArr1Arr.add(intArr1);
    Array<Array<Array<IntegerFieldValue>>> intArr1ArrArr = new Array<>(DataType.getArray(intArr1Arr.getDataType()));
    intArr1ArrArr.add(intArr1Arr);
    bookGeneric.setFieldValue("mytriplearray", intArr1ArrArr);
    return bookGeneric;
}
Also used : ProxyDocument(com.yahoo.docproc.proxy.ProxyDocument) AnnotationType(com.yahoo.document.annotation.AnnotationType) Annotation(com.yahoo.document.annotation.Annotation) SpanTree(com.yahoo.document.annotation.SpanTree)

Example 20 with AnnotationType

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

the class DocumentGenPluginTest method testPackComplex.

@Test
public void testPackComplex() {
    final DocumentTypeManager mgr = typeManagerForBookType();
    DocumentType bookT = mgr.getDocumentType("book");
    Document bookGeneric = new Document(bookT, new DocumentId("doc:book:0"));
    bookGeneric.setFieldValue("author", new StringFieldValue("Melville"));
    StringFieldValue title = new StringFieldValue("Moby Dick");
    SpanTree titleTree = new SpanTree();
    title.setSpanTree(titleTree);
    AnnotationType dateType = mgr.getAnnotationTypeRegistry().getType("date");
    Struct dateStruct = new Struct(mgr.getAnnotationTypeRegistry().getType("date").getDataType());
    dateStruct.setFieldValue("exacttime", new LongFieldValue(99l));
    Annotation date = new Annotation(dateType);
    date.setFieldValue(dateStruct);
    titleTree.annotate(date);
    bookGeneric.setFieldValue("title", title);
    StringFieldValue titleCheck = (StringFieldValue) bookGeneric.getFieldValue("title");
    assertEquals(titleCheck.getWrappedValue(), "Moby Dick");
    SpanTree treeCheck = titleCheck.getSpanTrees().iterator().next();
    Annotation titleAnnCheck = treeCheck.iterator().next();
    assertEquals(((StructuredFieldValue) titleAnnCheck.getFieldValue()).getFieldValue("exacttime").getWrappedValue(), 99l);
    bookGeneric.setFieldValue("year", new IntegerFieldValue(1851));
    Struct myS0 = new Struct(mgr.getDataType("ss0"));
    myS0.setFieldValue("s0", new StringFieldValue("My s0"));
    myS0.setFieldValue("d0", new DoubleFieldValue(99));
    Struct myS1 = new Struct(mgr.getDataType("ss1"));
    myS1.setFieldValue("s1", new StringFieldValue("My s1"));
    myS1.setFieldValue("l1", new LongFieldValue(89));
    Array<StringFieldValue> myAs1 = new Array<>(DataType.getArray(DataType.STRING));
    myAs1.add(new StringFieldValue("as1_1"));
    myAs1.add(new StringFieldValue("as1_2"));
    myS1.setFieldValue("as1", myAs1);
    myS1.setFieldValue("ss01", myS0);
    bookGeneric.setFieldValue("mystruct", myS1);
    assertEquals(((StructuredFieldValue) bookGeneric.getFieldValue("mystruct")).getFieldValue("s1").getWrappedValue(), "My s1");
    WeightedSet<FloatFieldValue> wsFloat = new WeightedSet<>(DataType.getWeightedSet(DataType.FLOAT));
    wsFloat.put(new FloatFieldValue(56f), 55);
    wsFloat.put(new FloatFieldValue(57f), 54);
    bookGeneric.setFieldValue("mywsfloat", 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<Array<IntegerFieldValue>> intArr1Arr = new Array<>(DataType.getArray(intArr1.getDataType()));
    intArr1Arr.add(intArr1);
    Array<Array<Array<IntegerFieldValue>>> intArr1ArrArr = new Array<>(DataType.getArray(intArr1Arr.getDataType()));
    intArr1ArrArr.add(intArr1Arr);
    bookGeneric.setFieldValue("mytriplearray", intArr1ArrArr);
    Book book = new Book(bookGeneric, bookGeneric.getId());
    assertEquals(book.getAuthor(), "Melville");
    assertEquals(book.getMystruct().getS1(), "My s1");
    assertEquals(book.getMystruct().getSs01().getS0(), "My s0");
    assertEquals(book.getMytriplearray().get(0).get(0).get(0), (Integer) 1);
    assertEquals(book.getMytriplearray().get(0).get(0).get(1), (Integer) 2);
    assertEquals(book.getMytriplearray().get(0).get(0).get(2), (Integer) 3);
    assertEquals(book.getMywsfloat().get(57f), (Integer) 54);
    assertEquals(book.getMystruct().getAs1().get(1), "as1_2");
    treeCheck = book.titleSpanTrees().values().iterator().next();
    titleAnnCheck = treeCheck.iterator().next();
    assertEquals(((StructuredFieldValue) titleAnnCheck.getFieldValue()).getFieldValue("exacttime").getWrappedValue(), 99l);
    Book book2 = new Book(book, book.getId());
    assertEquals(book2.getId(), bookGeneric.getId());
    assertEquals(book2.getAuthor(), "Melville");
    assertEquals(book2.getMystruct().getS1(), "My s1");
    assertEquals(book2.getMystruct().getSs01().getS0(), "My s0");
    assertEquals(book2.getMytriplearray().get(0).get(0).get(0), (Integer) 1);
    assertEquals(book2.getMytriplearray().get(0).get(0).get(1), (Integer) 2);
    assertEquals(book2.getMytriplearray().get(0).get(0).get(2), (Integer) 3);
    assertEquals(book2.getMywsfloat().get(57f), (Integer) 54);
    assertEquals(book2.getMystruct().getAs1().get(1), "as1_2");
    treeCheck = book2.titleSpanTrees().values().iterator().next();
    titleAnnCheck = treeCheck.iterator().next();
    assertEquals(((StructuredFieldValue) titleAnnCheck.getFieldValue()).getFieldValue("exacttime").getWrappedValue(), 99l);
}
Also used : ProxyDocument(com.yahoo.docproc.proxy.ProxyDocument) AnnotationType(com.yahoo.document.annotation.AnnotationType) Annotation(com.yahoo.document.annotation.Annotation) SpanTree(com.yahoo.document.annotation.SpanTree) Test(org.junit.Test)

Aggregations

AnnotationType (com.yahoo.document.annotation.AnnotationType)20 AnnotationReferenceDataType (com.yahoo.document.annotation.AnnotationReferenceDataType)7 Annotation (com.yahoo.document.annotation.Annotation)6 SpanTree (com.yahoo.document.annotation.SpanTree)6 DocumentmanagerConfig (com.yahoo.document.config.DocumentmanagerConfig)5 StructDataType (com.yahoo.document.StructDataType)3 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)3 NewDocumentType (com.yahoo.documentmodel.NewDocumentType)3 SDAnnotationType (com.yahoo.searchdefinition.document.annotation.SDAnnotationType)3 ProxyDocument (com.yahoo.docproc.proxy.ProxyDocument)2 Document (com.yahoo.document.Document)2 Span (com.yahoo.document.annotation.Span)2 SpanList (com.yahoo.document.annotation.SpanList)2 SpanNode (com.yahoo.document.annotation.SpanNode)2 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 TestDocumentProcessor1 (com.yahoo.docproc.DocumentProcessingAbstractTestCase.TestDocumentProcessor1)1 CollectionDataType (com.yahoo.document.CollectionDataType)1 DataType (com.yahoo.document.DataType)1