Akron | 7f1097f | 2021-09-21 16:00:29 +0200 | [diff] [blame] | 1 | package datok |
Akron | 8ef408b | 2021-08-02 22:11:04 +0200 | [diff] [blame] | 2 | |
| 3 | import ( |
Akron | 6247a5d | 2021-08-03 19:18:28 +0200 | [diff] [blame] | 4 | "bytes" |
Akron | bd40680 | 2021-08-11 18:39:13 +0200 | [diff] [blame] | 5 | "fmt" |
| 6 | "os" |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 7 | "regexp" |
Akron | 3f8571a | 2021-08-05 11:18:10 +0200 | [diff] [blame] | 8 | "strings" |
Akron | 8ef408b | 2021-08-02 22:11:04 +0200 | [diff] [blame] | 9 | "testing" |
| 10 | |
| 11 | "github.com/stretchr/testify/assert" |
| 12 | ) |
| 13 | |
Akron | 9fb63af | 2021-10-28 01:15:53 +0200 | [diff] [blame] | 14 | var dat *DaTokenizer |
| 15 | |
Akron | 1c34ce6 | 2021-09-23 23:27:39 +0200 | [diff] [blame] | 16 | func tmatch(tok Tokenizer, s string) bool { |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 17 | b := make([]byte, 0, 2048) |
| 18 | w := bytes.NewBuffer(b) |
Akron | 1c34ce6 | 2021-09-23 23:27:39 +0200 | [diff] [blame] | 19 | return tok.Transduce(strings.NewReader(s), w) |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 20 | } |
| 21 | |
Akron | 1c34ce6 | 2021-09-23 23:27:39 +0200 | [diff] [blame] | 22 | func ttokenize(tok Tokenizer, w *bytes.Buffer, str string) []string { |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 23 | w.Reset() |
Akron | 1c34ce6 | 2021-09-23 23:27:39 +0200 | [diff] [blame] | 24 | ok := tok.Transduce(strings.NewReader(str), w) |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 25 | if !ok { |
| 26 | return []string{} |
| 27 | } |
| 28 | obj := regexp.MustCompile("\n+") |
| 29 | |
| 30 | tokens := obj.Split(w.String(), -1) |
| 31 | return tokens[:len(tokens)-1] |
| 32 | } |
| 33 | |
Akron | c9c0eae | 2021-10-22 19:49:43 +0200 | [diff] [blame] | 34 | func TestDoubleArraySimpleString(t *testing.T) { |
Akron | 8ef408b | 2021-08-02 22:11:04 +0200 | [diff] [blame] | 35 | assert := assert.New(t) |
| 36 | |
| 37 | // bau | bauamt |
Akron | 64ffd9a | 2021-08-03 19:55:21 +0200 | [diff] [blame] | 38 | tok := LoadFomaFile("testdata/bauamt.fst") |
Akron | f2120ca | 2021-08-03 16:26:41 +0200 | [diff] [blame] | 39 | dat := tok.ToDoubleArray() |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 40 | assert.True(tmatch(dat, "bau")) |
| 41 | assert.True(tmatch(dat, "bauamt")) |
| 42 | assert.False(tmatch(dat, "baum")) |
Akron | e396a93 | 2021-10-19 01:06:13 +0200 | [diff] [blame] | 43 | assert.True(tmatch(dat, "baua")) |
Akron | 8ef408b | 2021-08-02 22:11:04 +0200 | [diff] [blame] | 44 | } |
Akron | 75ebe7f | 2021-08-03 10:34:10 +0200 | [diff] [blame] | 45 | |
Akron | c9c0eae | 2021-10-22 19:49:43 +0200 | [diff] [blame] | 46 | func TestDoubleArraySimpleBranches(t *testing.T) { |
Akron | 75ebe7f | 2021-08-03 10:34:10 +0200 | [diff] [blame] | 47 | assert := assert.New(t) |
| 48 | |
| 49 | // (bau | wahl) (amt | en) |
Akron | 64ffd9a | 2021-08-03 19:55:21 +0200 | [diff] [blame] | 50 | tok := LoadFomaFile("testdata/wahlamt.fst") |
Akron | f2120ca | 2021-08-03 16:26:41 +0200 | [diff] [blame] | 51 | dat := tok.ToDoubleArray() |
Akron | e396a93 | 2021-10-19 01:06:13 +0200 | [diff] [blame] | 52 | assert.True(tmatch(dat, "bau")) |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 53 | assert.True(tmatch(dat, "bauamt")) |
| 54 | assert.True(tmatch(dat, "wahlamt")) |
| 55 | assert.True(tmatch(dat, "bauen")) |
| 56 | assert.True(tmatch(dat, "wahlen")) |
| 57 | assert.False(tmatch(dat, "baum")) |
Akron | 75ebe7f | 2021-08-03 10:34:10 +0200 | [diff] [blame] | 58 | } |
Akron | 730a79c | 2021-08-03 11:05:29 +0200 | [diff] [blame] | 59 | |
| 60 | func TestSimpleTokenizer(t *testing.T) { |
| 61 | assert := assert.New(t) |
Akron | 64ffd9a | 2021-08-03 19:55:21 +0200 | [diff] [blame] | 62 | tok := LoadFomaFile("testdata/simpletok.fst") |
Akron | f2120ca | 2021-08-03 16:26:41 +0200 | [diff] [blame] | 63 | dat := tok.ToDoubleArray() |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 64 | assert.True(tmatch(dat, "bau")) |
| 65 | assert.True(tmatch(dat, "bad")) |
| 66 | assert.True(tmatch(dat, "wald gehen")) |
Akron | 730a79c | 2021-08-03 11:05:29 +0200 | [diff] [blame] | 67 | } |
Akron | 740f3d7 | 2021-08-03 12:12:34 +0200 | [diff] [blame] | 68 | |
Akron | c9c0eae | 2021-10-22 19:49:43 +0200 | [diff] [blame] | 69 | func TestDoubleArraySimpleTokenizerTransduce(t *testing.T) { |
Akron | 84d68e6 | 2021-08-04 17:06:52 +0200 | [diff] [blame] | 70 | assert := assert.New(t) |
| 71 | tok := LoadFomaFile("testdata/simpletok.fst") |
Akron | 84d68e6 | 2021-08-04 17:06:52 +0200 | [diff] [blame] | 72 | dat := tok.ToDoubleArray() |
Akron | 3f8571a | 2021-08-05 11:18:10 +0200 | [diff] [blame] | 73 | |
| 74 | r := strings.NewReader(" wald gehen Da kann\t man was \"erleben\"!") |
| 75 | b := make([]byte, 0, 2048) |
| 76 | w := bytes.NewBuffer(b) |
Akron | 524c543 | 2021-08-05 14:14:27 +0200 | [diff] [blame] | 77 | var tokens []string |
Akron | 524c543 | 2021-08-05 14:14:27 +0200 | [diff] [blame] | 78 | dat.Transduce(r, w) |
| 79 | tokens = strings.Split(w.String(), "\n") |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 80 | assert.Equal(len(tokens), 11) |
Akron | 3f8571a | 2021-08-05 11:18:10 +0200 | [diff] [blame] | 81 | assert.Equal("wald", tokens[0]) |
| 82 | assert.Equal("gehen", tokens[1]) |
| 83 | assert.Equal("Da", tokens[2]) |
| 84 | assert.Equal("kann", tokens[3]) |
| 85 | assert.Equal("man", tokens[4]) |
| 86 | assert.Equal("was", tokens[5]) |
| 87 | assert.Equal("\"erleben\"", tokens[6]) |
| 88 | |
Akron | 524c543 | 2021-08-05 14:14:27 +0200 | [diff] [blame] | 89 | r = strings.NewReader(" In den Wald gehen? -- Da kann\t man was \"erleben\"!") |
| 90 | w.Reset() |
| 91 | dat.Transduce(r, w) |
| 92 | tokens = strings.Split(w.String(), "\n") |
| 93 | assert.Equal("In", tokens[0]) |
| 94 | assert.Equal("den", tokens[1]) |
| 95 | assert.Equal("Wald", tokens[2]) |
| 96 | assert.Equal("gehen", tokens[3]) |
| 97 | assert.Equal("?", tokens[4]) |
| 98 | assert.Equal("--", tokens[5]) |
Akron | 3f8571a | 2021-08-05 11:18:10 +0200 | [diff] [blame] | 99 | |
Akron | 524c543 | 2021-08-05 14:14:27 +0200 | [diff] [blame] | 100 | r = strings.NewReader(" g? -- D") |
| 101 | w.Reset() |
| 102 | dat.Transduce(r, w) |
| 103 | tokens = strings.Split(w.String(), "\n") |
| 104 | assert.Equal("g", tokens[0]) |
| 105 | assert.Equal("?", tokens[1]) |
| 106 | assert.Equal("--", tokens[2]) |
| 107 | assert.Equal("D", tokens[3]) |
| 108 | assert.Equal("", tokens[4]) |
Akron | 6e70dc8 | 2021-08-11 11:33:18 +0200 | [diff] [blame] | 109 | assert.Equal("", tokens[5]) |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 110 | assert.Equal(7, len(tokens)) |
Akron | 068874c | 2021-08-04 15:19:56 +0200 | [diff] [blame] | 111 | } |
| 112 | |
Akron | c9c0eae | 2021-10-22 19:49:43 +0200 | [diff] [blame] | 113 | func TestDoubleArrayReadWriteTokenizer(t *testing.T) { |
Akron | 740f3d7 | 2021-08-03 12:12:34 +0200 | [diff] [blame] | 114 | assert := assert.New(t) |
Akron | 64ffd9a | 2021-08-03 19:55:21 +0200 | [diff] [blame] | 115 | tok := LoadFomaFile("testdata/simpletok.fst") |
Akron | f2120ca | 2021-08-03 16:26:41 +0200 | [diff] [blame] | 116 | dat := tok.ToDoubleArray() |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 117 | assert.True(tmatch(dat, "bau")) |
| 118 | assert.True(tmatch(dat, "bad")) |
| 119 | assert.True(tmatch(dat, "wald gehen")) |
Akron | 6247a5d | 2021-08-03 19:18:28 +0200 | [diff] [blame] | 120 | |
Akron | 3f8571a | 2021-08-05 11:18:10 +0200 | [diff] [blame] | 121 | b := make([]byte, 0, 1024) |
Akron | 6247a5d | 2021-08-03 19:18:28 +0200 | [diff] [blame] | 122 | buf := bytes.NewBuffer(b) |
| 123 | n, err := dat.WriteTo(buf) |
| 124 | assert.Nil(err) |
Akron | 29e306f | 2021-09-02 18:29:56 +0200 | [diff] [blame] | 125 | assert.Equal(int64(296), n) |
Akron | 3f8571a | 2021-08-05 11:18:10 +0200 | [diff] [blame] | 126 | |
| 127 | dat2 := ParseDatok(buf) |
| 128 | assert.NotNil(dat2) |
| 129 | assert.Equal(dat.array, dat2.array) |
| 130 | assert.Equal(dat.sigma, dat2.sigma) |
| 131 | assert.Equal(dat.epsilon, dat2.epsilon) |
| 132 | assert.Equal(dat.unknown, dat2.unknown) |
| 133 | assert.Equal(dat.identity, dat2.identity) |
| 134 | assert.Equal(dat.final, dat2.final) |
| 135 | assert.Equal(dat.LoadFactor(), dat2.LoadFactor()) |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 136 | assert.True(tmatch(dat2, "bau")) |
| 137 | assert.True(tmatch(dat2, "bad")) |
| 138 | assert.True(tmatch(dat2, "wald gehen")) |
Akron | 4fa28b3 | 2021-08-27 10:55:41 +0200 | [diff] [blame] | 139 | |
Akron | 92704eb | 2021-08-27 10:59:46 +0200 | [diff] [blame] | 140 | assert.Equal(dat.TransCount(), 17) |
| 141 | assert.Equal(dat2.TransCount(), 17) |
Akron | 6247a5d | 2021-08-03 19:18:28 +0200 | [diff] [blame] | 142 | } |
| 143 | |
Akron | c9c0eae | 2021-10-22 19:49:43 +0200 | [diff] [blame] | 144 | func TestDoubleArrayIgnorableMCS(t *testing.T) { |
Akron | e396a93 | 2021-10-19 01:06:13 +0200 | [diff] [blame] | 145 | |
| 146 | // This test relies on final states. That's why it is |
| 147 | // not working correctly anymore. |
| 148 | |
Akron | 31f3c06 | 2021-08-27 10:15:13 +0200 | [diff] [blame] | 149 | assert := assert.New(t) |
| 150 | // File has MCS in sigma but not in net |
| 151 | tok := LoadFomaFile("testdata/ignorable_mcs.fst") |
| 152 | assert.NotNil(tok) |
| 153 | dat := tok.ToDoubleArray() |
| 154 | assert.NotNil(dat) |
| 155 | |
| 156 | b := make([]byte, 0, 2048) |
| 157 | w := bytes.NewBuffer(b) |
| 158 | var tokens []string |
| 159 | |
| 160 | // Is only unambigous when transducing strictly greedy! |
Akron | e396a93 | 2021-10-19 01:06:13 +0200 | [diff] [blame] | 161 | assert.True(dat.Transduce(strings.NewReader("ab<ab>a"), w)) |
Akron | 31f3c06 | 2021-08-27 10:15:13 +0200 | [diff] [blame] | 162 | tokens = strings.Split(w.String(), "\n") |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 163 | assert.Equal("a\nb\n<ab>a\n\n\n", w.String()) |
Akron | 31f3c06 | 2021-08-27 10:15:13 +0200 | [diff] [blame] | 164 | assert.Equal("a", tokens[0]) |
| 165 | assert.Equal("b", tokens[1]) |
Akron | e396a93 | 2021-10-19 01:06:13 +0200 | [diff] [blame] | 166 | assert.Equal("<ab>a", tokens[2]) |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 167 | assert.Equal(6, len(tokens)) |
Akron | 92704eb | 2021-08-27 10:59:46 +0200 | [diff] [blame] | 168 | assert.Equal(dat.TransCount(), 15) |
Akron | 31f3c06 | 2021-08-27 10:15:13 +0200 | [diff] [blame] | 169 | } |
| 170 | |
Akron | c9c0eae | 2021-10-22 19:49:43 +0200 | [diff] [blame] | 171 | func TestDoubleArrayFullTokenizer(t *testing.T) { |
Akron | 3a063ef | 2021-08-05 19:36:35 +0200 | [diff] [blame] | 172 | assert := assert.New(t) |
Akron | 9fb63af | 2021-10-28 01:15:53 +0200 | [diff] [blame] | 173 | |
| 174 | if dat == nil { |
| 175 | dat = LoadDatokFile("testdata/tokenizer.datok") |
| 176 | } |
Akron | 3a063ef | 2021-08-05 19:36:35 +0200 | [diff] [blame] | 177 | assert.NotNil(dat) |
| 178 | assert.True(dat.LoadFactor() >= 70) |
| 179 | assert.Equal(dat.epsilon, 1) |
| 180 | assert.Equal(dat.unknown, 2) |
| 181 | assert.Equal(dat.identity, 3) |
Akron | fac8abc | 2021-11-10 07:19:59 +0100 | [diff] [blame] | 182 | assert.Equal(dat.final, 142) |
| 183 | assert.Equal(len(dat.sigma), 137) |
| 184 | // assert.True(len(dat.array) > 3000000) |
| 185 | // assert.True(dat.maxSize > 3000000) |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 186 | assert.True(tmatch(dat, "bau")) |
| 187 | assert.True(tmatch(dat, "bad")) |
| 188 | assert.True(tmatch(dat, "wald gehen")) |
Akron | 740f3d7 | 2021-08-03 12:12:34 +0200 | [diff] [blame] | 189 | } |
Akron | 3f8571a | 2021-08-05 11:18:10 +0200 | [diff] [blame] | 190 | |
Akron | c9c0eae | 2021-10-22 19:49:43 +0200 | [diff] [blame] | 191 | func TestDoubleArrayTokenizerBranch(t *testing.T) { |
Akron | 941f215 | 2021-09-26 15:14:25 +0200 | [diff] [blame] | 192 | assert := assert.New(t) |
| 193 | tok := LoadTokenizerFile("testdata/simpletok.datok") |
| 194 | assert.NotNil(tok) |
| 195 | assert.Equal(tok.Type(), "DATOK") |
| 196 | |
| 197 | tok = LoadTokenizerFile("testdata/simpletok.matok") |
| 198 | assert.NotNil(tok) |
| 199 | assert.Equal(tok.Type(), "MATOK") |
| 200 | } |
| 201 | |
Akron | c9c0eae | 2021-10-22 19:49:43 +0200 | [diff] [blame] | 202 | func XTestDoubleArrayFullTokenizerBuild(t *testing.T) { |
Akron | a0bded5 | 2021-08-11 15:48:02 +0200 | [diff] [blame] | 203 | assert := assert.New(t) |
| 204 | tok := LoadFomaFile("testdata/tokenizer.fst") |
| 205 | dat := tok.ToDoubleArray() |
Akron | de18e90 | 2021-08-27 09:34:12 +0200 | [diff] [blame] | 206 | assert.NotNil(dat) |
| 207 | // n, err := dat.Save("testdata/tokenizer.datok") |
| 208 | // assert.Nil(err) |
| 209 | // assert.True(n > 500) |
Akron | a0bded5 | 2021-08-11 15:48:02 +0200 | [diff] [blame] | 210 | } |
| 211 | |
Akron | c9c0eae | 2021-10-22 19:49:43 +0200 | [diff] [blame] | 212 | func TestDoubleArrayFullTokenizerTransduce(t *testing.T) { |
Akron | 3610f10 | 2021-08-08 14:13:25 +0200 | [diff] [blame] | 213 | assert := assert.New(t) |
| 214 | |
Akron | 9fb63af | 2021-10-28 01:15:53 +0200 | [diff] [blame] | 215 | if dat == nil { |
| 216 | dat = LoadDatokFile("testdata/tokenizer.datok") |
| 217 | } |
| 218 | |
Akron | 3610f10 | 2021-08-08 14:13:25 +0200 | [diff] [blame] | 219 | assert.NotNil(dat) |
| 220 | |
Akron | 3610f10 | 2021-08-08 14:13:25 +0200 | [diff] [blame] | 221 | b := make([]byte, 0, 2048) |
| 222 | w := bytes.NewBuffer(b) |
| 223 | var tokens []string |
| 224 | |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 225 | assert.True(dat.Transduce(strings.NewReader("tra. u Du?"), w)) |
Akron | 3610f10 | 2021-08-08 14:13:25 +0200 | [diff] [blame] | 226 | |
| 227 | tokens = strings.Split(w.String(), "\n") |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 228 | assert.Equal("tra\n.\n\nu\nDu\n?\n\n\n", w.String()) |
Akron | 3610f10 | 2021-08-08 14:13:25 +0200 | [diff] [blame] | 229 | assert.Equal("tra", tokens[0]) |
| 230 | assert.Equal(".", tokens[1]) |
Akron | b4bbb47 | 2021-08-09 11:49:38 +0200 | [diff] [blame] | 231 | assert.Equal("", tokens[2]) |
Akron | c5d8d43 | 2021-08-10 16:48:44 +0200 | [diff] [blame] | 232 | assert.Equal("u", tokens[3]) |
Akron | b4bbb47 | 2021-08-09 11:49:38 +0200 | [diff] [blame] | 233 | assert.Equal("Du", tokens[4]) |
| 234 | assert.Equal("?", tokens[5]) |
Akron | 3610f10 | 2021-08-08 14:13:25 +0200 | [diff] [blame] | 235 | assert.Equal("", tokens[6]) |
Akron | 1594cb8 | 2021-08-11 11:14:56 +0200 | [diff] [blame] | 236 | assert.Equal("", tokens[7]) |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 237 | assert.Equal("", tokens[8]) |
| 238 | assert.Equal(9, len(tokens)) |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 239 | |
| 240 | w.Reset() |
| 241 | assert.True(dat.Transduce(strings.NewReader("\"John Doe\"@xx.com"), w)) |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 242 | assert.Equal("\"\nJohn\nDoe\n\"\n@xx\n.\n\ncom\n\n\n", w.String()) |
Akron | 3f8571a | 2021-08-05 11:18:10 +0200 | [diff] [blame] | 243 | } |
Akron | b7e1f13 | 2021-08-10 11:52:31 +0200 | [diff] [blame] | 244 | |
Akron | c9c0eae | 2021-10-22 19:49:43 +0200 | [diff] [blame] | 245 | func TestDoubleArrayFullTokenizerSentenceSplitter(t *testing.T) { |
Akron | b7e1f13 | 2021-08-10 11:52:31 +0200 | [diff] [blame] | 246 | assert := assert.New(t) |
Akron | 9fb63af | 2021-10-28 01:15:53 +0200 | [diff] [blame] | 247 | |
| 248 | if dat == nil { |
| 249 | dat = LoadDatokFile("testdata/tokenizer.datok") |
| 250 | } |
| 251 | |
Akron | b7e1f13 | 2021-08-10 11:52:31 +0200 | [diff] [blame] | 252 | assert.NotNil(dat) |
| 253 | |
| 254 | b := make([]byte, 0, 2048) |
| 255 | w := bytes.NewBuffer(b) |
| 256 | var sentences []string |
| 257 | |
| 258 | // testSentSplitterSimple |
Akron | 1594cb8 | 2021-08-11 11:14:56 +0200 | [diff] [blame] | 259 | assert.True(dat.Transduce(strings.NewReader("Der alte Mann."), w)) |
| 260 | sentences = strings.Split(w.String(), "\n\n") |
| 261 | |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 262 | assert.Equal("Der\nalte\nMann\n.\n\n\n", w.String()) |
Akron | 1594cb8 | 2021-08-11 11:14:56 +0200 | [diff] [blame] | 263 | assert.Equal("Der\nalte\nMann\n.", sentences[0]) |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 264 | assert.Equal("\n", sentences[1]) |
| 265 | assert.Equal(2, len(sentences)) |
Akron | 1594cb8 | 2021-08-11 11:14:56 +0200 | [diff] [blame] | 266 | |
| 267 | w.Reset() |
| 268 | assert.True(dat.Transduce(strings.NewReader("Der Vorsitzende der Abk. hat gewählt."), w)) |
| 269 | sentences = strings.Split(w.String(), "\n\n") |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 270 | assert.Equal(2, len(sentences)) |
Akron | 1594cb8 | 2021-08-11 11:14:56 +0200 | [diff] [blame] | 271 | assert.Equal("Der\nVorsitzende\nder\nAbk.\nhat\ngewählt\n.", sentences[0]) |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 272 | assert.Equal("\n", sentences[1]) |
Akron | 1594cb8 | 2021-08-11 11:14:56 +0200 | [diff] [blame] | 273 | |
| 274 | w.Reset() |
| 275 | assert.True(dat.Transduce(strings.NewReader(""), w)) |
Akron | b7e1f13 | 2021-08-10 11:52:31 +0200 | [diff] [blame] | 276 | sentences = strings.Split(w.String(), "\n\n") |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 277 | assert.Equal(2, len(sentences)) |
| 278 | assert.Equal("", sentences[0]) |
Akron | 1594cb8 | 2021-08-11 11:14:56 +0200 | [diff] [blame] | 279 | |
| 280 | w.Reset() |
| 281 | assert.True(dat.Transduce(strings.NewReader("Gefunden auf wikipedia.org."), w)) |
| 282 | sentences = strings.Split(w.String(), "\n\n") |
| 283 | assert.Equal(len(sentences), 2) |
| 284 | |
| 285 | w.Reset() |
| 286 | assert.True(dat.Transduce(strings.NewReader("Ich bin unter korap@ids-mannheim.de erreichbar."), w)) |
| 287 | sentences = strings.Split(w.String(), "\n\n") |
| 288 | assert.Equal(len(sentences), 2) |
| 289 | |
Akron | 6e70dc8 | 2021-08-11 11:33:18 +0200 | [diff] [blame] | 290 | w.Reset() |
| 291 | assert.True(dat.Transduce(strings.NewReader("Unsere Website ist https://korap.ids-mannheim.de/?q=Baum"), w)) |
| 292 | sentences = strings.Split(w.String(), "\n\n") |
| 293 | assert.Equal("Unsere\nWebsite\nist\nhttps://korap.ids-mannheim.de/?q=Baum", sentences[0]) |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 294 | assert.Equal("\n", sentences[1]) |
| 295 | assert.Equal(2, len(sentences)) |
Akron | 1594cb8 | 2021-08-11 11:14:56 +0200 | [diff] [blame] | 296 | |
Akron | 6e70dc8 | 2021-08-11 11:33:18 +0200 | [diff] [blame] | 297 | w.Reset() |
| 298 | assert.True(dat.Transduce(strings.NewReader("Unser Server ist 10.0.10.51."), w)) |
| 299 | sentences = strings.Split(w.String(), "\n\n") |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 300 | assert.Equal("\n", sentences[1]) |
| 301 | assert.Equal(2, len(sentences)) |
Akron | 1594cb8 | 2021-08-11 11:14:56 +0200 | [diff] [blame] | 302 | |
Akron | 6e70dc8 | 2021-08-11 11:33:18 +0200 | [diff] [blame] | 303 | w.Reset() |
| 304 | assert.True(dat.Transduce(strings.NewReader("Zu 50.4% ist es sicher"), w)) |
| 305 | sentences = strings.Split(w.String(), "\n\n") |
| 306 | assert.Equal(len(sentences), 2) |
Akron | 1594cb8 | 2021-08-11 11:14:56 +0200 | [diff] [blame] | 307 | |
Akron | 6e70dc8 | 2021-08-11 11:33:18 +0200 | [diff] [blame] | 308 | w.Reset() |
| 309 | assert.True(dat.Transduce(strings.NewReader("Der Termin ist am 5.9.2018"), w)) |
| 310 | sentences = strings.Split(w.String(), "\n\n") |
| 311 | assert.Equal(len(sentences), 2) |
Akron | 1594cb8 | 2021-08-11 11:14:56 +0200 | [diff] [blame] | 312 | |
Akron | 6e70dc8 | 2021-08-11 11:33:18 +0200 | [diff] [blame] | 313 | w.Reset() |
| 314 | assert.True(dat.Transduce(strings.NewReader("Ich habe die readme.txt heruntergeladen"), w)) |
| 315 | sentences = strings.Split(w.String(), "\n\n") |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 316 | assert.Equal(2, len(sentences)) |
Akron | 6e70dc8 | 2021-08-11 11:33:18 +0200 | [diff] [blame] | 317 | assert.Equal("Ich\nhabe\ndie\nreadme.txt\nheruntergeladen", sentences[0]) |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 318 | assert.Equal("\n", sentences[1]) |
Akron | 1594cb8 | 2021-08-11 11:14:56 +0200 | [diff] [blame] | 319 | |
Akron | 6e70dc8 | 2021-08-11 11:33:18 +0200 | [diff] [blame] | 320 | w.Reset() |
| 321 | assert.True(dat.Transduce(strings.NewReader("Ausschalten!!! Hast Du nicht gehört???"), w)) |
| 322 | sentences = strings.Split(w.String(), "\n\n") |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 323 | assert.Equal(3, len(sentences)) |
Akron | 6e70dc8 | 2021-08-11 11:33:18 +0200 | [diff] [blame] | 324 | assert.Equal("Ausschalten\n!!!", sentences[0]) |
| 325 | assert.Equal("Hast\nDu\nnicht\ngehört\n???", sentences[1]) |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 326 | assert.Equal("\n", sentences[2]) |
Akron | 1594cb8 | 2021-08-11 11:14:56 +0200 | [diff] [blame] | 327 | |
Akron | 4af79f1 | 2021-08-11 14:48:17 +0200 | [diff] [blame] | 328 | w.Reset() |
| 329 | assert.True(dat.Transduce(strings.NewReader("Ich wohne in der Weststr. und Du?"), w)) |
| 330 | sentences = strings.Split(w.String(), "\n\n") |
| 331 | assert.Equal(len(sentences), 2) |
Akron | 1594cb8 | 2021-08-11 11:14:56 +0200 | [diff] [blame] | 332 | |
| 333 | /* |
| 334 | Test: |
| 335 | "\"Ausschalten!!!\", sagte er. \"Hast Du nicht gehört???\""), w)) |
| 336 | */ |
Akron | b7e1f13 | 2021-08-10 11:52:31 +0200 | [diff] [blame] | 337 | } |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 338 | |
Akron | c9c0eae | 2021-10-22 19:49:43 +0200 | [diff] [blame] | 339 | func TestDoubleArrayFullTokenizerTokenSplitter(t *testing.T) { |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 340 | assert := assert.New(t) |
Akron | 9fb63af | 2021-10-28 01:15:53 +0200 | [diff] [blame] | 341 | |
| 342 | if dat == nil { |
| 343 | dat = LoadDatokFile("testdata/tokenizer.datok") |
| 344 | } |
| 345 | |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 346 | assert.NotNil(dat) |
| 347 | |
| 348 | b := make([]byte, 0, 2048) |
| 349 | w := bytes.NewBuffer(b) |
| 350 | var tokens []string |
| 351 | |
| 352 | // testTokenizerSimple |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 353 | tokens = ttokenize(dat, w, "Der alte Mann") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 354 | assert.Equal(tokens[0], "Der") |
| 355 | assert.Equal(tokens[1], "alte") |
| 356 | assert.Equal(tokens[2], "Mann") |
| 357 | assert.Equal(len(tokens), 3) |
| 358 | |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 359 | tokens = ttokenize(dat, w, "Der alte Mann.") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 360 | assert.Equal(tokens[0], "Der") |
| 361 | assert.Equal(tokens[1], "alte") |
| 362 | assert.Equal(tokens[2], "Mann") |
| 363 | assert.Equal(tokens[3], ".") |
| 364 | assert.Equal(len(tokens), 4) |
| 365 | |
| 366 | // testTokenizerAbbr |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 367 | tokens = ttokenize(dat, w, "Der Vorsitzende der F.D.P. hat gewählt") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 368 | assert.Equal(tokens[0], "Der") |
| 369 | assert.Equal(tokens[1], "Vorsitzende") |
| 370 | assert.Equal(tokens[2], "der") |
| 371 | assert.Equal(tokens[3], "F.D.P.") |
| 372 | assert.Equal(tokens[4], "hat") |
| 373 | assert.Equal(tokens[5], "gewählt") |
| 374 | assert.Equal(len(tokens), 6) |
| 375 | // Ignored in KorAP-Tokenizer |
| 376 | |
| 377 | // testTokenizerHost1 |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 378 | tokens = ttokenize(dat, w, "Gefunden auf wikipedia.org") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 379 | assert.Equal(tokens[0], "Gefunden") |
| 380 | assert.Equal(tokens[1], "auf") |
| 381 | assert.Equal(tokens[2], "wikipedia.org") |
| 382 | assert.Equal(len(tokens), 3) |
| 383 | |
| 384 | // testTokenizerWwwHost |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 385 | tokens = ttokenize(dat, w, "Gefunden auf www.wikipedia.org") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 386 | assert.Equal("Gefunden", tokens[0]) |
| 387 | assert.Equal("auf", tokens[1]) |
| 388 | assert.Equal("www.wikipedia.org", tokens[2]) |
| 389 | assert.Equal(3, len(tokens)) |
| 390 | |
| 391 | // testTokenizerWwwUrl |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 392 | tokens = ttokenize(dat, w, "Weitere Infos unter www.info.biz/info") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 393 | assert.Equal("www.info.biz/info", tokens[3]) |
| 394 | |
| 395 | // testTokenizerFtpHost |
| 396 | /* |
| 397 | tokens = tokenize(dat, w, "Kann von ftp.download.org heruntergeladen werden") |
| 398 | assert.Equal("Kann", tokens[0]) |
| 399 | assert.Equal("von", tokens[1]) |
| 400 | assert.Equal("ftp.download.org", tokens[2]) |
| 401 | assert.Equal(5, len(tokens)) |
| 402 | // Ignored in KorAP-Tokenizer |
| 403 | */ |
| 404 | |
| 405 | // testTokenizerDash |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 406 | tokens = ttokenize(dat, w, "Das war -- spitze") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 407 | assert.Equal(tokens[0], "Das") |
| 408 | assert.Equal(tokens[1], "war") |
| 409 | assert.Equal(tokens[2], "--") |
| 410 | assert.Equal(tokens[3], "spitze") |
| 411 | assert.Equal(len(tokens), 4) |
| 412 | |
| 413 | // testTokenizerEmail1 |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 414 | tokens = ttokenize(dat, w, "Ich bin unter korap@ids-mannheim.de erreichbar.") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 415 | assert.Equal(tokens[0], "Ich") |
| 416 | assert.Equal(tokens[1], "bin") |
| 417 | assert.Equal(tokens[2], "unter") |
| 418 | assert.Equal(tokens[3], "korap@ids-mannheim.de") |
| 419 | assert.Equal(tokens[4], "erreichbar") |
| 420 | assert.Equal(tokens[5], ".") |
| 421 | assert.Equal(len(tokens), 6) |
| 422 | |
| 423 | // testTokenizerEmail2 |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 424 | tokens = ttokenize(dat, w, "Oder unter korap[at]ids-mannheim[dot]de.") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 425 | assert.Equal(tokens[0], "Oder") |
| 426 | assert.Equal(tokens[1], "unter") |
| 427 | assert.Equal(tokens[2], "korap[at]ids-mannheim[dot]de") |
| 428 | assert.Equal(tokens[3], ".") |
| 429 | assert.Equal(len(tokens), 4) |
| 430 | |
| 431 | // testTokenizerEmail3 |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 432 | tokens = ttokenize(dat, w, "Oder unter korap(at)ids-mannheim(dot)de.") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 433 | assert.Equal(tokens[0], "Oder") |
| 434 | assert.Equal(tokens[1], "unter") |
| 435 | assert.Equal(tokens[2], "korap(at)ids-mannheim(dot)de") |
| 436 | assert.Equal(tokens[3], ".") |
| 437 | assert.Equal(len(tokens), 4) |
| 438 | // Ignored in KorAP-Tokenizer |
| 439 | |
| 440 | // testTokenizerDoNotAcceptQuotedEmailNames |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 441 | tokens = ttokenize(dat, w, "\"John Doe\"@xx.com") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 442 | assert.Equal("\"", tokens[0]) |
| 443 | assert.Equal("John", tokens[1]) |
| 444 | assert.Equal("Doe", tokens[2]) |
| 445 | assert.Equal("\"", tokens[3]) |
| 446 | assert.Equal("@xx", tokens[4]) |
| 447 | assert.Equal(".", tokens[5]) // Differs - as the sentence splitter splits here! |
| 448 | assert.Equal("com", tokens[6]) |
| 449 | assert.Equal(7, len(tokens)) |
| 450 | |
| 451 | // testTokenizerTwitter |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 452 | tokens = ttokenize(dat, w, "Folgt @korap und #korap") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 453 | assert.Equal(tokens[0], "Folgt") |
| 454 | assert.Equal(tokens[1], "@korap") |
| 455 | assert.Equal(tokens[2], "und") |
| 456 | assert.Equal(tokens[3], "#korap") |
| 457 | assert.Equal(len(tokens), 4) |
| 458 | |
| 459 | // testTokenizerWeb1 |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 460 | tokens = ttokenize(dat, w, "Unsere Website ist https://korap.ids-mannheim.de/?q=Baum") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 461 | assert.Equal(tokens[0], "Unsere") |
| 462 | assert.Equal(tokens[1], "Website") |
| 463 | assert.Equal(tokens[2], "ist") |
| 464 | assert.Equal(tokens[3], "https://korap.ids-mannheim.de/?q=Baum") |
| 465 | assert.Equal(len(tokens), 4) |
| 466 | |
| 467 | // testTokenizerWeb2 |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 468 | tokens = ttokenize(dat, w, "Wir sind auch im Internet (https://korap.ids-mannheim.de/?q=Baum)") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 469 | assert.Equal(tokens[0], "Wir") |
| 470 | assert.Equal(tokens[1], "sind") |
| 471 | assert.Equal(tokens[2], "auch") |
| 472 | assert.Equal(tokens[3], "im") |
| 473 | assert.Equal(tokens[4], "Internet") |
| 474 | assert.Equal(tokens[5], "(") |
| 475 | assert.Equal(tokens[6], "https://korap.ids-mannheim.de/?q=Baum") |
| 476 | assert.Equal(tokens[7], ")") |
| 477 | assert.Equal(len(tokens), 8) |
| 478 | // Ignored in KorAP-Tokenizer |
| 479 | |
| 480 | // testTokenizerWeb3 |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 481 | tokens = ttokenize(dat, w, "Die Adresse ist https://korap.ids-mannheim.de/?q=Baum.") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 482 | assert.Equal(tokens[0], "Die") |
| 483 | assert.Equal(tokens[1], "Adresse") |
| 484 | assert.Equal(tokens[2], "ist") |
| 485 | assert.Equal(tokens[3], "https://korap.ids-mannheim.de/?q=Baum") |
| 486 | assert.Equal(tokens[4], ".") |
| 487 | assert.Equal(len(tokens), 5) |
| 488 | // Ignored in KorAP-Tokenizer |
| 489 | |
| 490 | // testTokenizerServer |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 491 | tokens = ttokenize(dat, w, "Unser Server ist 10.0.10.51.") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 492 | assert.Equal(tokens[0], "Unser") |
| 493 | assert.Equal(tokens[1], "Server") |
| 494 | assert.Equal(tokens[2], "ist") |
| 495 | assert.Equal(tokens[3], "10.0.10.51") |
| 496 | assert.Equal(tokens[4], ".") |
| 497 | assert.Equal(len(tokens), 5) |
| 498 | |
| 499 | // testTokenizerNum |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 500 | tokens = ttokenize(dat, w, "Zu 50,4% ist es sicher") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 501 | assert.Equal(tokens[0], "Zu") |
| 502 | assert.Equal(tokens[1], "50,4%") |
| 503 | assert.Equal(tokens[2], "ist") |
| 504 | assert.Equal(tokens[3], "es") |
| 505 | assert.Equal(tokens[4], "sicher") |
| 506 | assert.Equal(len(tokens), 5) |
| 507 | // Differs from KorAP-Tokenizer |
| 508 | |
| 509 | // testTokenizerDate |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 510 | tokens = ttokenize(dat, w, "Der Termin ist am 5.9.2018") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 511 | assert.Equal(tokens[0], "Der") |
| 512 | assert.Equal(tokens[1], "Termin") |
| 513 | assert.Equal(tokens[2], "ist") |
| 514 | assert.Equal(tokens[3], "am") |
| 515 | assert.Equal(tokens[4], "5.9.2018") |
| 516 | assert.Equal(len(tokens), 5) |
| 517 | |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 518 | tokens = ttokenize(dat, w, "Der Termin ist am 5/9/2018") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 519 | assert.Equal(tokens[0], "Der") |
| 520 | assert.Equal(tokens[1], "Termin") |
| 521 | assert.Equal(tokens[2], "ist") |
| 522 | assert.Equal(tokens[3], "am") |
| 523 | assert.Equal(tokens[4], "5/9/2018") |
| 524 | assert.Equal(len(tokens), 5) |
| 525 | |
| 526 | // testTokenizerDateRange |
| 527 | /* |
| 528 | tokens = tokenize(dat, w, "Der Termin war vom 4.-5.9.2018") |
| 529 | assert.Equal(tokens[0], "Der") |
| 530 | assert.Equal(tokens[1], "Termin") |
| 531 | assert.Equal(tokens[2], "war") |
| 532 | assert.Equal(tokens[3], "vom") |
| 533 | assert.Equal(tokens[4], "4.") |
| 534 | assert.Equal(tokens[5], "-") |
| 535 | assert.Equal(tokens[6], "5.9.2018") |
| 536 | assert.Equal(len(tokens), 7) |
| 537 | // Ignored in KorAP-Tokenizer |
| 538 | */ |
| 539 | |
| 540 | // testTokenizerEmoji1 |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 541 | tokens = ttokenize(dat, w, "Das ist toll! ;)") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 542 | assert.Equal(tokens[0], "Das") |
| 543 | assert.Equal(tokens[1], "ist") |
| 544 | assert.Equal(tokens[2], "toll") |
| 545 | assert.Equal(tokens[3], "!") |
| 546 | assert.Equal(tokens[4], ";)") |
| 547 | assert.Equal(len(tokens), 5) |
| 548 | |
| 549 | // testTokenizerRef1 |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 550 | tokens = ttokenize(dat, w, "Kupietz und Schmidt (2018): Korpuslinguistik") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 551 | assert.Equal(tokens[0], "Kupietz") |
| 552 | assert.Equal(tokens[1], "und") |
| 553 | assert.Equal(tokens[2], "Schmidt") |
| 554 | assert.Equal(tokens[3], "(2018)") |
| 555 | assert.Equal(tokens[4], ":") |
| 556 | assert.Equal(tokens[5], "Korpuslinguistik") |
| 557 | assert.Equal(len(tokens), 6) |
| 558 | // Differs from KorAP-Tokenizer! |
| 559 | |
| 560 | // testTokenizerRef2 () { |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 561 | tokens = ttokenize(dat, w, "Kupietz und Schmidt [2018]: Korpuslinguistik") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 562 | assert.Equal(tokens[0], "Kupietz") |
| 563 | assert.Equal(tokens[1], "und") |
| 564 | assert.Equal(tokens[2], "Schmidt") |
| 565 | assert.Equal(tokens[3], "[2018]") |
| 566 | assert.Equal(tokens[4], ":") |
| 567 | assert.Equal(tokens[5], "Korpuslinguistik") |
| 568 | assert.Equal(len(tokens), 6) |
| 569 | // Differs from KorAP-Tokenizer! |
| 570 | |
| 571 | // testTokenizerOmission1 () { |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 572 | tokens = ttokenize(dat, w, "Er ist ein A****loch!") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 573 | assert.Equal(tokens[0], "Er") |
| 574 | assert.Equal(tokens[1], "ist") |
| 575 | assert.Equal(tokens[2], "ein") |
| 576 | assert.Equal(tokens[3], "A****loch") |
| 577 | assert.Equal(tokens[4], "!") |
| 578 | assert.Equal(len(tokens), 5) |
| 579 | |
| 580 | // testTokenizerOmission2 |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 581 | tokens = ttokenize(dat, w, "F*ck!") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 582 | assert.Equal(tokens[0], "F*ck") |
| 583 | assert.Equal(tokens[1], "!") |
| 584 | assert.Equal(len(tokens), 2) |
| 585 | |
| 586 | // testTokenizerOmission3 () { |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 587 | tokens = ttokenize(dat, w, "Dieses verf***** Kleid!") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 588 | assert.Equal(tokens[0], "Dieses") |
| 589 | assert.Equal(tokens[1], "verf*****") |
| 590 | assert.Equal(tokens[2], "Kleid") |
| 591 | assert.Equal(tokens[3], "!") |
| 592 | assert.Equal(len(tokens), 4) |
| 593 | |
| 594 | // Probably interpreted as HOST |
| 595 | // testTokenizerFileExtension1 |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 596 | tokens = ttokenize(dat, w, "Ich habe die readme.txt heruntergeladen") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 597 | assert.Equal(tokens[0], "Ich") |
| 598 | assert.Equal(tokens[1], "habe") |
| 599 | assert.Equal(tokens[2], "die") |
| 600 | assert.Equal(tokens[3], "readme.txt") |
| 601 | assert.Equal(tokens[4], "heruntergeladen") |
| 602 | assert.Equal(len(tokens), 5) |
| 603 | |
| 604 | // Probably interpreted as HOST |
| 605 | // testTokenizerFileExtension2 |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 606 | tokens = ttokenize(dat, w, "Nimm die README.TXT!") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 607 | assert.Equal(tokens[0], "Nimm") |
| 608 | assert.Equal(tokens[1], "die") |
| 609 | assert.Equal(tokens[2], "README.TXT") |
| 610 | assert.Equal(tokens[3], "!") |
| 611 | assert.Equal(len(tokens), 4) |
| 612 | |
| 613 | // Probably interpreted as HOST |
| 614 | // testTokenizerFileExtension3 |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 615 | tokens = ttokenize(dat, w, "Zeig mir profile.jpeg") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 616 | assert.Equal(tokens[0], "Zeig") |
| 617 | assert.Equal(tokens[1], "mir") |
| 618 | assert.Equal(tokens[2], "profile.jpeg") |
| 619 | assert.Equal(len(tokens), 3) |
| 620 | |
| 621 | // testTokenizerFile1 |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 622 | |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 623 | tokens = ttokenize(dat, w, "Zeig mir c:\\Dokumente\\profile.docx") |
Akron | e8837b5 | 2021-08-11 17:29:58 +0200 | [diff] [blame] | 624 | assert.Equal(tokens[0], "Zeig") |
| 625 | assert.Equal(tokens[1], "mir") |
| 626 | assert.Equal(tokens[2], "c:\\Dokumente\\profile.docx") |
| 627 | assert.Equal(len(tokens), 3) |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 628 | |
Akron | e8837b5 | 2021-08-11 17:29:58 +0200 | [diff] [blame] | 629 | // testTokenizerFile2 |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 630 | tokens = ttokenize(dat, w, "Gehe zu /Dokumente/profile.docx") |
Akron | e8837b5 | 2021-08-11 17:29:58 +0200 | [diff] [blame] | 631 | assert.Equal(tokens[0], "Gehe") |
| 632 | assert.Equal(tokens[1], "zu") |
| 633 | assert.Equal(tokens[2], "/Dokumente/profile.docx") |
| 634 | assert.Equal(len(tokens), 3) |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 635 | |
Akron | e8837b5 | 2021-08-11 17:29:58 +0200 | [diff] [blame] | 636 | // testTokenizerFile3 |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 637 | tokens = ttokenize(dat, w, "Zeig mir c:\\Dokumente\\profile.jpeg") |
Akron | e8837b5 | 2021-08-11 17:29:58 +0200 | [diff] [blame] | 638 | assert.Equal(tokens[0], "Zeig") |
| 639 | assert.Equal(tokens[1], "mir") |
| 640 | assert.Equal(tokens[2], "c:\\Dokumente\\profile.jpeg") |
| 641 | assert.Equal(len(tokens), 3) |
| 642 | // Ignored in KorAP-Tokenizer |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 643 | |
Akron | fd92d7e | 2021-08-11 16:31:43 +0200 | [diff] [blame] | 644 | // testTokenizerPunct |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 645 | tokens = ttokenize(dat, w, "Er sagte: \"Es geht mir gut!\", daraufhin ging er.") |
Akron | fd92d7e | 2021-08-11 16:31:43 +0200 | [diff] [blame] | 646 | assert.Equal(tokens[0], "Er") |
| 647 | assert.Equal(tokens[1], "sagte") |
| 648 | assert.Equal(tokens[2], ":") |
| 649 | assert.Equal(tokens[3], "\"") |
| 650 | assert.Equal(tokens[4], "Es") |
| 651 | assert.Equal(tokens[5], "geht") |
| 652 | assert.Equal(tokens[6], "mir") |
| 653 | assert.Equal(tokens[7], "gut") |
| 654 | assert.Equal(tokens[8], "!") |
| 655 | assert.Equal(tokens[9], "\"") |
| 656 | assert.Equal(tokens[10], ",") |
| 657 | assert.Equal(tokens[11], "daraufhin") |
| 658 | assert.Equal(tokens[12], "ging") |
| 659 | assert.Equal(tokens[13], "er") |
| 660 | assert.Equal(tokens[14], ".") |
| 661 | assert.Equal(len(tokens), 15) |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 662 | |
| 663 | // testTokenizerPlusAmpersand |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 664 | tokens = ttokenize(dat, w, ""Das ist von C&A!"") |
| 665 | assert.Equal(tokens[0], """) |
| 666 | assert.Equal(tokens[1], "Das") |
| 667 | assert.Equal(tokens[2], "ist") |
| 668 | assert.Equal(tokens[3], "von") |
| 669 | assert.Equal(tokens[4], "C&A") |
| 670 | assert.Equal(tokens[5], "!") |
| 671 | assert.Equal(tokens[6], """) |
| 672 | assert.Equal(len(tokens), 7) |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 673 | |
| 674 | // testTokenizerLongEnd |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 675 | tokens = ttokenize(dat, w, "Siehst Du?!!?") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 676 | assert.Equal(tokens[0], "Siehst") |
| 677 | assert.Equal(tokens[1], "Du") |
| 678 | assert.Equal(tokens[2], "?!!?") |
| 679 | assert.Equal(len(tokens), 3) |
| 680 | |
| 681 | // testTokenizerIrishO |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 682 | tokens = ttokenize(dat, w, "Peter O'Toole") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 683 | assert.Equal(tokens[0], "Peter") |
| 684 | assert.Equal(tokens[1], "O'Toole") |
| 685 | assert.Equal(len(tokens), 2) |
| 686 | |
| 687 | // testTokenizerAbr |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 688 | tokens = ttokenize(dat, w, "Früher bzw. später ...") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 689 | assert.Equal(tokens[0], "Früher") |
| 690 | assert.Equal(tokens[1], "bzw.") |
| 691 | assert.Equal(tokens[2], "später") |
| 692 | assert.Equal(tokens[3], "...") |
| 693 | assert.Equal(len(tokens), 4) |
| 694 | |
| 695 | // testTokenizerUppercaseRule |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 696 | tokens = ttokenize(dat, w, "Es war spät.Morgen ist es früh.") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 697 | assert.Equal(tokens[0], "Es") |
| 698 | assert.Equal(tokens[1], "war") |
| 699 | assert.Equal(tokens[2], "spät") |
| 700 | assert.Equal(tokens[3], ".") |
| 701 | assert.Equal(tokens[4], "Morgen") |
| 702 | assert.Equal(tokens[5], "ist") |
| 703 | assert.Equal(tokens[6], "es") |
| 704 | assert.Equal(tokens[7], "früh") |
| 705 | assert.Equal(tokens[8], ".") |
| 706 | assert.Equal(len(tokens), 9) |
| 707 | // Ignored in KorAP-Tokenizer |
| 708 | |
| 709 | // testTokenizerOrd |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 710 | tokens = ttokenize(dat, w, "Sie erreichte den 1. Platz!") |
Akron | a0bded5 | 2021-08-11 15:48:02 +0200 | [diff] [blame] | 711 | assert.Equal(tokens[0], "Sie") |
| 712 | assert.Equal(tokens[1], "erreichte") |
| 713 | assert.Equal(tokens[2], "den") |
| 714 | assert.Equal(tokens[3], "1.") |
| 715 | assert.Equal(tokens[4], "Platz") |
| 716 | assert.Equal(tokens[5], "!") |
| 717 | assert.Equal(len(tokens), 6) |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 718 | |
| 719 | // testNoZipOuputArchive |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 720 | tokens = ttokenize(dat, w, "Archive: Ich bin kein zip\n") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 721 | assert.Equal(tokens[0], "Archive") |
| 722 | assert.Equal(tokens[1], ":") |
| 723 | assert.Equal(tokens[2], "Ich") |
| 724 | assert.Equal(tokens[3], "bin") |
| 725 | assert.Equal(tokens[4], "kein") |
| 726 | assert.Equal(tokens[5], "zip") |
| 727 | assert.Equal(6, len(tokens)) |
| 728 | |
| 729 | // testTokenizerStrasse |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 730 | tokens = ttokenize(dat, w, "Ich wohne in der Weststr. und Du?") |
Akron | 4af79f1 | 2021-08-11 14:48:17 +0200 | [diff] [blame] | 731 | assert.Equal(tokens[4], "Weststr.") |
| 732 | assert.Equal(8, len(tokens)) |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 733 | |
| 734 | // germanTokenizerKnowsGermanOmissionWords |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 735 | tokens = ttokenize(dat, w, "D'dorf Ku'damm Lu'hafen M'gladbach W'schaft") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 736 | assert.Equal("D'dorf", tokens[0]) |
| 737 | assert.Equal("Ku'damm", tokens[1]) |
| 738 | assert.Equal("Lu'hafen", tokens[2]) |
| 739 | assert.Equal("M'gladbach", tokens[3]) |
| 740 | assert.Equal("W'schaft", tokens[4]) |
| 741 | assert.Equal(5, len(tokens)) |
| 742 | |
| 743 | // germanTokenizerDoesNOTSeparateGermanContractions |
Akron | ec835ad | 2021-08-11 18:23:22 +0200 | [diff] [blame] | 744 | tokens = ttokenize(dat, w, "mach's macht's was'n ist's haste willste kannste biste kriegste") |
Akron | 03ca425 | 2021-08-11 13:32:53 +0200 | [diff] [blame] | 745 | assert.Equal("mach's", tokens[0]) |
| 746 | assert.Equal("macht's", tokens[1]) |
| 747 | assert.Equal("was'n", tokens[2]) |
| 748 | assert.Equal("ist's", tokens[3]) |
| 749 | assert.Equal("haste", tokens[4]) |
| 750 | assert.Equal("willste", tokens[5]) |
| 751 | assert.Equal("kannste", tokens[6]) |
| 752 | assert.Equal("biste", tokens[7]) |
| 753 | assert.Equal("kriegste", tokens[8]) |
| 754 | assert.Equal(9, len(tokens)) |
| 755 | |
| 756 | /* |
| 757 | @Test |
| 758 | public void englishTokenizerSeparatesEnglishContractionsAndClitics () { |
| 759 | DerekoDfaTokenizer_en tok = new DerekoDfaTokenizer_en(); |
| 760 | tokens = tokenize(dat, w, "I've we'll you'd I'm we're Peter's isn't") |
| 761 | assert.Equal("'ve", tokens[1]); |
| 762 | assert.Equal("'ll", tokens[3]); |
| 763 | assert.Equal("'d", tokens[5]); |
| 764 | assert.Equal("'m", tokens[7]); |
| 765 | assert.Equal("'re", tokens[9]); |
| 766 | assert.Equal("'s", tokens[11]); |
| 767 | assert.Equal("is", tokens[12]); |
| 768 | assert.Equal("n't", tokens[13]); |
| 769 | assert.Equal(14, len(tokens)); |
| 770 | } |
| 771 | |
| 772 | @Test |
| 773 | public void frenchTokenizerKnowsFrenchAbbreviations () { |
| 774 | DerekoDfaTokenizer_fr tok = new DerekoDfaTokenizer_fr(); |
| 775 | tokens = tokenize(dat, w, "Approx. en juill. 2004 mon prof. M. Foux m'a dit qu'il faut faire exerc. no. 4, et lire pp. 27-30.") |
| 776 | assert.Equal("Approx.", tokens[0]); |
| 777 | assert.Equal("juill.", tokens[2]); |
| 778 | assert.Equal("prof.", tokens[5]); |
| 779 | assert.Equal("exerc.", tokens[15]); |
| 780 | assert.Equal("no.", tokens[16]); |
| 781 | assert.Equal("pp.", tokens[21]); |
| 782 | } |
| 783 | |
| 784 | @Test |
| 785 | public void frenchTokenizerKnowsFrenchContractions () { |
| 786 | DerekoDfaTokenizer_fr tok = new DerekoDfaTokenizer_fr(); |
| 787 | tokens = tokenize(dat, w, "J'ai j'habite qu'il d'un jusqu'à Aujourd'hui D'accord Quelqu'un Presqu'île") |
| 788 | assert.Equal("J'", tokens[0]); |
| 789 | assert.Equal("j'", tokens[2]); |
| 790 | assert.Equal("qu'", tokens[4]); |
| 791 | assert.Equal("d'", tokens[6]); |
| 792 | assert.Equal("jusqu'", tokens[8]); |
| 793 | assert.Equal("Aujourd'hui", tokens[10]); |
| 794 | assert.Equal("D'", tokens[11]); // ’ |
| 795 | assert.Equal("Quelqu'un", tokens[13]); // ’ |
| 796 | assert.Equal("Presqu'île", tokens[14]); // ’ |
| 797 | } |
| 798 | |
| 799 | @Test |
| 800 | public void frenchTokenizerKnowsFrenchClitics () { |
| 801 | DerekoDfaTokenizer_fr tok = new DerekoDfaTokenizer_fr(); |
| 802 | tokens = tokenize(dat, w, "suis-je sont-elles ") |
| 803 | assert.Equal("suis", tokens[0]); |
| 804 | assert.Equal("-je", tokens[1]); |
| 805 | assert.Equal("sont", tokens[2]); |
| 806 | assert.Equal("-elles", tokens[3]); |
| 807 | } |
| 808 | |
| 809 | @Test |
| 810 | public void testEnglishTokenizerScienceAbbreviations () { |
| 811 | DerekoDfaTokenizer_en tok = new DerekoDfaTokenizer_en(); |
| 812 | tokens = tokenize(dat, w, "Approx. in Sept. 1954, Assoc. Prof. Dr. R. J. Ewing reviewed articles on Enzymol. Bacteriol. effects later published in Nutr. Rheumatol. No. 12 and Nº. 13., pp. 17-18.") |
| 813 | assert.Equal("Approx.", tokens[0]); |
| 814 | assert.Equal("in", tokens[1]); |
| 815 | assert.Equal("Sept.", tokens[2]); |
| 816 | assert.Equal("1954", tokens[3]); |
| 817 | assert.Equal(",", tokens[4]); |
| 818 | assert.Equal("Assoc.", tokens[5]); |
| 819 | assert.Equal("Prof.", tokens[6]); |
| 820 | assert.Equal("Dr.", tokens[7]); |
| 821 | assert.Equal("R.", tokens[8]); |
| 822 | assert.Equal("J.", tokens[9]); |
| 823 | assert.Equal("Ewing", tokens[10]); |
| 824 | assert.Equal("reviewed", tokens[11]); |
| 825 | assert.Equal("articles", tokens[12]); |
| 826 | assert.Equal("on", tokens[13]); |
| 827 | assert.Equal("Enzymol.", tokens[14]); |
| 828 | assert.Equal("Bacteriol.", tokens[15]); |
| 829 | assert.Equal("effects", tokens[16]); |
| 830 | assert.Equal("later", tokens[17]); |
| 831 | assert.Equal("published", tokens[18]); |
| 832 | assert.Equal("in", tokens[19]); |
| 833 | assert.Equal("Nutr.", tokens[20]); |
| 834 | assert.Equal("Rheumatol.", tokens[21]); |
| 835 | assert.Equal("No.", tokens[22]); |
| 836 | assert.Equal("12", tokens[23]); |
| 837 | assert.Equal("and", tokens[24]); |
| 838 | assert.Equal("Nº.", tokens[25]); |
| 839 | assert.Equal("13.", tokens[26]); |
| 840 | assert.Equal(",", tokens[27]); |
| 841 | assert.Equal("pp.", tokens[28]); |
| 842 | assert.Equal("17-18", tokens[29]); |
| 843 | assert.Equal(".", tokens[30]); |
| 844 | } |
| 845 | |
| 846 | @Test |
| 847 | public void englishTokenizerCanGuessWhetherIIsAbbrev () { |
| 848 | DerekoDfaTokenizer_en tok = new DerekoDfaTokenizer_en(); |
| 849 | tokens = tokenize(dat, w, "M. I. Baxter was born during World War I. So was I. He went to the Peter I. Hardy school. So did I.") |
| 850 | assert.Equal("I.", tokens[1]); |
| 851 | assert.Equal("I", tokens[8]); |
| 852 | assert.Equal(".", tokens[9]); |
| 853 | assert.Equal("I", tokens[12]); |
| 854 | assert.Equal(".", tokens[13]); |
| 855 | } |
| 856 | |
| 857 | @Test |
| 858 | public void testZipOuputArchive () { |
| 859 | |
| 860 | final ByteArrayOutputStream clearOut = new ByteArrayOutputStream(); |
| 861 | System.setOut(new PrintStream(clearOut)); |
| 862 | tokens = tokenize(dat, w, "Archive: ich/bin/ein.zip\n") |
| 863 | assert.Equal(0, len(tokens)); |
| 864 | } |
| 865 | */ |
| 866 | /* |
| 867 | |
| 868 | @Test |
| 869 | public void testTextBreakOutputArchive () throws InstantiationException, IllegalAccessException, ClassNotFoundException { |
| 870 | DerekoDfaTokenizer_de tok = (DerekoDfaTokenizer_de) new KorapTokenizer.Builder() |
| 871 | .tokenizerClassName(DerekoDfaTokenizer_de.class.getName()) |
| 872 | .printOffsets(true) |
| 873 | .build(); |
| 874 | Span[] tokens = tok.tokenizePos("Text1\004\nText2 Hallo\004Rumsdibums\004Das freut mich sehr.\n"); |
| 875 | assert.Equal("Text1", tokens[0].getType()); |
| 876 | assert.Equal(len(tokens), 9 ); |
| 877 | } |
| 878 | */ |
| 879 | } |
Akron | bd40680 | 2021-08-11 18:39:13 +0200 | [diff] [blame] | 880 | |
Akron | c9c0eae | 2021-10-22 19:49:43 +0200 | [diff] [blame] | 881 | func TestDoubleArrayLoadFactor1(t *testing.T) { |
Akron | 29e306f | 2021-09-02 18:29:56 +0200 | [diff] [blame] | 882 | assert := assert.New(t) |
| 883 | tok := LoadFomaFile("testdata/abbr_bench.fst") |
| 884 | dat := tok.ToDoubleArray() |
| 885 | assert.True(dat.LoadFactor() > 88) |
| 886 | } |
| 887 | |
Akron | c9c0eae | 2021-10-22 19:49:43 +0200 | [diff] [blame] | 888 | func TestDoubleArrayFullTokenizerXML(t *testing.T) { |
Akron | 4c2a1ad | 2021-08-31 00:35:53 +0200 | [diff] [blame] | 889 | assert := assert.New(t) |
| 890 | |
Akron | 9fb63af | 2021-10-28 01:15:53 +0200 | [diff] [blame] | 891 | if dat == nil { |
| 892 | dat = LoadDatokFile("testdata/tokenizer.datok") |
| 893 | } |
| 894 | |
Akron | 4c2a1ad | 2021-08-31 00:35:53 +0200 | [diff] [blame] | 895 | assert.NotNil(dat) |
| 896 | |
| 897 | b := make([]byte, 0, 2048) |
| 898 | w := bytes.NewBuffer(b) |
| 899 | var tokens []string |
| 900 | |
| 901 | tokens = ttokenize(dat, w, "Das <b>beste</b> Fußballspiel") |
| 902 | assert.Equal("Das", tokens[0]) |
| 903 | assert.Equal("<b>", tokens[1]) |
| 904 | assert.Equal("beste", tokens[2]) |
| 905 | assert.Equal("</b>", tokens[3]) |
| 906 | assert.Equal("Fußballspiel", tokens[4]) |
| 907 | assert.Equal(5, len(tokens)) |
| 908 | |
| 909 | tokens = ttokenize(dat, w, "Das <b class=\"c\">beste</b> Fußballspiel") |
| 910 | assert.Equal("Das", tokens[0]) |
| 911 | assert.Equal("<b class=\"c\">", tokens[1]) |
| 912 | assert.Equal("beste", tokens[2]) |
| 913 | assert.Equal("</b>", tokens[3]) |
| 914 | assert.Equal("Fußballspiel", tokens[4]) |
| 915 | assert.Equal(5, len(tokens)) |
| 916 | |
| 917 | tokens = ttokenize(dat, w, "der<x y=\"alte \"> <x x> alte</x> etc. et. Mann.") |
| 918 | assert.Equal("der", tokens[0]) |
| 919 | assert.Equal("<x y=\"alte \">", tokens[1]) |
| 920 | assert.Equal("<x x>", tokens[2]) |
| 921 | assert.Equal("alte", tokens[3]) |
| 922 | assert.Equal("</x>", tokens[4]) |
| 923 | assert.Equal("etc.", tokens[5]) |
| 924 | assert.Equal("et", tokens[6]) |
| 925 | assert.Equal(".", tokens[7]) |
| 926 | assert.Equal("Mann", tokens[8]) |
| 927 | assert.Equal(".", tokens[9]) |
| 928 | assert.Equal(10, len(tokens)) |
| 929 | } |
| 930 | |
Akron | c9c0eae | 2021-10-22 19:49:43 +0200 | [diff] [blame] | 931 | func BenchmarkDoubleArrayTransduce(b *testing.B) { |
Akron | bd40680 | 2021-08-11 18:39:13 +0200 | [diff] [blame] | 932 | bu := make([]byte, 0, 2048) |
| 933 | w := bytes.NewBuffer(bu) |
| 934 | |
| 935 | s := `Der Vorsitzende der Abk. hat gewählt. Gefunden auf wikipedia.org. Ich bin unter korap@ids-mannheim.de erreichbar. |
| 936 | Unsere Website ist https://korap.ids-mannheim.de/?q=Baum. Unser Server ist 10.0.10.51. Zu 50.4% ist es sicher. |
| 937 | Der Termin ist am 5.9.2018. |
| 938 | Ich habe die readme.txt heruntergeladen. |
| 939 | Ausschalten!!! Hast Du nicht gehört??? |
| 940 | Ich wohne in der Weststr. und Du? Kupietz und Schmidt [2018]: Korpuslinguistik. Dieses verf***** Kleid! Ich habe die readme.txt heruntergeladen. |
| 941 | Er sagte: \"Es geht mir gut!\", daraufhin ging er. "Das ist von C&A!" Früher bzw. später ... Sie erreichte den 1. Platz! |
| 942 | Archive: Ich bin kein zip. D'dorf Ku'damm Lu'hafen M'gladbach W'schaft. |
| 943 | Mach's macht's was'n ist's haste willste kannste biste kriegste.` |
| 944 | r := strings.NewReader(s) |
| 945 | |
| 946 | dat := LoadDatokFile("testdata/tokenizer.datok") |
| 947 | |
Akron | df37a55 | 2021-09-02 12:16:08 +0200 | [diff] [blame] | 948 | b.ResetTimer() |
| 949 | |
Akron | bd40680 | 2021-08-11 18:39:13 +0200 | [diff] [blame] | 950 | for i := 0; i < b.N; i++ { |
| 951 | w.Reset() |
| 952 | r.Reset(s) |
| 953 | ok := dat.Transduce(r, w) |
| 954 | if !ok { |
| 955 | fmt.Println("Fail!") |
| 956 | fmt.Println(w.String()) |
| 957 | os.Exit(1) |
| 958 | } |
| 959 | } |
Akron | bd40680 | 2021-08-11 18:39:13 +0200 | [diff] [blame] | 960 | } |
Akron | bb4aac5 | 2021-08-13 00:52:27 +0200 | [diff] [blame] | 961 | |
Akron | 6f1c16c | 2021-08-17 10:45:42 +0200 | [diff] [blame] | 962 | // This test is deprecated as the datok file changes over time |
| 963 | func XBenchmarkLoadDatokFile(b *testing.B) { |
Akron | bb4aac5 | 2021-08-13 00:52:27 +0200 | [diff] [blame] | 964 | for i := 0; i < b.N; i++ { |
| 965 | dat := LoadDatokFile("testdata/tokenizer.datok") |
| 966 | if dat == nil { |
| 967 | fmt.Println("Fail!") |
| 968 | os.Exit(1) |
| 969 | } |
| 970 | } |
| 971 | } |
| 972 | |
Akron | c9c0eae | 2021-10-22 19:49:43 +0200 | [diff] [blame] | 973 | func BenchmarkDoubleArrayConstruction(b *testing.B) { |
Akron | 6f1c16c | 2021-08-17 10:45:42 +0200 | [diff] [blame] | 974 | tok := LoadFomaFile("testdata/simple_bench.fst") |
Akron | df37a55 | 2021-09-02 12:16:08 +0200 | [diff] [blame] | 975 | b.ResetTimer() |
Akron | 6f1c16c | 2021-08-17 10:45:42 +0200 | [diff] [blame] | 976 | for i := 0; i < b.N; i++ { |
| 977 | dat := tok.ToDoubleArray() |
| 978 | if dat == nil { |
| 979 | fmt.Println("Fail!") |
| 980 | os.Exit(1) |
| 981 | } |
| 982 | } |
| 983 | } |
| 984 | |
Akron | c9c0eae | 2021-10-22 19:49:43 +0200 | [diff] [blame] | 985 | func BenchmarkDoubleArrayLarger(b *testing.B) { |
Akron | 7b1faa6 | 2021-09-02 16:10:21 +0200 | [diff] [blame] | 986 | tok := LoadFomaFile("testdata/abbr_bench.fst") |
| 987 | b.ResetTimer() |
| 988 | for i := 0; i < b.N; i++ { |
| 989 | dat := tok.ToDoubleArray() |
| 990 | if dat == nil { |
| 991 | fmt.Println("Fail!") |
| 992 | os.Exit(1) |
| 993 | } |
| 994 | } |
| 995 | } |
| 996 | |
Akron | bb4aac5 | 2021-08-13 00:52:27 +0200 | [diff] [blame] | 997 | // 2021-08-11 (go 1.16) |
| 998 | // go test -bench=. -test.benchmem |
| 999 | // BenchmarkTransduce-4 19069 60609 ns/op 11048 B/op 137 allocs/op |
Akron | f1a1650 | 2021-08-16 15:24:38 +0200 | [diff] [blame] | 1000 | // 2021-08-12 (go 1.16) |
Akron | bb4aac5 | 2021-08-13 00:52:27 +0200 | [diff] [blame] | 1001 | // BenchmarkTransduce-4 20833 55241 ns/op 9676 B/op 3 allocs/op |
| 1002 | // BenchmarkLoadDatokFile-4 4 258418169 ns/op 29916470 B/op 5697 allocs/op |
| 1003 | // BenchmarkTransduce-4 19430 58133 ns/op 18696 B/op 3 allocs/op |
| 1004 | // BenchmarkLoadDatokFile-4 8 139071939 ns/op 203158377 B/op 5742 allocs/op |
Akron | f1a1650 | 2021-08-16 15:24:38 +0200 | [diff] [blame] | 1005 | // 2021-08-16 |
| 1006 | // BenchmarkTransduce-4 22251 49989 ns/op 17370 B/op 3 allocs/op |
| 1007 | // BenchmarkLoadDatokFile-4 8 138937532 ns/op 203158327 B/op 5742 allocs/op |
| 1008 | // BenchmarkTransduce-4 22005 48665 ns/op 17472 B/op 3 allocs/op |
| 1009 | // BenchmarkLoadDatokFile-4 7 143143934 ns/op 203158450 B/op 5743 allocs/op |
Akron | ea46e8a | 2021-08-17 00:36:31 +0200 | [diff] [blame] | 1010 | // BenchmarkTransduce-4 34939 34363 ns/op 14056 B/op 3 allocs/op |
| 1011 | // BenchmarkLoadDatokFile-4 7 149511609 ns/op 203217193 B/op 5915 allocs/op |
Akron | 6f1c16c | 2021-08-17 10:45:42 +0200 | [diff] [blame] | 1012 | // 2021-08-17 |
| 1013 | // BenchmarkTransduce-4 31204 32678 ns/op 14752 B/op 3 allocs/op |
| 1014 | // BenchmarkToDoubleArray-4 44138 26850 ns/op 10704 B/op 29 allocs/op |
Akron | de18e90 | 2021-08-27 09:34:12 +0200 | [diff] [blame] | 1015 | // BenchmarkTransduce-4 29376 34562 ns/op 15157 B/op 3 allocs/op |
| 1016 | // BenchmarkToDoubleArray-4 54441 21355 ns/op 10704 B/op 29 allocs/op |
Akron | df37a55 | 2021-09-02 12:16:08 +0200 | [diff] [blame] | 1017 | // 2021-09-02 - New tokenizer - fixed loading |
Akron | 7b1faa6 | 2021-09-02 16:10:21 +0200 | [diff] [blame] | 1018 | // BenchmarkTransduce-4 40149 31515 ns/op 8240 B/op 3 allocs/op |
| 1019 | // BenchmarkToDoubleArray-4 51043 22586 ns/op 10702 B/op 29 allocs/op |
| 1020 | // BenchmarkToDoubleArrayLarger-4 3 396009639 ns/op 6352293 B/op 2575 allocs/op |
| 1021 | // BenchmarkTransduce-4 38698 31900 ns/op 8240 B/op 3 allocs/op |
| 1022 | // BenchmarkToDoubleArray-4 50644 21569 ns/op 11151 B/op 14 allocs/op |
| 1023 | // BenchmarkToDoubleArrayLarger-4 3 441260766 ns/op 6942336 B/op 30 allocs/op |
| 1024 | // BenchmarkTransduce-4 39966 30835 ns/op 8240 B/op 3 allocs/op |
| 1025 | // BenchmarkToDoubleArray-4 50720 24863 ns/op 11091 B/op 46 allocs/op |
| 1026 | // BenchmarkToDoubleArrayLarger-4 3 432523828 ns/op 6413381 B/op 5122 allocs/op |
Akron | 679b486 | 2021-09-02 16:59:26 +0200 | [diff] [blame] | 1027 | // 2021-09-02 - xCheckSkip() with .9 |
| 1028 | // BenchmarkTransduce-4 36325 38501 ns/op 8240 B/op 3 allocs/op |
| 1029 | // BenchmarkToDoubleArray-4 66858 19286 ns/op 10607 B/op 29 allocs/op |
| 1030 | // BenchmarkToDoubleArrayLarger-4 18 67428011 ns/op 6360604 B/op 2578 allocs/op |
Akron | 29e306f | 2021-09-02 18:29:56 +0200 | [diff] [blame] | 1031 | // 2021-09-02 - xCheckSkipNiu() with .9 and >= 3 |
| 1032 | // BenchmarkTransduce-4 37105 27714 ns/op 8240 B/op 3 allocs/op |
| 1033 | // BenchmarkToDoubleArray-4 76600 15973 ns/op 10703 B/op 29 allocs/op |
| 1034 | // BenchmarkToDoubleArrayLarger-4 21 55161934 ns/op 6357889 B/op 2578 allocs/op |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 1035 | // 2021-09-30 - Go 1.17.1 |
| 1036 | // BenchmarkTransduce-4 47222 25962 ns/op 8240 B/op 3 allocs/op |
| 1037 | // BenchmarkToDoubleArray-4 69192 17355 ns/op 10704 B/op 29 allocs/op |
| 1038 | // BenchmarkToDoubleArrayLarger-4 16 65042885 ns/op 6357794 B/op 2576 allocs/op |
| 1039 | // BenchmarkTransduceMatrix-4 45404 25156 ns/op 8240 B/op 3 allocs/op |
Akron | 094a4e8 | 2021-10-02 18:37:00 +0200 | [diff] [blame] | 1040 | // 2021-10-02 |
| 1041 | // BenchmarkTransduce-4 47676 25398 ns/op 8240 B/op 3 allocs/op |
| 1042 | // BenchmarkToDoubleArray-4 71919 16083 ns/op 10702 B/op 29 allocs/op |
| 1043 | // BenchmarkToDoubleArrayLarger-4 16 68012819 ns/op 6357920 B/op 2578 allocs/op |
| 1044 | // BenchmarkTransduceMatrix-4 51529 23678 ns/op 8240 B/op 3 allocs/op |
Akron | e396a93 | 2021-10-19 01:06:13 +0200 | [diff] [blame] | 1045 | // 2021-10-12 - Introduction of Callbacks in Matrix |
| 1046 | // BenchmarkTransduce-4 46947 26043 ns/op 8240 B/op 3 allocs/op |
| 1047 | // BenchmarkToDoubleArray-4 65192 16501 ns/op 10703 B/op 29 allocs/op |
| 1048 | // BenchmarkToDoubleArrayLarger-4 15 69263576 ns/op 6357859 B/op 2577 allocs/op |
| 1049 | // BenchmarkTransduceMatrix-4 49928 26313 ns/op 12408 B/op 6 allocs/op |
| 1050 | // 2021-10-18 - Introduction of Callbacks in DA |
| 1051 | // BenchmarkTransduce-4 41055 30058 ns/op 12408 B/op 6 allocs/op |
| 1052 | // BenchmarkToDoubleArray-4 64672 17659 ns/op 10703 B/op 29 allocs/op |
| 1053 | // BenchmarkToDoubleArrayLarger-4 15 71640553 ns/op 6357865 B/op 2577 allocs/op |
| 1054 | // BenchmarkTransduceMatrix-4 47036 26009 ns/op 12408 B/op 6 allocs/op |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 1055 | // 2021-10-21 - Simplify DA code to ignore final states |
| 1056 | // BenchmarkTransduce-4 41365 33766 ns/op 12408 B/op 6 allocs/op |
| 1057 | // BenchmarkToDoubleArray-4 63663 17675 ns/op 10703 B/op 29 allocs/op |
| 1058 | // BenchmarkToDoubleArrayLarger-4 16 83535733 ns/op 6357874 B/op 2577 allocs/op |
| 1059 | // BenchmarkTransduceMatrix-4 45362 25258 ns/op 12408 B/op 6 allocs/op |
Akron | 98fbfef | 2021-10-23 17:02:11 +0200 | [diff] [blame] | 1060 | // 2021-10-22 - Introduxe EOT |
Akron | c9c0eae | 2021-10-22 19:49:43 +0200 | [diff] [blame] | 1061 | // BenchmarkDoubleArrayTransduce-4 43820 27661 ns/op 12408 B/op 6 allocs/op |
| 1062 | // BenchmarkDoubleArrayConstruction-4 68259 16608 ns/op 10703 B/op 29 allocs/op |
| 1063 | // BenchmarkDoubleArrayLarger-4 16 69889532 ns/op 6357901 B/op 2578 allocs/op |
| 1064 | // BenchmarkMatrixTransduce-4 49426 25105 ns/op 12408 B/op 6 allocs/op |
Akron | 98fbfef | 2021-10-23 17:02:11 +0200 | [diff] [blame] | 1065 | // 2021-10-23 - Improve offset handling |
| 1066 | // BenchmarkDoubleArrayTransduce-4 41890 29729 ns/op 12408 B/op 6 allocs/op |
| 1067 | // BenchmarkDoubleArrayConstruction-4 74510 15879 ns/op 10703 B/op 29 allocs/op |
| 1068 | // BenchmarkDoubleArrayLarger-4 18 73752383 ns/op 6357956 B/op 2579 allocs/op |
| 1069 | // BenchmarkMatrixTransduce-4 46870 27140 ns/op 12408 B/op 6 allocs/op |
Akron | 04335c6 | 2021-10-28 11:56:00 +0200 | [diff] [blame] | 1070 | // 2021-10-28 - Finalize feature compatibility with KorAP-Tokenizer |
| 1071 | // BenchmarkDoubleArrayTransduce-4 39130 31612 ns/op 28944 B/op 16 allocs/op |
| 1072 | // BenchmarkDoubleArrayConstruction-4 79302 14994 ns/op 10703 B/op 29 allocs/op |
| 1073 | // BenchmarkDoubleArrayLarger-4 18 67942077 ns/op 6357870 B/op 2577 allocs/op |
| 1074 | // BenchmarkMatrixTransduce-4 39536 30510 ns/op 28944 B/op 16 allocs/op |
Akron | 289414f | 2021-11-09 19:56:42 +0100 | [diff] [blame] | 1075 | // 2021-11-09 - go 1.17.3 |
| 1076 | // BenchmarkDoubleArrayTransduce-4 35067 34192 ns/op 28944 B/op 17 allocs/op |
| 1077 | // BenchmarkDoubleArrayConstruction-4 72446 15614 ns/op 10703 B/op 29 allocs/op |
| 1078 | // BenchmarkDoubleArrayLarger-4 16 71058822 ns/op 6357860 B/op 2577 allocs/op |
| 1079 | // BenchmarkMatrixTransduce-4 36703 31891 ns/op 28944 B/op 17 allocs/op |
Akron | fac8abc | 2021-11-10 07:19:59 +0100 | [diff] [blame] | 1080 | // 2021-11-10 - rearranged longest match operator |
Akron | 4880fb6 | 2021-12-05 12:03:05 +0100 | [diff] [blame] | 1081 | // BenchmarkDoubleArrayTransduce-4 34522 33210 ns/op 28944 B/op 17 allocs/op |
| 1082 | // BenchmarkDoubleArrayConstruction-4 66990 16012 ns/op 10703 B/op 29 allocs/op |
| 1083 | // BenchmarkDoubleArrayLarger-4 16 62829878 ns/op 6357823 B/op 2576 allocs/op |
| 1084 | // BenchmarkMatrixTransduce-4 36154 32702 ns/op 28944 B/op 17 allocs/op |
| 1085 | // 2021-12-04 - optimize identity branch |
| 1086 | // BenchmarkDoubleArrayTransduce-4 34903 32255 ns/op 28944 B/op 17 allocs/op |
| 1087 | // BenchmarkDoubleArrayConstruction-4 79394 14561 ns/op 10703 B/op 29 allocs/op |
| 1088 | // BenchmarkDoubleArrayLarger-4 19 60257675 ns/op 6357911 B/op 2577 allocs/op |
| 1089 | // BenchmarkMatrixTransduce-4 35076 30581 ns/op 28944 B/op 17 allocs/op |
Akron | 00cecd1 | 2021-12-05 13:14:03 +0100 | [diff] [blame] | 1090 | // 2021-12-05 - init identity for sigma < 256 |
| 1091 | // BenchmarkDoubleArrayTransduce-4 35284 31918 ns/op 28944 B/op 17 allocs/op |
| 1092 | // BenchmarkDoubleArrayConstruction-4 80342 14504 ns/op 10703 B/op 29 allocs/op |
| 1093 | // BenchmarkDoubleArrayLarger-4 19 60343253 ns/op 6357789 B/op 2575 allocs/op |
| 1094 | // BenchmarkMatrixTransduce-4 34029 30238 ns/op 28944 B/op 17 allocs/op |