Search in sources :

Example 31 with DocumentTypeManager

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);
}
Also used : Struct(com.yahoo.document.datatypes.Struct) Array(com.yahoo.document.datatypes.Array) Field(com.yahoo.document.Field) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StructDataType(com.yahoo.document.StructDataType) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue)

Example 32 with DocumentTypeManager

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);
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) DocumentType(com.yahoo.document.DocumentType) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Document(com.yahoo.document.Document) Test(org.junit.Test)

Example 33 with DocumentTypeManager

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);
}
Also used : Field(com.yahoo.document.Field) StructDataType(com.yahoo.document.StructDataType) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) Before(org.junit.Before)

Example 34 with DocumentTypeManager

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()));
}
Also used : Receptor(com.yahoo.messagebus.test.Receptor) RPCNetworkParams(com.yahoo.messagebus.network.rpc.RPCNetworkParams) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) Slobrok(com.yahoo.jrt.slobrok.server.Slobrok) TestServer(com.yahoo.messagebus.network.rpc.test.TestServer) DocumentProtocol(com.yahoo.documentapi.messagebus.protocol.DocumentProtocol)

Example 35 with DocumentTypeManager

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));
}
Also used : Receptor(com.yahoo.messagebus.test.Receptor) RPCNetworkParams(com.yahoo.messagebus.network.rpc.RPCNetworkParams) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) Slobrok(com.yahoo.jrt.slobrok.server.Slobrok) Identity(com.yahoo.messagebus.network.Identity) DocumentProtocol(com.yahoo.documentapi.messagebus.protocol.DocumentProtocol) TestServer(com.yahoo.messagebus.network.rpc.test.TestServer)

Aggregations

DocumentTypeManager (com.yahoo.document.DocumentTypeManager)35 Test (org.junit.Test)18 DocumentType (com.yahoo.document.DocumentType)17 Document (com.yahoo.document.Document)12 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)7 Field (com.yahoo.document.Field)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 DeserializationException (com.yahoo.document.serialization.DeserializationException)5 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)5 DocumentPut (com.yahoo.document.DocumentPut)4 IlscriptsConfig (com.yahoo.vespa.configdefinition.IlscriptsConfig)4 StructDataType (com.yahoo.document.StructDataType)3 Before (org.junit.Before)3 DocumentUpdate (com.yahoo.document.DocumentUpdate)2 DocumentmanagerConfig (com.yahoo.document.config.DocumentmanagerConfig)2 Array (com.yahoo.document.datatypes.Array)2 DocumentProtocol (com.yahoo.documentapi.messagebus.protocol.DocumentProtocol)2 Slobrok (com.yahoo.jrt.slobrok.server.Slobrok)2 RPCNetworkParams (com.yahoo.messagebus.network.rpc.RPCNetworkParams)2 TestServer (com.yahoo.messagebus.network.rpc.test.TestServer)2