Search in sources :

Example 11 with AnnotationType

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

the class VespaDocumentDeserializer42 method read.

public void read(Annotation annotation) {
    int annotationTypeId = buf.getInt();
    AnnotationType type = manager.getAnnotationTypeRegistry().getType(annotationTypeId);
    if (type == null) {
        throw new DeserializationException("Cannot deserialize annotation of type " + annotationTypeId + " (unknown type)");
    }
    annotation.setType(type);
    byte features = buf.get();
    int length = buf.getInt1_2_4Bytes();
    if ((features & (byte) 1) == (byte) 1) {
        // we have a span node
        int spanNodeId = buf.getInt1_2_4Bytes();
        try {
            SpanNode node = spanNodes.get(spanNodeId);
            annotation.setSpanNode(node);
        } catch (IndexOutOfBoundsException ioobe) {
            throw new DeserializationException("Could not deserialize annotation, associated span node not found ", ioobe);
        }
    }
    if ((features & (byte) 2) == (byte) 2) {
        // we have a value:
        int dataTypeId = buf.getInt();
        // if this data type ID the same as the one in our config?
        if (dataTypeId != type.getDataType().getId()) {
            // not the same, but we will handle it gracefully, and just skip past the data:
            buf.position(buf.position() + length - 4);
        } else {
            FieldValue value = type.getDataType().createFieldValue();
            value.deserialize(this);
            annotation.setFieldValue(value);
        }
    }
}
Also used : SpanNode(com.yahoo.document.annotation.SpanNode) CollectionFieldValue(com.yahoo.document.datatypes.CollectionFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FloatFieldValue(com.yahoo.document.datatypes.FloatFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) ReferenceFieldValue(com.yahoo.document.datatypes.ReferenceFieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) TensorFieldValue(com.yahoo.document.datatypes.TensorFieldValue) ByteFieldValue(com.yahoo.document.datatypes.ByteFieldValue) DoubleFieldValue(com.yahoo.document.datatypes.DoubleFieldValue) StructuredFieldValue(com.yahoo.document.datatypes.StructuredFieldValue) PredicateFieldValue(com.yahoo.document.datatypes.PredicateFieldValue) MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) AnnotationType(com.yahoo.document.annotation.AnnotationType)

Example 12 with AnnotationType

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

the class DocumentModelBuilder method anyParentsHavePayLoad.

private static boolean anyParentsHavePayLoad(SDAnnotationType sa, SDDocumentType sdoc) {
    if (sa.getInherits() != null) {
        AnnotationType tmp = sdoc.findAnnotation(sa.getInherits());
        SDAnnotationType inherited = (SDAnnotationType) tmp;
        return ((inherited.getSdDocType() != null) || anyParentsHavePayLoad(inherited, sdoc));
    }
    return false;
}
Also used : SDAnnotationType(com.yahoo.searchdefinition.document.annotation.SDAnnotationType) SDAnnotationType(com.yahoo.searchdefinition.document.annotation.SDAnnotationType) AnnotationType(com.yahoo.document.annotation.AnnotationType)

Example 13 with AnnotationType

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

the class DocumentModelBuilder method specialHandleAnnotationReferenceRecurse.

private static DataType specialHandleAnnotationReferenceRecurse(NewDocumentType docType, String fieldName, DataType dataType) {
    if (dataType instanceof TemporaryAnnotationReferenceDataType) {
        TemporaryAnnotationReferenceDataType refType = (TemporaryAnnotationReferenceDataType) dataType;
        if (refType.getId() != 0) {
            return null;
        }
        AnnotationType target = docType.getAnnotationType(refType.getTarget());
        if (target == null) {
            throw new RetryLaterException("Annotation '" + refType.getTarget() + "' in reference '" + fieldName + "' does not exist.");
        }
        dataType = new AnnotationReferenceDataType(target);
        addType(docType, dataType);
        return dataType;
    } else if (dataType instanceof MapDataType) {
        MapDataType mapType = (MapDataType) dataType;
        DataType valueType = specialHandleAnnotationReferenceRecurse(docType, fieldName, mapType.getValueType());
        if (valueType == null) {
            return null;
        }
        mapType = mapType.clone();
        mapType.setValueType(valueType);
        addType(docType, mapType);
        return mapType;
    } else if (dataType instanceof CollectionDataType) {
        CollectionDataType lstType = (CollectionDataType) dataType;
        DataType nestedType = specialHandleAnnotationReferenceRecurse(docType, fieldName, lstType.getNestedType());
        if (nestedType == null) {
            return null;
        }
        lstType = lstType.clone();
        lstType.setNestedType(nestedType);
        addType(docType, lstType);
        return lstType;
    }
    return null;
}
Also used : AnnotationReferenceDataType(com.yahoo.document.annotation.AnnotationReferenceDataType) TemporaryAnnotationReferenceDataType(com.yahoo.searchdefinition.document.annotation.TemporaryAnnotationReferenceDataType) CollectionDataType(com.yahoo.document.CollectionDataType) StructuredDataType(com.yahoo.document.StructuredDataType) TemporaryStructuredDataType(com.yahoo.document.TemporaryStructuredDataType) DataType(com.yahoo.document.DataType) StructDataType(com.yahoo.document.StructDataType) CollectionDataType(com.yahoo.document.CollectionDataType) MapDataType(com.yahoo.document.MapDataType) AnnotationReferenceDataType(com.yahoo.document.annotation.AnnotationReferenceDataType) TemporaryAnnotationReferenceDataType(com.yahoo.searchdefinition.document.annotation.TemporaryAnnotationReferenceDataType) ReferenceDataType(com.yahoo.document.ReferenceDataType) MapDataType(com.yahoo.document.MapDataType) TemporaryAnnotationReferenceDataType(com.yahoo.searchdefinition.document.annotation.TemporaryAnnotationReferenceDataType) SDAnnotationType(com.yahoo.searchdefinition.document.annotation.SDAnnotationType) AnnotationType(com.yahoo.document.annotation.AnnotationType)

Example 14 with AnnotationType

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

the class DocumentManager method buildConfig.

private void buildConfig(Collection<AnnotationType> types, DocumentmanagerConfig.Builder builder) {
    for (AnnotationType type : types) {
        DocumentmanagerConfig.Annotationtype.Builder atb = new DocumentmanagerConfig.Annotationtype.Builder();
        buildConfig(type, atb);
        builder.annotationtype(atb);
    }
}
Also used : DocumentmanagerConfig(com.yahoo.document.config.DocumentmanagerConfig) AnnotationType(com.yahoo.document.annotation.AnnotationType)

Example 15 with AnnotationType

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

the class DocumentTypes method buildConfig.

private void buildConfig(AnnotationType annotation, DocumenttypesConfig.Documenttype.Annotationtype.Builder builder) {
    builder.id(annotation.getId()).name(annotation.getName());
    DataType dt = annotation.getDataType();
    if (dt != null) {
        builder.datatype(dt.getId());
    }
    for (AnnotationType inherited : annotation.getInheritedTypes()) {
        builder.inherits(new DocumenttypesConfig.Documenttype.Annotationtype.Inherits.Builder().id(inherited.getId()));
    }
}
Also used : AnnotationReferenceDataType(com.yahoo.document.annotation.AnnotationReferenceDataType) AnnotationType(com.yahoo.document.annotation.AnnotationType)

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