Load data from word segmentation results to generate corpus
(cls, inputs, fields)
| 146 | |
| 147 | @classmethod |
| 148 | def load_word_segments(cls, inputs, fields): |
| 149 | """Load data from word segmentation results to generate corpus""" |
| 150 | fields = [fd if fd is not None else Field(str(i)) for i, fd in enumerate(fields)] |
| 151 | sentences = [] |
| 152 | for tokens in inputs: |
| 153 | values = [list(range(1, len(tokens) + 1)), tokens, tokens] + [['-'] * len(tokens) for _ in range(7)] |
| 154 | |
| 155 | sentences.append(Sentence(fields, values)) |
| 156 | return cls(fields, sentences) |
| 157 | |
| 158 | def save(self, path): |
| 159 | """Dumping corpus to disk""" |