use of com.yahoo.document.annotation.AnnotationType in project vespa by vespa-engine.
the class DocumentTypeManagerConfigurer method addAnnotationTypeInheritance.
private static void addAnnotationTypeInheritance(DocumentmanagerConfig config, DocumentTypeManager manager) {
for (DocumentmanagerConfig.Annotationtype annType : config.annotationtype()) {
if (annType.inherits().size() > 0) {
AnnotationType inheritedType = manager.getAnnotationTypeRegistry().getType(annType.inherits(0).id());
AnnotationType type = manager.getAnnotationTypeRegistry().getType(annType.id());
type.inherit(inheritedType);
}
}
}
use of com.yahoo.document.annotation.AnnotationType in project vespa by vespa-engine.
the class DocumentTypeManager method registerDefaultDataTypes.
private void registerDefaultDataTypes() {
DocumentType superDocType = DataType.DOCUMENT;
dataTypes.put(superDocType.getId(), superDocType);
documentTypes.put(superDocType.getDataTypeName(), superDocType);
Class<? extends DataType> dataTypeClass = DataType.class;
for (java.lang.reflect.Field field : dataTypeClass.getFields()) {
if (Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) {
if (DataType.class.isAssignableFrom(field.getType())) {
try {
// these are all static final DataTypes listed in DataType:
DataType type = (DataType) field.get(null);
register(type);
} catch (IllegalAccessException e) {
// ignore
}
}
}
}
for (AnnotationType type : AnnotationTypes.ALL_TYPES) {
annotationTypeRegistry.register(type);
}
}
use of com.yahoo.document.annotation.AnnotationType in project vespa by vespa-engine.
the class DocumentGenMojo method execute.
void execute(File sdDir, File outputDir, String packageName) throws MojoFailureException {
if ("".equals(packageName))
throw new IllegalArgumentException("You may not use empty package for generated types.");
searches = new HashMap<String, Search>();
docTypes = new HashMap<String, String>();
structTypes = new HashMap<String, String>();
annotationTypes = new HashMap<String, String>();
outputDir.mkdirs();
SearchBuilder builder = buildSearches(sdDir);
boolean annotationsExported = false;
for (NewDocumentType docType : builder.getModel().getDocumentManager().getTypes()) {
if (docType != VespaDocumentType.INSTANCE) {
exportDocumentSources(outputDir, docType, packageName);
for (AnnotationType annotationType : docType.getAllAnnotations()) {
if (provided(annotationType.getName()) != null)
continue;
annotationsExported = true;
exportAnnotationSources(outputDir, annotationType, docType, packageName);
}
}
}
exportPackageInfo(outputDir, packageName);
if (annotationsExported)
exportPackageInfo(outputDir, packageName + ".annotation");
exportDocFactory(outputDir, builder.getSearchList(), packageName);
if (project != null)
project.addCompileSourceRoot(outputDirectory.toString());
}
use of com.yahoo.document.annotation.AnnotationType in project vespa by vespa-engine.
the class StringTestCase method annotate.
public Document 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");
Map<String, AnnotationType> m = registry.getTypes();
for (String key : m.keySet()) {
System.out.println("Key: " + key);
AnnotationType val = m.get(key);
parseAnnotationType(val);
}
SpanTree tree = new SpanTree("testannotations");
SpanList root = (SpanList) tree.getRoot();
SpanNode companySpan = new Span(0, 5);
SpanNode industrySpan = new Span(5, 10);
SpanNode personSpan = new Span(10, 15);
SpanNode locationSpan = new Span(15, 20);
root.add(companySpan);
root.add(industrySpan);
root.add(personSpan);
root.add(locationSpan);
Struct companyValue = (Struct) company.getDataType().createFieldValue();
companyValue.setFieldValue("name", new StringFieldValue("Sun"));
companyValue.setFieldValue("ceo", new StringFieldValue("Scott Mcnealy"));
companyValue.setFieldValue("lat", new DoubleFieldValue(37.7));
companyValue.setFieldValue("lon", new DoubleFieldValue(-122.44));
companyValue.setFieldValue("vertical", new StringFieldValue("software"));
Annotation compAn = new Annotation(company, companyValue);
tree.annotate(companySpan, compAn);
Struct personValue = new Struct(manager.getDataType("annotation.person"));
personValue.setFieldValue("name", new StringFieldValue("Richard Bair"));
Annotation personAn = new Annotation(person, personValue);
tree.annotate(personSpan, personAn);
Struct locValue = new Struct(manager.getDataType("annotation.location"));
locValue.setFieldValue("name", new StringFieldValue("Prinsens Gate"));
Annotation loc = new Annotation(location, locValue);
tree.annotate(locationSpan, loc);
Struct locValue2 = new Struct(manager.getDataType("annotation.location"));
locValue2.setFieldValue("name", new StringFieldValue("Kongens Gate"));
Annotation locAn = new Annotation(location, locValue2);
tree.annotate(locationSpan, locAn);
SpanList branch = new SpanList();
SpanNode span1 = new Span(0, 3);
SpanNode span2 = new Span(1, 9);
SpanNode span3 = new Span(12, 10);
branch.add(span1);
branch.add(span3);
branch.add(span2);
Struct industryValue = new Struct(manager.getDataType("annotation.industry"));
industryValue.setFieldValue("vertical", new StringFieldValue("Manufacturing"));
Annotation ind = new Annotation(industry, industryValue);
tree.annotate(span1, ind);
Struct pValue = new Struct(manager.getDataType("annotation.person"));
pValue.setFieldValue("name", new StringFieldValue("Praveen Mohan"));
Annotation pAn = new Annotation(person, pValue);
tree.annotate(span2, pAn);
Struct lValue = new Struct(manager.getDataType("annotation.location"));
lValue.setFieldValue("name", new StringFieldValue("Embassy Golf Links"));
Annotation locn = new Annotation(location, lValue);
tree.annotate(span3, locn);
Struct cValue = (Struct) company.getDataType().createFieldValue();
cValue.setFieldValue("name", new StringFieldValue("Yahoo"));
cValue.setFieldValue("ceo", new StringFieldValue("Carol Bartz"));
cValue.setFieldValue("lat", new DoubleFieldValue(127.7));
cValue.setFieldValue("lon", new DoubleFieldValue(-42.44));
cValue.setFieldValue("vertical", new StringFieldValue("search"));
Annotation cAn = new Annotation(company, cValue);
tree.annotate(branch, cAn);
Struct pVal = new Struct(manager.getDataType("annotation.person"));
pVal.setFieldValue("name", new StringFieldValue("Kim Omar"));
Annotation an = new Annotation(person, pVal);
tree.annotate(root, an);
root.add(branch);
StringFieldValue body = (StringFieldValue) document.getFieldValue(document.getDataType().getField("body"));
root.remove(branch);
tree.cleanup();
System.out.println("No. Of Annotations: " + tree.numAnnotations());
body.setSpanTree(tree);
document.setFieldValue(document.getField("body"), body);
return document;
}
use of com.yahoo.document.annotation.AnnotationType in project vespa by vespa-engine.
the class StringTestCase method testNestedSpanTreeBug4187377.
@Test
public void testNestedSpanTreeBug4187377() {
AnnotationType type = new AnnotationType("ann", DataType.STRING);
StringFieldValue outerString = new StringFieldValue("Ballooo");
SpanTree outerTree = new SpanTree("outer");
outerString.setSpanTree(outerTree);
SpanList outerRoot = (SpanList) outerTree.getRoot();
Span outerSpan = new Span(0, 1);
outerRoot.add(outerSpan);
StringFieldValue innerString = new StringFieldValue("innerBalloooo");
outerTree.annotate(outerSpan, new Annotation(type, innerString));
SpanTree innerTree = new SpanTree("inner");
innerString.setSpanTree(innerTree);
SpanList innerRoot = (SpanList) innerTree.getRoot();
Span innerSpan = new Span(0, 1);
innerRoot.add(innerSpan);
innerTree.annotate(innerSpan, new Annotation(type));
GrowableByteBuffer buffer = new GrowableByteBuffer(1024);
DocumentSerializer serializer = DocumentSerializerFactory.create42(buffer);
try {
serializer.write(null, outerString);
fail("Should have failed, nested span trees are not supported.");
} catch (SerializationException se) {
// OK!
}
}
Aggregations