class ParseState(object): """Support object for read().""" def __init__(self, config=defaults, name=None): self.config = config self.dataset = Dataset(name=name) self.document = Document() self.texts = [] self.tags = [] def sentence_break(self): if len(self.texts) == 0: return if self.config.iobes: self.tags = iob_to_iobes(self.tags) tokens = [Token(t, g) for t, g in zip(self.texts, self.tags)] self.document.add_child(Sentence(tokens=tokens)) self.texts = [] self.tags = [] def document_break(self): self.sentence_break() if len(self.document) == 0: return self.dataset.add_child(self.document) self.document = Document() def finish(self): self.document_break()