use of com.yahoo.document.DocumentTypeManager 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.DocumentTypeManager in project vespa by vespa-engine.
the class Bug4259784TestCase method testSerialize.
@Test
public void testSerialize() {
DocumentTypeManager manager = new DocumentTypeManager();
DocumentTypeManagerConfigurer.configure(manager, "file:src/test/java/com/yahoo/document/annotation/documentmanager.bug4259784.cfg");
DocumentType type = manager.getDocumentType("blog");
Document doc = new Document(type, "doc:this:is:a:test");
doc.setFieldValue("body", new StringFieldValue("bla bla bla bla bla bla bla" + "bla bla bla bla bla bla bla"));
annotate(doc, manager);
GrowableByteBuffer buf = new GrowableByteBuffer();
doc.serialize(buf);
}
use of com.yahoo.document.DocumentTypeManager 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);
}
use of com.yahoo.document.DocumentTypeManager in project vespa by vespa-engine.
the class PolicyFactoryTestCase method setUp.
@Override
public void setUp() throws ListenFailedException {
slobrok = new Slobrok();
srv = new TestServer(new MessageBusParams().addProtocol(new DocumentProtocol(new DocumentTypeManager())), new RPCNetworkParams().setSlobrokConfigId(TestServer.getSlobrokConfig(slobrok)));
src = srv.mb.createSourceSession(new SourceSessionParams().setReplyHandler(new Receptor()));
}
use of com.yahoo.document.DocumentTypeManager in project vespa by vespa-engine.
the class RoutableFactoryTestCase method setUp.
@Override
public void setUp() throws ListenFailedException {
slobrok = new Slobrok();
DocumentTypeManager docMan = new DocumentTypeManager();
dstProtocol = new DocumentProtocol(docMan);
dstServer = new TestServer(new MessageBusParams().addProtocol(dstProtocol), new RPCNetworkParams().setIdentity(new Identity("dst")).setSlobrokConfigId(TestServer.getSlobrokConfig(slobrok)));
dstSession = dstServer.mb.createDestinationSession(new DestinationSessionParams().setName("session").setMessageHandler(new Receptor()));
srcProtocol = new DocumentProtocol(docMan);
srcServer = new TestServer(new MessageBusParams().addProtocol(srcProtocol), new RPCNetworkParams().setSlobrokConfigId(TestServer.getSlobrokConfig(slobrok)));
srcSession = srcServer.mb.createSourceSession(new SourceSessionParams().setReplyHandler(new Receptor()));
assertTrue(srcServer.waitSlobrok("dst/session", 1));
}
Aggregations