Search in sources :

Example 11 with FloatFieldValue

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

the class Bug4475379TestCase method annotate.

public void annotate(DocumentTypeManager manager, Document document) {
    AnnotationTypeRegistry registry = manager.getAnnotationTypeRegistry();
    AnnotationType company = registry.getType("company");
    AnnotationType industry = registry.getType("industry");
    AnnotationType person = registry.getType("person");
    AnnotationType location = registry.getType("location");
    Annotation compAn1;
    Annotation personAn1;
    Annotation locAn1;
    Annotation indAn1;
    Annotation compAn2;
    Annotation personAn2;
    Annotation locAn2;
    Annotation indAn2;
    {
        Struct companyValue1 = (Struct) company.getDataType().createFieldValue();
        companyValue1.setFieldValue("name", new StringFieldValue("Sun"));
        companyValue1.setFieldValue("ceo", new StringFieldValue("Scott Mcnealy"));
        companyValue1.setFieldValue("lat", new FloatFieldValue(37.7f));
        companyValue1.setFieldValue("lon", new FloatFieldValue(-122.44f));
        companyValue1.setFieldValue("alt", 60.456);
        companyValue1.setFieldValue("vertical", new StringFieldValue("software"));
        compAn1 = new Annotation(company, companyValue1);
    }
    {
        Struct personValue1 = new Struct(manager.getDataType("annotation.person"));
        personValue1.setFieldValue("name", new StringFieldValue("Richard Bair"));
        personAn1 = new Annotation(person, personValue1);
    }
    {
        Struct locValue1 = new Struct(manager.getDataType("annotation.location"));
        locValue1.setFieldValue("name", new StringFieldValue("Prinsens Gate"));
        locAn1 = new Annotation(location, locValue1);
    }
    {
        Struct indValue1 = new Struct(manager.getDataType("annotation.industry"));
        indValue1.setFieldValue("vertical", new StringFieldValue("Software Services"));
        indAn1 = new Annotation(industry, indValue1);
    }
    {
        Struct companyValue2 = (Struct) company.getDataType().createFieldValue();
        companyValue2.setFieldValue("name", new StringFieldValue("Yahoo"));
        companyValue2.setFieldValue("ceo", new StringFieldValue("Carol Bartz"));
        companyValue2.setFieldValue("lat", new FloatFieldValue(32.1f));
        companyValue2.setFieldValue("lon", new FloatFieldValue(-48.44f));
        companyValue2.setFieldValue("alt", 33.56);
        companyValue2.setFieldValue("vertical", new StringFieldValue("Research"));
        compAn2 = new Annotation(company, companyValue2);
    }
    {
        Struct personValue2 = new Struct(manager.getDataType("annotation.person"));
        personValue2.setFieldValue("name", new StringFieldValue("Kim Johansen"));
        personAn2 = new Annotation(person, personValue2);
    }
    {
        Struct locValue2 = new Struct(manager.getDataType("annotation.location"));
        locValue2.setFieldValue("name", new StringFieldValue("RT Nagar"));
        locAn2 = new Annotation(location, locValue2);
    }
    {
        Struct indValue2 = new Struct(manager.getDataType("annotation.industry"));
        indValue2.setFieldValue("vertical", new StringFieldValue("Software Consulting"));
        indAn2 = new Annotation(industry, indValue2);
    }
    SpanTree tree = new SpanTree("test");
    SpanList root = (SpanList) tree.getRoot();
    AlternateSpanList branch = new AlternateSpanList();
    SpanNode span1 = new Span(0, 3);
    SpanNode span2 = new Span(1, 9);
    SpanNode span3 = new Span(12, 10);
    SpanNode span11 = new Span(0, 3);
    SpanNode span22 = new Span(1, 9);
    SpanNode span33 = new Span(12, 10);
    SpanList alternate1 = new SpanList();
    alternate1.add(span3);
    alternate1.add(span2);
    alternate1.add(span1);
    SpanList alternate2 = new SpanList();
    alternate2.add(span11);
    alternate2.add(span22);
    alternate2.add(span33);
    tree.annotate(span1, compAn1);
    tree.annotate(span2, personAn1);
    tree.annotate(span3, locAn1);
    tree.annotate(span1, indAn1);
    tree.annotate(span11, compAn2);
    tree.annotate(span22, personAn2);
    tree.annotate(span33, locAn2);
    tree.annotate(span11, indAn2);
    List<SpanNode> subtreeList1 = new ArrayList<>();
    subtreeList1.add(alternate1);
    List<SpanNode> subtreeList2 = new ArrayList<>();
    subtreeList2.add(alternate2);
    branch.addChildren(1, subtreeList1, 20.0d);
    branch.addChildren(2, subtreeList2, 50.0d);
    root.add(branch);
    StringFieldValue body = (StringFieldValue) document.getFieldValue(document.getDataType().getField("body"));
    body.setSpanTree(tree);
    document.setFieldValue(document.getDataType().getField("body"), body);
}
Also used : ArrayList(java.util.ArrayList) Struct(com.yahoo.document.datatypes.Struct) FloatFieldValue(com.yahoo.document.datatypes.FloatFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue)

Aggregations

FloatFieldValue (com.yahoo.document.datatypes.FloatFieldValue)11 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)10 Test (org.junit.Test)7 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)6 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)6 ByteFieldValue (com.yahoo.document.datatypes.ByteFieldValue)5 DoubleFieldValue (com.yahoo.document.datatypes.DoubleFieldValue)5 Raw (com.yahoo.document.datatypes.Raw)5 WeightedSet (com.yahoo.document.datatypes.WeightedSet)4 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)4 ByteBuffer (java.nio.ByteBuffer)4 Array (com.yahoo.document.datatypes.Array)3 FileOutputStream (java.io.FileOutputStream)3 ArrayList (java.util.ArrayList)3 FieldValue (com.yahoo.document.datatypes.FieldValue)2 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)2 AbstractTypesTest (com.yahoo.document.annotation.AbstractTypesTest)1 Struct (com.yahoo.document.datatypes.Struct)1 DocumentSerializer (com.yahoo.document.serialization.DocumentSerializer)1 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)1