Search in sources :

Example 1 with AnnotationType

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

the class DocumentModelBuilder method convert.

private NewDocumentType convert(SDDocumentType sdoc) {
    Map<AnnotationType, String> annotationInheritance = new HashMap<>();
    Map<StructDataType, String> structInheritance = new HashMap<>();
    NewDocumentType dt = new NewDocumentType(new NewDocumentType.Name(sdoc.getName()), sdoc.getDocumentType().getHeaderType(), sdoc.getDocumentType().getBodyType(), sdoc.getFieldSets(), convertDocumentReferencesToNames(sdoc.getDocumentReferences()));
    for (SDDocumentType n : sdoc.getInheritedTypes()) {
        NewDocumentType.Name name = new NewDocumentType.Name(n.getName());
        NewDocumentType inherited = model.getDocumentManager().getDocumentType(name);
        if (inherited != null) {
            dt.inherit(inherited);
        }
    }
    for (SDDocumentType type : sdoc.getTypes()) {
        if (type.isStruct()) {
            handleStruct(dt, type);
        } else {
            throw new IllegalArgumentException("Data type '" + sdoc.getName() + "' is not a struct => tostring='" + sdoc.toString() + "'.");
        }
    }
    for (AnnotationType annotation : sdoc.getAnnotations()) {
        dt.add(annotation);
    }
    for (AnnotationType annotation : sdoc.getAnnotations()) {
        SDAnnotationType sa = (SDAnnotationType) annotation;
        if (annotation.getInheritedTypes().isEmpty() && (sa.getInherits() != null)) {
            annotationInheritance.put(annotation, sa.getInherits());
        }
        if (annotation.getDataType() == null) {
            if (sa.getSdDocType() != null) {
                StructDataType s = handleStruct(dt, sa.getSdDocType());
                annotation.setDataType(s);
                if ((sa.getInherits() != null)) {
                    structInheritance.put(s, "annotation." + sa.getInherits());
                }
            } else if (sa.getInherits() != null) {
                StructDataType s = new StructDataType("annotation." + annotation.getName());
                if (anyParentsHavePayLoad(sa, sdoc)) {
                    annotation.setDataType(s);
                    addType(dt, s);
                }
                structInheritance.put(s, "annotation." + sa.getInherits());
            }
        }
    }
    for (Map.Entry<AnnotationType, String> e : annotationInheritance.entrySet()) {
        e.getKey().inherit(dt.getAnnotationType(e.getValue()));
    }
    for (Map.Entry<StructDataType, String> e : structInheritance.entrySet()) {
        StructDataType s = (StructDataType) dt.getDataType(e.getValue());
        if (s != null) {
            e.getKey().inherit(s);
        }
    }
    handleStruct(dt, sdoc.getDocumentType().getHeaderType());
    handleStruct(dt, sdoc.getDocumentType().getBodyType());
    extractDataTypesFromFields(dt, sdoc.fieldSet());
    return dt;
}
Also used : SDAnnotationType(com.yahoo.searchdefinition.document.annotation.SDAnnotationType) HashMap(java.util.HashMap) NewDocumentType(com.yahoo.documentmodel.NewDocumentType) SDAnnotationType(com.yahoo.searchdefinition.document.annotation.SDAnnotationType) AnnotationType(com.yahoo.document.annotation.AnnotationType) SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType) StructDataType(com.yahoo.document.StructDataType) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with AnnotationType

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

the class DocumentTypes method buildConfig.

private void buildConfig(NewDocumentType documentType, DocumenttypesConfig.Builder builder) {
    if (documentType == VespaDocumentType.INSTANCE) {
        return;
    }
    DocumenttypesConfig.Documenttype.Builder db = new DocumenttypesConfig.Documenttype.Builder();
    db.id(documentType.getId()).name(documentType.getName()).headerstruct(documentType.getHeader().getId()).bodystruct(documentType.getBody().getId());
    Set<Integer> built = new HashSet<>();
    for (NewDocumentType inherited : documentType.getInherited()) {
        db.inherits(new DocumenttypesConfig.Documenttype.Inherits.Builder().id(inherited.getId()));
        markAsBuilt(built, inherited.getAllTypes());
    }
    for (DataType dt : documentType.getTypes()) {
        buildConfig(dt, db, built);
    }
    for (AnnotationType annotation : documentType.getAnnotations()) {
        DocumenttypesConfig.Documenttype.Annotationtype.Builder atb = new DocumenttypesConfig.Documenttype.Annotationtype.Builder();
        db.annotationtype(atb);
        buildConfig(annotation, atb);
    }
    buildConfig(documentType.getFieldSets(), db);
    builder.documenttype(db);
}
Also used : AnnotationReferenceDataType(com.yahoo.document.annotation.AnnotationReferenceDataType) NewDocumentType(com.yahoo.documentmodel.NewDocumentType) AnnotationType(com.yahoo.document.annotation.AnnotationType)

Example 3 with AnnotationType

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

the class SchemaMappingAndAccessesTest method getDoc.

private Document getDoc() {
    DocumentType type = new DocumentType("album");
    AnnotationType personType = new AnnotationType("person");
    Annotation person = new Annotation(personType);
    type.addField("title", DataType.STRING);
    type.addField("artist", DataType.STRING);
    type.addField("guitarist", DataType.STRING);
    type.addField("year", DataType.INT);
    type.addField("labels", DataType.getArray(DataType.STRING));
    Document doc = new Document(type, new DocumentId("doc:map:test:1"));
    doc.setFieldValue("title", new StringFieldValue("Black Rock"));
    StringFieldValue joe = new StringFieldValue("Joe Bonamassa");
    joe.setSpanTree(new SpanTree("mytree").annotate(person));
    doc.setFieldValue("artist", joe);
    doc.setFieldValue("year", new IntegerFieldValue(2010));
    Array<StringFieldValue> labels = new Array<>(type.getField("labels").getDataType());
    labels.add(new StringFieldValue("audun"));
    labels.add(new StringFieldValue("tylden"));
    doc.setFieldValue("labels", labels);
    StructDataType personStructType = new StructDataType("artist");
    personStructType.addField(new com.yahoo.document.Field("firstname", DataType.STRING));
    personStructType.addField(new com.yahoo.document.Field("lastname", DataType.STRING));
    type.addField("listeners", DataType.getArray(personStructType));
    Array<Struct> listeners = new Array<>(type.getField("listeners").getDataType());
    Struct listenerOne = new Struct(personStructType);
    listenerOne.setFieldValue("firstname", new StringFieldValue("per"));
    listenerOne.setFieldValue("lastname", new StringFieldValue("olsen"));
    Struct listenerTwo = new Struct(personStructType);
    listenerTwo.setFieldValue("firstname", new StringFieldValue("anders"));
    listenerTwo.setFieldValue("lastname", new StringFieldValue("and"));
    listeners.add(listenerOne);
    listeners.add(listenerTwo);
    doc.setFieldValue("listeners", listeners);
    return doc;
}
Also used : DocumentId(com.yahoo.document.DocumentId) DocumentType(com.yahoo.document.DocumentType) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Document(com.yahoo.document.Document) AnnotationType(com.yahoo.document.annotation.AnnotationType) Annotation(com.yahoo.document.annotation.Annotation) Struct(com.yahoo.document.datatypes.Struct) Array(com.yahoo.document.datatypes.Array) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StructDataType(com.yahoo.document.StructDataType) SpanTree(com.yahoo.document.annotation.SpanTree)

Example 4 with AnnotationType

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

the class DocumentTypeManagerConfigurer method setupAnnotationRefTypes.

private static void setupAnnotationRefTypes(DocumentmanagerConfig config, DocumentTypeManager manager) {
    for (int i = 0; i < config.datatype().size(); i++) {
        DocumentmanagerConfig.Datatype thisDataType = config.datatype(i);
        int id = thisDataType.id();
        for (Object o : thisDataType.annotationreftype()) {
            DocumentmanagerConfig.Datatype.Annotationreftype annRefType = (DocumentmanagerConfig.Datatype.Annotationreftype) o;
            AnnotationType annotationType = manager.getAnnotationTypeRegistry().getType(annRefType.annotation());
            if (annotationType == null) {
                throw new IllegalArgumentException("Found reference to " + annRefType.annotation() + ", which does not exist!");
            }
            AnnotationReferenceDataType type = new AnnotationReferenceDataType(annotationType, id);
            manager.register(type);
        }
    }
}
Also used : DocumentmanagerConfig(com.yahoo.document.config.DocumentmanagerConfig) AnnotationReferenceDataType(com.yahoo.document.annotation.AnnotationReferenceDataType) AnnotationType(com.yahoo.document.annotation.AnnotationType)

Example 5 with AnnotationType

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

the class DocumentTypeManagerConfigurer method setupAnnotationTypesWithoutPayloads.

private static void setupAnnotationTypesWithoutPayloads(DocumentmanagerConfig config, DocumentTypeManager manager) {
    for (DocumentmanagerConfig.Annotationtype annType : config.annotationtype()) {
        AnnotationType annotationType = new AnnotationType(annType.name(), annType.id());
        manager.getAnnotationTypeRegistry().register(annotationType);
    }
}
Also used : DocumentmanagerConfig(com.yahoo.document.config.DocumentmanagerConfig) 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