use of com.yahoo.document.annotation.SpanTree in project vespa by vespa-engine.
the class DocumentGenPluginTest method newBookConcrete.
private Book newBookConcrete(int i) {
Book book = new Book(new DocumentId("doc:book:" + i));
book.setAuthor("Melville");
Date date = new Date().setExacttime(99l);
book.setTitleSpanTrees(new HashMap<String, SpanTree>());
SpanTree t = new SpanTree().annotate(date);
book.titleSpanTrees().put(t.getName(), t);
book.setTitle("Moby Dick");
book.setYear(1851);
// .setAl1(myAs1));
book.setMystruct(new Ss1().setSs01(new Ss0().setS0("My s0").setD0(99d)).setS1("My s1").setL1(89l));
Map<Float, Integer> wsFloat = new HashMap<>();
wsFloat.put(56f, 55);
wsFloat.put(57f, 54);
book.setMywsfloat(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 intArr1Arr = new Array(DataType.getArray(intArr1.getDataType()));
intArr1Arr.add(intArr1);
Array intArr1ArrArr = new Array(DataType.getArray(intArr1Arr.getDataType()));
intArr1ArrArr.add(intArr1Arr);
book.setMytriplearray(intArr1ArrArr);
return book;
}
use of com.yahoo.document.annotation.SpanTree in project vespa by vespa-engine.
the class DocumentGenPluginTest method testFactory.
@Test
public void testFactory() {
Book b = (Book) ConcreteDocumentFactory.getDocument("book", new DocumentId("doc:book:10"));
b.setAuthor("Per Ulv");
final Date d = (Date) ConcreteDocumentFactory.getAnnotation("date");
d.setExacttime(79l);
b.setAuthorSpanTrees(new HashMap<String, SpanTree>() {
{
put("root", new SpanTree("root").annotate(d));
}
});
StringFieldValue authorCheck = (StringFieldValue) b.getFieldValue("author");
assertEquals(authorCheck.getWrappedValue(), "Per Ulv");
SpanTree treeCheck = authorCheck.getSpanTrees().iterator().next();
Annotation authorAnnCheck = treeCheck.iterator().next();
assertEquals(((Struct) authorAnnCheck.getFieldValue()).getFieldValue("exacttime").getWrappedValue(), 79l);
b.setMystruct(((Ss1) ConcreteDocumentFactory.getStruct("ss1")).setS1("Test s1!"));
assertEquals(((Struct) b.getFieldValue("mystruct")).getFieldValue("s1").getWrappedValue(), "Test s1!");
Ss1 fss1 = (Ss1) ConcreteDocumentFactory.getStruct("ss1");
fss1.setD1(678d);
b.setMystruct(fss1);
assertEquals(b.getMystruct().getFieldValue("d1").getWrappedValue(), 678d);
assertEquals(b.getMystruct().getD1(), (Double) 678d);
assertEquals(ConcreteDocumentFactory.documentTypeObjects.size(), 10);
assertEquals(ConcreteDocumentFactory.documentTypeObjects.get("music"), Music.type);
assertEquals(ConcreteDocumentFactory.documentTypeObjects.get("parent"), Parent.type);
assertEquals(ConcreteDocumentFactory.documentTypeObjects.get("common"), Common.type);
}
use of com.yahoo.document.annotation.SpanTree 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.SpanTree in project vespa by vespa-engine.
the class ExtendedStringField method setFieldValue.
@Override
public FieldValue setFieldValue(StructuredFieldValue doc, FieldValue fv) {
FieldValue old = getFieldValue(doc);
StringFieldValue sfv = (StringFieldValue) fv;
super.setFieldValue(doc, sfv);
Map<String, SpanTree> trees = null;
if (sfv != null) {
trees = sfv.getSpanTreeMap();
if (trees == null) {
trees = new HashMap<>();
}
}
extractSpanTrees.set(doc, trees);
return old;
}
use of com.yahoo.document.annotation.SpanTree in project vespa by vespa-engine.
the class ExtendedStringField method getFieldValue.
@Override
public FieldValue getFieldValue(StructuredFieldValue doc) {
StringFieldValue sfv = (StringFieldValue) super.getFieldValue(doc);
Map<String, SpanTree> trees = extractSpanTrees.get(doc);
if (trees != null) {
for (SpanTree tree : trees.values()) {
sfv.setSpanTree(tree);
}
}
return sfv;
}
Aggregations