use of com.yahoo.document.DataType in project vespa by vespa-engine.
the class WeightedSetTestCase method testAssignDoesNotIgnoreSpecialProperties.
public void testAssignDoesNotIgnoreSpecialProperties() {
DataType type = DataType.getWeightedSet(DataType.STRING);
WeightedSet<StringFieldValue> set = new WeightedSet<>(type);
set.put(new StringFieldValue("hello"), 5);
set.put(new StringFieldValue("aba"), 10);
assertEquals(2, set.size());
assertEquals(new Integer(5), set.get(new StringFieldValue("hello")));
assertEquals(new Integer(10), set.get(new StringFieldValue("aba")));
DataType type2 = DataType.getWeightedSet(DataType.STRING, true, true);
WeightedSet<StringFieldValue> set2 = new WeightedSet<>(type2);
set2.put(new StringFieldValue("hi"), 6);
set2.put(new StringFieldValue("bye"), 13);
set2.put(new StringFieldValue("see you"), 15);
assertEquals(3, set2.size());
assertEquals(new Integer(6), set2.get(new StringFieldValue("hi")));
assertEquals(new Integer(13), set2.get(new StringFieldValue("bye")));
assertEquals(new Integer(15), set2.get(new StringFieldValue("see you")));
try {
set.assign(set2);
fail("it shouldn't be possible to assign a weighted set to another when types differ");
} catch (IllegalArgumentException iae) {
// success
}
assertEquals(2, set.size());
assertEquals(new Integer(5), set.get(new StringFieldValue("hello")));
assertEquals(new Integer(10), set.get(new StringFieldValue("aba")));
}
use of com.yahoo.document.DataType in project vespa by vespa-engine.
the class SerializeAnnotationsTestCase method testSerializeAdvancedTree.
public void testSerializeAdvancedTree() throws IOException {
SpanList root = new SpanList();
SpanTree tree = new SpanTree("html", root);
DataType positionType = docMan.getDataType("myposition");
StructDataType cityDataType = (StructDataType) docMan.getDataType("annotation.city");
AnnotationTypeRegistry registry = docMan.getAnnotationTypeRegistry();
AnnotationType textType = registry.getType("text");
AnnotationType beginTag = registry.getType("begintag");
AnnotationType endTag = registry.getType("endtag");
AnnotationType bodyType = registry.getType("body");
AnnotationType paragraphType = registry.getType("paragraph");
AnnotationType cityType = registry.getType("city");
AnnotationReferenceDataType annRefType = (AnnotationReferenceDataType) docMan.getDataType("annotationreference<text>");
Struct position = new Struct(positionType);
position.setFieldValue("latitude", new DoubleFieldValue(37.774929));
position.setFieldValue("longitude", new DoubleFieldValue(-122.419415));
Annotation sanAnnotation = new Annotation(textType);
Annotation franciscoAnnotation = new Annotation(textType);
Struct positionWithRef = cityDataType.createFieldValue();
positionWithRef.setFieldValue("position", position);
Field referencesField = cityDataType.getField("references");
Array<FieldValue> refList = new Array<FieldValue>(referencesField.getDataType());
refList.add(new AnnotationReference(annRefType, sanAnnotation));
refList.add(new AnnotationReference(annRefType, franciscoAnnotation));
positionWithRef.setFieldValue(referencesField, refList);
Annotation city = new Annotation(cityType, positionWithRef);
AlternateSpanList paragraph = new AlternateSpanList();
paragraph.addChildren(new ArrayList<SpanNode>(), 0);
paragraph.setProbability(0, 0.9);
paragraph.setProbability(1, 0.1);
{
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(0, span1).add(0, span2).add(0, span3).add(0, span4);
Span alt_span1 = new Span(6, 13);
Span alt_span2 = new Span(19, 8);
paragraph.add(1, alt_span1).add(1, alt_span2);
tree.annotate(span1, beginTag).annotate(span2, textType).annotate(span3, sanAnnotation).annotate(span4, endTag).annotate(alt_span1, textType).annotate(alt_span2, bodyType).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);
}
StringFieldValue value = new StringFieldValue("lkj lkj lkj lkj lkj lkj lkj lkj lkj lkj lkj lkj " + "lkj lkj lkj lkj lkj lkj lkj lkj lkj lkj l jlkj lkj lkj " + "lkjoijoij oij oij oij oij oij oijoijoij oij oij oij oij oij " + "oijoijoijoijoijoijoijoijoijoijoijoijoij oij oij oij oij " + "oijaosdifjoai fdoais jdoasi jai os oafoai ai dfojsfoa dfoi dsf" + "aosifjasofija sodfij oasdifj aosdiosifjsi ooai oais osi");
value.setSpanTree(tree);
// important! call readFile() before writeFile()!
ByteBuffer serializedFromFile = readFile("test_data_serialized_advanced");
ByteBuffer serialized = writeFile(value, "test_data_serialized_advanced");
assertEquals(serialized.limit(), serializedFromFile.limit());
StringFieldValue valueFromFile = new StringFieldValue();
DocumentDeserializer deserializer = DocumentDeserializerFactory.create42(docMan, new GrowableByteBuffer(serializedFromFile));
deserializer.read(null, valueFromFile);
assertEquals(value, valueFromFile);
}
use of com.yahoo.document.DataType in project vespa by vespa-engine.
the class ArithmeticExpression method requiredInputType.
@Override
public DataType requiredInputType() {
DataType lhsType = lhs.requiredInputType();
DataType rhsType = rhs.requiredInputType();
if (lhsType == null) {
return rhsType;
}
if (rhsType == null) {
return lhsType;
}
if (!lhsType.equals(rhsType)) {
throw new VerificationException(this, "Operands require conflicting input types, " + lhsType.getName() + " vs " + rhsType.getName() + ".");
}
return lhsType;
}
use of com.yahoo.document.DataType in project vespa by vespa-engine.
the class CatExpression method doExecute.
@Override
protected void doExecute(ExecutionContext ctx) {
FieldValue input = ctx.getValue();
DataType inputType = input != null ? input.getDataType() : null;
VerificationContext ver = new VerificationContext(ctx);
List<FieldValue> values = new LinkedList<>();
List<DataType> types = new LinkedList<>();
for (Expression exp : this) {
FieldValue val = ctx.setValue(input).execute(exp).getValue();
values.add(val);
DataType type;
if (val != null) {
type = val.getDataType();
} else {
type = ver.setValue(inputType).execute(this).getValue();
}
types.add(type);
}
DataType type = resolveOutputType(types);
ctx.setValue(type == DataType.STRING ? asString(values) : asCollection(type, values));
}
use of com.yahoo.document.DataType in project vespa by vespa-engine.
the class CatExpression method doVerify.
@Override
protected void doVerify(VerificationContext context) {
DataType input = context.getValue();
List<DataType> types = new LinkedList<>();
for (Expression exp : this) {
DataType val = context.setValue(input).execute(exp).getValue();
types.add(val);
if (val == null) {
throw new VerificationException(this, "Attempting to concatenate a null value (" + exp + ").");
}
}
context.setValue(resolveOutputType(types));
}
Aggregations