Search in sources :

Example 31 with Array

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

the class DocTestCase method simple5.

public void simple5() {
    // the following two lines work inside process(Document, Arguments, Processing) in a DocumentProcessor
    DocumentTypeManager dtm = processing.getService().getDocumentTypeManager();
    AnnotationTypeRegistry atr = dtm.getAnnotationTypeRegistry();
    StringFieldValue text = new StringFieldValue("<body><p>I live in San </p>Francisco</body>");
    // 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
    SpanList root = new SpanList();
    SpanTree tree = new SpanTree("html", root);
    StructDataType positionType = (StructDataType) dtm.getDataType("position");
    AnnotationType textType = atr.getType("text");
    AnnotationType beginTag = atr.getType("begintag");
    AnnotationType endTag = atr.getType("endtag");
    AnnotationType bodyType = atr.getType("body");
    AnnotationType paragraphType = atr.getType("paragraph");
    AnnotationType cityType = atr.getType("city");
    Struct position = new Struct(positionType);
    position.setFieldValue("latitude", 37.774929);
    position.setFieldValue("longitude", -122.419415);
    Annotation sanAnnotation = new Annotation(textType);
    Annotation franciscoAnnotation = new Annotation(textType);
    Struct positionWithRef = (Struct) cityType.getDataType().createFieldValue();
    positionWithRef.setFieldValue("position", position);
    Field referencesField = ((StructDataType) cityType.getDataType()).getField("references");
    Array<FieldValue> refList = new Array<FieldValue>(referencesField.getDataType());
    AnnotationReferenceDataType annRefType = (AnnotationReferenceDataType) ((ArrayDataType) referencesField.getDataType()).getNestedType();
    refList.add(new AnnotationReference(annRefType, sanAnnotation));
    refList.add(new AnnotationReference(annRefType, franciscoAnnotation));
    positionWithRef.setFieldValue(referencesField, refList);
    Annotation city = new Annotation(cityType, positionWithRef);
    SpanList paragraph = new SpanList();
    {
        Span span1 = new Span(6, 3);
        Span span2 = new Span(9, 10);
        Span span3 = new Span(19, 4);
        Span span4 = new Span(23, 4);
        paragraph.add(span1).add(span2).add(span3).add(span4);
        tree.annotate(span1, beginTag).annotate(span2, textType).annotate(span3, sanAnnotation).annotate(span4, endTag).annotate(paragraph, paragraphType);
    }
    {
        Span span1 = new Span(0, 6);
        Span span2 = new Span(27, 9);
        Span span3 = new Span(36, 8);
        root.add(span1).add(paragraph).add(span2).add(span3);
        tree.annotate(span1, beginTag).annotate(span2, franciscoAnnotation).annotate(span3, endTag).annotate(root, bodyType).annotate(city);
    }
    text.setSpanTree(tree);
}
Also used : Struct(com.yahoo.document.datatypes.Struct) Array(com.yahoo.document.datatypes.Array) Field(com.yahoo.document.Field) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StructDataType(com.yahoo.document.StructDataType) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue)

Example 32 with Array

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

the class Bug4259784TestCase method annotate.

private void annotate(Document document, DocumentTypeManager manager) {
    AnnotationTypeRegistry registry = manager.getAnnotationTypeRegistry();
    AnnotationType company = registry.getType("company");
    AnnotationType industry = registry.getType("industry");
    AnnotationType person = registry.getType("person");
    AnnotationType location = registry.getType("location");
    SpanTree tree = new SpanTree("testannotations");
    SpanList root = (SpanList) tree.getRoot();
    SpanNode span1 = new Span(0, 5);
    SpanNode span2 = new Span(5, 10);
    SpanNode span3 = new Span(10, 15);
    SpanNode span4 = new Span(15, 20);
    SpanNode span5 = new Span(6, 10);
    SpanNode span6 = new Span(8, 4);
    SpanNode span7 = new Span(4, 2);
    root.add(span1);
    root.add(span2);
    root.add(span4);
    root.add(span5);
    root.add(span6);
    AlternateSpanList aspl = new AlternateSpanList();
    aspl.add(span7);
    List<SpanNode> subtree1 = new ArrayList<SpanNode>();
    subtree1.add(span3);
    aspl.addChildren(1, subtree1, 33.0d);
    root.add(aspl);
    Struct personValue = (Struct) person.getDataType().createFieldValue();
    personValue.setFieldValue("name", "Richard Bair");
    Annotation personAn = new Annotation(person, personValue);
    tree.annotate(span1, personAn);
    Struct companyValue = (Struct) company.getDataType().createFieldValue();
    companyValue.setFieldValue("name", "Sun");
    Annotation compAn = new Annotation(company, companyValue);
    tree.annotate(span2, compAn);
    Struct locationVal = new Struct(manager.getDataType("annotation.location"));
    locationVal.setFieldValue("lat", 37.774929);
    locationVal.setFieldValue("lon", -122.419415);
    Annotation locAnnotation = new Annotation(location, locationVal);
    tree.annotate(span3, locAnnotation);
    Struct dirValue1 = new Struct(manager.getDataType("annotation.person"));
    dirValue1.setFieldValue("name", "Jonathan Schwartz");
    Annotation dirAnnotation1 = new Annotation(person, dirValue1);
    tree.annotate(span5, dirAnnotation1);
    Struct dirValue2 = new Struct(manager.getDataType("annotation.person"));
    dirValue2.setFieldValue("name", "Scott Mcnealy");
    Annotation dirAnnotation2 = new Annotation(person, dirValue2);
    tree.annotate(span6, dirAnnotation2);
    Struct indValue = new Struct(manager.getDataType("annotation.industry"));
    indValue.setFieldValue("vertical", "Manufacturing");
    Annotation indAn = new Annotation(industry, indValue);
    tree.annotate(span4, indAn);
    Field compLocField = ((StructDataType) company.getDataType()).getField("place");
    AnnotationReferenceDataType annType = (AnnotationReferenceDataType) compLocField.getDataType();
    FieldValue compLocFieldVal = new AnnotationReference(annType, locAnnotation);
    companyValue.setFieldValue(compLocField, compLocFieldVal);
    companyValue.setFieldValue("vertical", "software");
    Field dirField = ((StructDataType) company.getDataType()).getField("directors");
    Array<FieldValue> dirFieldVal = new Array<FieldValue>(dirField.getDataType());
    AnnotationReferenceDataType annRefType = (AnnotationReferenceDataType) ((ArrayDataType) dirField.getDataType()).getNestedType();
    dirFieldVal.add(new AnnotationReference(annRefType, dirAnnotation1));
    dirFieldVal.add(new AnnotationReference(annRefType, dirAnnotation2));
    companyValue.setFieldValue(dirField, dirFieldVal);
    tree.clearAnnotations(span3);
    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) Array(com.yahoo.document.datatypes.Array) Field(com.yahoo.document.Field) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StructDataType(com.yahoo.document.StructDataType) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue)

Example 33 with Array

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

the class JoinExpression method doExecute.

@SuppressWarnings({ "unchecked" })
@Override
protected void doExecute(ExecutionContext ctx) {
    FieldValue input = ctx.getValue();
    if (!(input instanceof Array)) {
        throw new IllegalArgumentException("Expected Array input, got " + input.getDataType().getName() + ".");
    }
    StringBuilder output = new StringBuilder();
    for (Iterator<FieldValue> it = ((Array) input).fieldValueIterator(); it.hasNext(); ) {
        output.append(String.valueOf(it.next()));
        if (it.hasNext()) {
            output.append(delimiter);
        }
    }
    ctx.setValue(new StringFieldValue(output.toString()));
}
Also used : Array(com.yahoo.document.datatypes.Array) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue)

Example 34 with Array

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

the class ToArrayExpression method doExecute.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void doExecute(ExecutionContext ctx) {
    FieldValue input = ctx.getValue();
    DataType inputType = input.getDataType();
    ArrayDataType outputType = DataType.getArray(inputType);
    Array output = outputType.createFieldValue();
    output.add(input);
    ctx.setValue(output);
}
Also used : Array(com.yahoo.document.datatypes.Array) DataType(com.yahoo.document.DataType) ArrayDataType(com.yahoo.document.ArrayDataType) FieldValue(com.yahoo.document.datatypes.FieldValue) ArrayDataType(com.yahoo.document.ArrayDataType)

Aggregations

Array (com.yahoo.document.datatypes.Array)34 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)27 FieldValue (com.yahoo.document.datatypes.FieldValue)20 Test (org.junit.Test)17 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)16 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)9 Struct (com.yahoo.document.datatypes.Struct)9 WeightedSet (com.yahoo.document.datatypes.WeightedSet)9 Document (com.yahoo.document.Document)8 DocumentPut (com.yahoo.document.DocumentPut)7 DoubleFieldValue (com.yahoo.document.datatypes.DoubleFieldValue)7 StructDataType (com.yahoo.document.StructDataType)6 ByteFieldValue (com.yahoo.document.datatypes.ByteFieldValue)6 FloatFieldValue (com.yahoo.document.datatypes.FloatFieldValue)6 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)6 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)5 DocumentType (com.yahoo.document.DocumentType)4 Field (com.yahoo.document.Field)4 TensorFieldValue (com.yahoo.document.datatypes.TensorFieldValue)4 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)4