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;
}
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"));
}
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);
}
}
}
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;
}
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);
}
Aggregations