Akron | e396a93 | 2021-10-19 01:06:13 +0200 | [diff] [blame] | 1 | package datok |
| 2 | |
| 3 | import ( |
| 4 | "bufio" |
| 5 | "io" |
| 6 | ) |
| 7 | |
| 8 | type TokenWriterI interface { |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 9 | SentenceEnd(int) |
| 10 | TextEnd(int) |
Akron | e396a93 | 2021-10-19 01:06:13 +0200 | [diff] [blame] | 11 | Token(int, []rune) |
| 12 | Flush() error |
| 13 | } |
| 14 | |
| 15 | var _ TokenWriterI = &TokenWriterSimple{} |
| 16 | |
| 17 | type TokenWriterSimple struct { |
| 18 | writer *bufio.Writer |
| 19 | } |
| 20 | |
| 21 | func NewTokenWriterSimple(w io.Writer) *TokenWriterSimple { |
| 22 | return &TokenWriterSimple{bufio.NewWriter(w)} |
| 23 | } |
| 24 | |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 25 | func (tw *TokenWriterSimple) SentenceEnd(_ int) { |
Akron | e396a93 | 2021-10-19 01:06:13 +0200 | [diff] [blame] | 26 | tw.writer.WriteRune('\n') |
| 27 | } |
| 28 | |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 29 | func (tw *TokenWriterSimple) TextEnd(_ int) { |
| 30 | tw.writer.WriteRune('\n') |
| 31 | tw.writer.Flush() |
| 32 | } |
| 33 | |
Akron | e396a93 | 2021-10-19 01:06:13 +0200 | [diff] [blame] | 34 | func (tw *TokenWriterSimple) Token(_ int, buf []rune) { |
| 35 | tw.writer.WriteString(string(buf)) |
| 36 | tw.writer.WriteRune('\n') |
| 37 | } |
| 38 | |
| 39 | func (tw *TokenWriterSimple) Flush() error { |
| 40 | return tw.writer.Flush() |
| 41 | } |