use of com.yahoo.document.StructDataType in project vespa by vespa-engine.
the class Bug4261985TestCase method annotate.
public void annotate(Document document, DocumentTypeManager manager) {
AnnotationTypeRegistry registry = manager.getAnnotationTypeRegistry();
AnnotationType company = registry.getType("company");
AnnotationType industry = registry.getType("industry");
AnnotationType person = registry.getType("person");
AnnotationType location = registry.getType("location");
AnnotationType bigshots = registry.getType("bigshots");
if (company.inherits(industry)) {
System.out.println("Company Inherits Industry");
} else {
System.out.println("FAIL: COMPANY DOES NOT INHERIT INDUSTRY");
throw new RuntimeException("FAIL: COMPANY DOES NOT INHERIT INDUSTRY, though it does in SD file");
}
SpanTree tree = new SpanTree("testannotations");
SpanList root = (SpanList) tree.getRoot();
SpanNode span1 = new Span(0, 5);
SpanNode span2 = new Span(5, 10);
SpanNode span3 = new Span(10, 15);
SpanNode span4 = new Span(15, 20);
SpanNode span5 = new Span(6, 10);
SpanNode span6 = new Span(8, 4);
SpanNode span7 = new Span(4, 2);
SpanNode span8 = new Span(12, 6);
root.add(span1);
root.add(span2);
// root.add(span3);
root.add(span4);
root.add(span5);
root.add(span6);
// root.add(span7);
root.add(span8);
AlternateSpanList aspl = new AlternateSpanList();
aspl.add(span7);
List<SpanNode> subtree1 = new ArrayList<SpanNode>();
subtree1.add(span3);
aspl.addChildren(1, subtree1, 33.0d);
root.add(aspl);
Struct personValue = (Struct) person.getDataType().createFieldValue();
personValue.setFieldValue("name", "Richard Bair");
Annotation personAn = new Annotation(person, personValue);
tree.annotate(span1, personAn);
Struct companyValue = (Struct) company.getDataType().createFieldValue();
companyValue.setFieldValue("name", "Sun");
Struct locationVal = new Struct(manager.getDataType("annotation.location"));
locationVal.setFieldValue("lat", 37.774929);
locationVal.setFieldValue("lon", -122.419415);
Annotation locAnnotation = new Annotation(location, locationVal);
Field compLocField = ((StructDataType) company.getDataType()).getField("place");
// FieldValue compLocFieldVal = new FieldValue(compLocField.getDataType());
AnnotationReferenceDataType annType = (AnnotationReferenceDataType) compLocField.getDataType();
FieldValue compLocFieldVal = null;
// if (scenario.equals("createFieldValue")) {
// compLocFieldVal = annType.createFieldValue(new AnnotationReference(annType, locAnnotation));
// } else {
compLocFieldVal = new AnnotationReference(annType, locAnnotation);
// }
companyValue.setFieldValue(compLocField, compLocFieldVal);
companyValue.setFieldValue("vertical", "software");
Struct dirValue1 = new Struct(manager.getDataType("annotation.person"));
dirValue1.setFieldValue("name", "Jonathan Schwartz");
Annotation dirAnnotation1 = new Annotation(person, dirValue1);
Struct dirValue2 = new Struct(manager.getDataType("annotation.person"));
dirValue2.setFieldValue("name", "Scott Mcnealy");
Annotation dirAnnotation2 = new Annotation(person, dirValue2);
Field dirField = ((StructDataType) company.getDataType()).getField("directors");
Array<FieldValue> dirFieldVal = new Array<FieldValue>(dirField.getDataType());
AnnotationReferenceDataType annRefType = (AnnotationReferenceDataType) ((ArrayDataType) dirField.getDataType()).getNestedType();
dirFieldVal.add(new AnnotationReference(annRefType, dirAnnotation1));
dirFieldVal.add(new AnnotationReference(annRefType, dirAnnotation2));
companyValue.setFieldValue(dirField, dirFieldVal);
Annotation compAn = new Annotation(company, companyValue);
tree.annotate(span2, compAn);
Struct bigshotsValue = (Struct) bigshots.getDataType().createFieldValue();
Field ceosField = ((StructDataType) bigshots.getDataType()).getField("ceos");
// FieldValue compLocFieldVal = new FieldValue(compLocField.getDataType());
AnnotationReferenceDataType annType1 = (AnnotationReferenceDataType) ceosField.getDataType();
FieldValue ceosFieldVal = new AnnotationReference(annType1, compAn);
bigshotsValue.setFieldValue(ceosField, ceosFieldVal);
Annotation bigshotsAn = new Annotation(bigshots, bigshotsValue);
tree.annotate(span8, bigshotsAn);
Field selfField = ((StructDataType) bigshots.getDataType()).getField("self");
AnnotationReferenceDataType annType2 = (AnnotationReferenceDataType) selfField.getDataType();
FieldValue selfFieldVal = new AnnotationReference(annType2, bigshotsAn);
bigshotsValue.setFieldValue(selfField, selfFieldVal);
bigshotsAn = new Annotation(bigshots, bigshotsValue);
tree.annotate(span8, bigshotsAn);
tree.annotate(span3, locAnnotation);
tree.annotate(span5, dirAnnotation1);
tree.annotate(span6, dirAnnotation2);
Struct indValue = new Struct(manager.getDataType("annotation.industry"));
indValue.setFieldValue("vertical", "Manufacturing");
Annotation indAn = new Annotation(industry, indValue);
tree.annotate(span4, indAn);
StringFieldValue body = (StringFieldValue) document.getFieldValue(document.getDataType().getField("body"));
body.setSpanTree(tree);
document.setFieldValue(document.getDataType().getField("body"), body);
}
use of com.yahoo.document.StructDataType in project vespa by vespa-engine.
the class Bug6394548TestCase method createBigFeatureSetAnnotation.
private Annotation createBigFeatureSetAnnotation(AnnotationType featuresetAnno) {
StructDataType featuresetType = (StructDataType) featuresetAnno.getDataType();
Struct featureset = featuresetType.createFieldValue();
System.out.println("featureset type: " + featureset.getDataType().toString());
MapFieldValue<StringFieldValue, IntegerFieldValue> discreteValued = (MapFieldValue<StringFieldValue, IntegerFieldValue>) featuresetType.getField("discretevaluedfeatures").getDataType().createFieldValue();
discreteValued.put(new StringFieldValue("foo"), new IntegerFieldValue(1234));
discreteValued.put(new StringFieldValue("bar"), new IntegerFieldValue(567890123));
featureset.setFieldValue("discretevaluedfeatures", discreteValued);
MapFieldValue<StringFieldValue, DoubleFieldValue> realValued = (MapFieldValue<StringFieldValue, DoubleFieldValue>) featuresetType.getField("realvaluedfeatures").getDataType().createFieldValue();
realValued.put(new StringFieldValue("foo"), new DoubleFieldValue(0.75));
realValued.put(new StringFieldValue("bar"), new DoubleFieldValue(1.5));
featureset.setFieldValue("realvaluedfeatures", realValued);
Array<StringFieldValue> nested = (Array<StringFieldValue>) featureset.getField("foo10").getDataType().createFieldValue();
nested.add(new StringFieldValue("baz"));
nested.add(new StringFieldValue("blargh"));
featureset.setFieldValue("foo10", nested);
featureset.setFieldValue("foo1", new StringFieldValue("asdf"));
featureset.setFieldValue("foo4", new StringFieldValue("qwerty"));
featureset.setFieldValue("foo2", new IntegerFieldValue(555));
featureset.setFieldValue("foo2", new IntegerFieldValue(8));
featureset.setFieldValue("foo7", new IntegerFieldValue(1337));
featureset.setFieldValue("foo8", new IntegerFieldValue(967867));
featureset.setFieldValue("foo9", new DoubleFieldValue(123.45));
Array<StringFieldValue> attributes = (Array<StringFieldValue>) featureset.getField("foo6").getDataType().createFieldValue();
attributes.add(new StringFieldValue("adam"));
attributes.add(new StringFieldValue("jamie"));
attributes.add(new StringFieldValue("grant"));
attributes.add(new StringFieldValue("tory"));
attributes.add(new StringFieldValue("kari"));
featureset.setFieldValue("variantattribute", attributes);
Annotation anno = new Annotation(featuresetAnno);
anno.setFieldValue(featureset);
return anno;
}
use of com.yahoo.document.StructDataType in project vespa by vespa-engine.
the class DocTestCase method simple5.
public void simple5() {
// the following two lines work inside process(Document, Arguments, Processing) in a DocumentProcessor
DocumentTypeManager dtm = processing.getService().getDocumentTypeManager();
AnnotationTypeRegistry atr = dtm.getAnnotationTypeRegistry();
StringFieldValue text = new StringFieldValue("<body><p>I live in San </p>Francisco</body>");
// 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
SpanList root = new SpanList();
SpanTree tree = new SpanTree("html", root);
StructDataType positionType = (StructDataType) dtm.getDataType("position");
AnnotationType textType = atr.getType("text");
AnnotationType beginTag = atr.getType("begintag");
AnnotationType endTag = atr.getType("endtag");
AnnotationType bodyType = atr.getType("body");
AnnotationType paragraphType = atr.getType("paragraph");
AnnotationType cityType = atr.getType("city");
Struct position = new Struct(positionType);
position.setFieldValue("latitude", 37.774929);
position.setFieldValue("longitude", -122.419415);
Annotation sanAnnotation = new Annotation(textType);
Annotation franciscoAnnotation = new Annotation(textType);
Struct positionWithRef = (Struct) cityType.getDataType().createFieldValue();
positionWithRef.setFieldValue("position", position);
Field referencesField = ((StructDataType) cityType.getDataType()).getField("references");
Array<FieldValue> refList = new Array<FieldValue>(referencesField.getDataType());
AnnotationReferenceDataType annRefType = (AnnotationReferenceDataType) ((ArrayDataType) referencesField.getDataType()).getNestedType();
refList.add(new AnnotationReference(annRefType, sanAnnotation));
refList.add(new AnnotationReference(annRefType, franciscoAnnotation));
positionWithRef.setFieldValue(referencesField, refList);
Annotation city = new Annotation(cityType, positionWithRef);
SpanList paragraph = new SpanList();
{
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(span1).add(span2).add(span3).add(span4);
tree.annotate(span1, beginTag).annotate(span2, textType).annotate(span3, sanAnnotation).annotate(span4, endTag).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);
}
text.setSpanTree(tree);
}
use of com.yahoo.document.StructDataType in project vespa by vespa-engine.
the class Bug4259784TestCase method annotate.
private void annotate(Document document, DocumentTypeManager manager) {
AnnotationTypeRegistry registry = manager.getAnnotationTypeRegistry();
AnnotationType company = registry.getType("company");
AnnotationType industry = registry.getType("industry");
AnnotationType person = registry.getType("person");
AnnotationType location = registry.getType("location");
SpanTree tree = new SpanTree("testannotations");
SpanList root = (SpanList) tree.getRoot();
SpanNode span1 = new Span(0, 5);
SpanNode span2 = new Span(5, 10);
SpanNode span3 = new Span(10, 15);
SpanNode span4 = new Span(15, 20);
SpanNode span5 = new Span(6, 10);
SpanNode span6 = new Span(8, 4);
SpanNode span7 = new Span(4, 2);
root.add(span1);
root.add(span2);
root.add(span4);
root.add(span5);
root.add(span6);
AlternateSpanList aspl = new AlternateSpanList();
aspl.add(span7);
List<SpanNode> subtree1 = new ArrayList<SpanNode>();
subtree1.add(span3);
aspl.addChildren(1, subtree1, 33.0d);
root.add(aspl);
Struct personValue = (Struct) person.getDataType().createFieldValue();
personValue.setFieldValue("name", "Richard Bair");
Annotation personAn = new Annotation(person, personValue);
tree.annotate(span1, personAn);
Struct companyValue = (Struct) company.getDataType().createFieldValue();
companyValue.setFieldValue("name", "Sun");
Annotation compAn = new Annotation(company, companyValue);
tree.annotate(span2, compAn);
Struct locationVal = new Struct(manager.getDataType("annotation.location"));
locationVal.setFieldValue("lat", 37.774929);
locationVal.setFieldValue("lon", -122.419415);
Annotation locAnnotation = new Annotation(location, locationVal);
tree.annotate(span3, locAnnotation);
Struct dirValue1 = new Struct(manager.getDataType("annotation.person"));
dirValue1.setFieldValue("name", "Jonathan Schwartz");
Annotation dirAnnotation1 = new Annotation(person, dirValue1);
tree.annotate(span5, dirAnnotation1);
Struct dirValue2 = new Struct(manager.getDataType("annotation.person"));
dirValue2.setFieldValue("name", "Scott Mcnealy");
Annotation dirAnnotation2 = new Annotation(person, dirValue2);
tree.annotate(span6, dirAnnotation2);
Struct indValue = new Struct(manager.getDataType("annotation.industry"));
indValue.setFieldValue("vertical", "Manufacturing");
Annotation indAn = new Annotation(industry, indValue);
tree.annotate(span4, indAn);
Field compLocField = ((StructDataType) company.getDataType()).getField("place");
AnnotationReferenceDataType annType = (AnnotationReferenceDataType) compLocField.getDataType();
FieldValue compLocFieldVal = new AnnotationReference(annType, locAnnotation);
companyValue.setFieldValue(compLocField, compLocFieldVal);
companyValue.setFieldValue("vertical", "software");
Field dirField = ((StructDataType) company.getDataType()).getField("directors");
Array<FieldValue> dirFieldVal = new Array<FieldValue>(dirField.getDataType());
AnnotationReferenceDataType annRefType = (AnnotationReferenceDataType) ((ArrayDataType) dirField.getDataType()).getNestedType();
dirFieldVal.add(new AnnotationReference(annRefType, dirAnnotation1));
dirFieldVal.add(new AnnotationReference(annRefType, dirAnnotation2));
companyValue.setFieldValue(dirField, dirFieldVal);
tree.clearAnnotations(span3);
StringFieldValue body = (StringFieldValue) document.getFieldValue(document.getDataType().getField("body"));
body.setSpanTree(tree);
document.setFieldValue(document.getDataType().getField("body"), body);
}
use of com.yahoo.document.StructDataType in project vespa by vespa-engine.
the class Bug6425939TestCase method setUp.
@Before
public void setUp() {
man = new DocumentTypeManager();
person = new StructDataType("personStruct");
person.addField(new Field("foo", DataType.STRING));
person.addField(new Field("bar", DataType.INT));
man.register(person);
personA = new AnnotationType("person", person);
man.getAnnotationTypeRegistry().register(personA);
}
Aggregations