-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Tim Dawborn edited this page Mar 10, 2014
·
2 revisions
import java.io.*;
import org.schwa.dr.*;
@dr.Ann
public class Token extends AbstractAnn {
@dr.Field public ByteSlice span;
@dr.Field public String raw;
@dr.Field public String lemma;
@dr.Field public String pos;
}
@dr.Ann(serial="MyChunk")
public class Chunk extends AbstractAnn {
@dr.Pointer(store="tokens") public Slice<Token> span;
@dr.Field(serial="gold_tag") public String tag;
}
@dr.Doc
public class Doc extends AbstractDoc {
@dr.Store public Store<Token> tokens = new Store<Token>();
@dr.Store public Store<Chunk> chunks = new Store<Chunk>();
}
public class Main {
public static void main(String[] args) throws IOException {
// Create a schema for writing.
DocSchema docSchema = DocSchema.create(Doc.class);
// Change the serial name of Token.pos to Token.gold_pos.
docSchema.getSchema(Token.class).getField("pos").setSerial("gold_pos");
// Construct a writer.
OutputStream out = ...;
Writer writer = new Writer(out, docSchema);
// Write documents to the stream.
while (...) {
Doc doc = ...;
writer.write(doc);
}
// Construct a reader.
InputStream in = ...;
Reader<Doc> reader = new Reader<Doc>(in, docSchema);
// Read documents from the stream.
for (Doc doc : reader) {
...
}
}
}