Akron | 1c34ce6 | 2021-09-23 23:27:39 +0200 | [diff] [blame] | 1 | package datok |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 5 | "fmt" |
| 6 | "os" |
Akron | 1c34ce6 | 2021-09-23 23:27:39 +0200 | [diff] [blame] | 7 | "strings" |
| 8 | "testing" |
| 9 | |
| 10 | "github.com/stretchr/testify/assert" |
| 11 | ) |
| 12 | |
Akron | abcb6a5 | 2021-10-09 15:52:08 +0200 | [diff] [blame] | 13 | var s string = `Der Vorsitzende der Abk. hat gewählt. Gefunden auf wikipedia.org. Ich bin unter korap@ids-mannheim.de erreichbar. |
| 14 | Unsere Website ist https://korap.ids-mannheim.de/?q=Baum. Unser Server ist 10.0.10.51. Zu 50.4% ist es sicher. |
| 15 | Der Termin ist am 5.9.2018. |
| 16 | Ich habe die readme.txt heruntergeladen. |
| 17 | Ausschalten!!! Hast Du nicht gehört??? |
| 18 | Ich wohne in der Weststr. und Du? Kupietz und Schmidt [2018]: Korpuslinguistik. Dieses verf***** Kleid! Ich habe die readme.txt heruntergeladen. |
| 19 | Er sagte: \"Es geht mir gut!\", daraufhin ging er. "Das ist von C&A!" Früher bzw. später ... Sie erreichte den 1. Platz! |
| 20 | Archive: Ich bin kein zip. D'dorf Ku'damm Lu'hafen M'gladbach W'schaft. |
| 21 | Mach's macht's was'n ist's haste willste kannste biste kriegste.` |
| 22 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 23 | var mat_de, mat_en *MatrixTokenizer |
Akron | 9fb63af | 2021-10-28 01:15:53 +0200 | [diff] [blame] | 24 | |
Akron | c9c0eae | 2021-10-22 19:49:43 +0200 | [diff] [blame] | 25 | func TestMatrixFullTokenizer(t *testing.T) { |
Akron | 1c34ce6 | 2021-09-23 23:27:39 +0200 | [diff] [blame] | 26 | assert := assert.New(t) |
| 27 | foma := LoadFomaFile("testdata/simpletok.fst") |
| 28 | assert.NotNil(foma) |
| 29 | |
| 30 | mat := foma.ToMatrix() |
| 31 | |
| 32 | r := strings.NewReader(" wald gehen Da kann\t man was \"erleben\"!") |
| 33 | b := make([]byte, 0, 2048) |
| 34 | w := bytes.NewBuffer(b) |
| 35 | var tokens []string |
| 36 | mat.Transduce(r, w) |
| 37 | tokens = strings.Split(w.String(), "\n") |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 38 | assert.Equal(len(tokens), 11) |
Akron | 1c34ce6 | 2021-09-23 23:27:39 +0200 | [diff] [blame] | 39 | assert.Equal("wald", tokens[0]) |
| 40 | assert.Equal("gehen", tokens[1]) |
| 41 | assert.Equal("Da", tokens[2]) |
| 42 | assert.Equal("kann", tokens[3]) |
| 43 | assert.Equal("man", tokens[4]) |
| 44 | assert.Equal("was", tokens[5]) |
| 45 | assert.Equal("\"erleben\"", tokens[6]) |
| 46 | assert.Equal("!", tokens[7]) |
Akron | 5c82a92 | 2021-09-24 19:11:29 +0200 | [diff] [blame] | 47 | |
| 48 | r = strings.NewReader(" In den Wald gehen? -- Da kann\t man was \"erleben\"!") |
| 49 | w.Reset() |
| 50 | mat.Transduce(r, w) |
| 51 | tokens = strings.Split(w.String(), "\n") |
| 52 | assert.Equal("In", tokens[0]) |
| 53 | assert.Equal("den", tokens[1]) |
| 54 | assert.Equal("Wald", tokens[2]) |
| 55 | assert.Equal("gehen", tokens[3]) |
| 56 | assert.Equal("?", tokens[4]) |
| 57 | assert.Equal("--", tokens[5]) |
| 58 | |
| 59 | r = strings.NewReader(" g? -- D") |
| 60 | w.Reset() |
| 61 | mat.Transduce(r, w) |
| 62 | tokens = strings.Split(w.String(), "\n") |
| 63 | assert.Equal("g", tokens[0]) |
| 64 | assert.Equal("?", tokens[1]) |
| 65 | assert.Equal("--", tokens[2]) |
| 66 | assert.Equal("D", tokens[3]) |
| 67 | assert.Equal("", tokens[4]) |
| 68 | assert.Equal("", tokens[5]) |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 69 | assert.Equal("", tokens[6]) |
| 70 | assert.Equal(7, len(tokens)) |
Akron | 5c82a92 | 2021-09-24 19:11:29 +0200 | [diff] [blame] | 71 | } |
| 72 | |
Akron | df27581 | 2022-03-27 12:54:46 +0200 | [diff] [blame] | 73 | func TestMatrixSimpleString(t *testing.T) { |
| 74 | assert := assert.New(t) |
| 75 | // bau | bauamt |
| 76 | tok := LoadFomaFile("testdata/bauamt.fst") |
| 77 | mat := tok.ToMatrix() |
| 78 | |
| 79 | b := make([]byte, 0, 2048) |
| 80 | w := bytes.NewBuffer(b) |
| 81 | var tokens []string |
| 82 | |
| 83 | tokens = ttokenize(mat, w, "ibauamt") |
| 84 | assert.Equal("i", tokens[0]) |
| 85 | assert.Equal("bauamt", tokens[1]) |
| 86 | |
| 87 | tokens = ttokenize(mat, w, "ibbauamt") |
| 88 | assert.Equal("i", tokens[0]) |
| 89 | |
| 90 | assert.Equal("b", tokens[1]) |
| 91 | assert.Equal("bauamt", tokens[2]) |
| 92 | |
| 93 | tokens = ttokenize(mat, w, "bau") |
| 94 | assert.Equal("bau", tokens[0]) |
| 95 | |
| 96 | tokens = ttokenize(mat, w, "baum") |
| 97 | assert.Equal("bau", tokens[0]) |
| 98 | assert.Equal("m", tokens[1]) |
| 99 | |
| 100 | tokens = ttokenize(mat, w, "baudibauamt") |
| 101 | assert.Equal("bau", tokens[0]) |
| 102 | assert.Equal("d", tokens[1]) |
| 103 | assert.Equal("i", tokens[2]) |
| 104 | assert.Equal("bauamt", tokens[3]) |
| 105 | } |
| 106 | |
Akron | c9c0eae | 2021-10-22 19:49:43 +0200 | [diff] [blame] | 107 | func TestMatrixReadWriteTokenizer(t *testing.T) { |
Akron | 16c312e | 2021-09-26 13:11:12 +0200 | [diff] [blame] | 108 | assert := assert.New(t) |
| 109 | foma := LoadFomaFile("testdata/simpletok.fst") |
| 110 | assert.NotNil(foma) |
| 111 | |
| 112 | mat := foma.ToMatrix() |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 113 | assert.NotNil(mat) |
Akron | 16c312e | 2021-09-26 13:11:12 +0200 | [diff] [blame] | 114 | |
Akron | df27581 | 2022-03-27 12:54:46 +0200 | [diff] [blame] | 115 | assert.Equal(ttokenizeStr(mat, "bau"), "bau") |
| 116 | assert.Equal(ttokenizeStr(mat, "bad"), "bad") |
| 117 | assert.Equal(ttokenizeStr(mat, "wald gehen"), "wald\ngehen") |
Akron | 16c312e | 2021-09-26 13:11:12 +0200 | [diff] [blame] | 118 | b := make([]byte, 0, 1024) |
| 119 | buf := bytes.NewBuffer(b) |
| 120 | n, err := mat.WriteTo(buf) |
| 121 | assert.Nil(err) |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 122 | assert.Equal(int64(230), n) |
Akron | 16c312e | 2021-09-26 13:11:12 +0200 | [diff] [blame] | 123 | mat2 := ParseMatrix(buf) |
| 124 | assert.NotNil(mat2) |
| 125 | assert.Equal(mat.sigma, mat2.sigma) |
| 126 | assert.Equal(mat.epsilon, mat2.epsilon) |
| 127 | assert.Equal(mat.unknown, mat2.unknown) |
| 128 | assert.Equal(mat.identity, mat2.identity) |
| 129 | assert.Equal(mat.stateCount, mat2.stateCount) |
| 130 | assert.Equal(len(mat.array), len(mat2.array)) |
| 131 | assert.Equal(mat.array, mat2.array) |
Akron | df27581 | 2022-03-27 12:54:46 +0200 | [diff] [blame] | 132 | assert.Equal(ttokenizeStr(mat2, "bau"), "bau") |
| 133 | assert.Equal(ttokenizeStr(mat2, "bad"), "bad") |
| 134 | assert.Equal(ttokenizeStr(mat2, "wald gehen"), "wald\ngehen") |
Akron | 16c312e | 2021-09-26 13:11:12 +0200 | [diff] [blame] | 135 | } |
| 136 | |
Akron | e396a93 | 2021-10-19 01:06:13 +0200 | [diff] [blame] | 137 | func TestMatrixIgnorableMCS(t *testing.T) { |
| 138 | assert := assert.New(t) |
| 139 | |
| 140 | // This test relies on final states. That's why it is |
| 141 | // not working correctly anymore. |
| 142 | |
| 143 | // File has MCS in sigma but not in net |
| 144 | tok := LoadFomaFile("testdata/ignorable_mcs.fst") |
| 145 | assert.NotNil(tok) |
| 146 | mat := tok.ToMatrix() |
| 147 | assert.NotNil(mat) |
| 148 | |
| 149 | b := make([]byte, 0, 2048) |
| 150 | w := bytes.NewBuffer(b) |
| 151 | var tokens []string |
| 152 | |
| 153 | // Is only unambigous when transducing strictly greedy! |
| 154 | assert.True(mat.Transduce(strings.NewReader("ab<ab>a"), w)) |
| 155 | tokens = strings.Split(w.String(), "\n") |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 156 | assert.Equal("a\nb\n<ab>a\n\n\n", w.String()) |
Akron | e396a93 | 2021-10-19 01:06:13 +0200 | [diff] [blame] | 157 | assert.Equal("a", tokens[0]) |
| 158 | assert.Equal("b", tokens[1]) |
| 159 | assert.Equal("<ab>a", tokens[2]) |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 160 | assert.Equal(6, len(tokens)) |
Akron | e396a93 | 2021-10-19 01:06:13 +0200 | [diff] [blame] | 161 | } |
| 162 | |
Akron | c9c0eae | 2021-10-22 19:49:43 +0200 | [diff] [blame] | 163 | func xTestMatrixReadWriteFullTokenizer(t *testing.T) { |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 164 | assert := assert.New(t) |
| 165 | foma := LoadFomaFile("testdata/tokenizer.fst") |
| 166 | assert.NotNil(foma) |
| 167 | |
| 168 | mat := foma.ToMatrix() |
| 169 | assert.NotNil(foma) |
| 170 | |
| 171 | tb := make([]byte, 0, 2048) |
| 172 | w := bytes.NewBuffer(tb) |
| 173 | |
| 174 | assert.True(mat.Transduce(strings.NewReader("der alte baum"), w)) |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 175 | assert.Equal("der\nalte\nbaum\n\n\n", w.String()) |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 176 | |
| 177 | b := make([]byte, 0, 1024) |
| 178 | buf := bytes.NewBuffer(b) |
| 179 | _, err := mat.WriteTo(buf) |
| 180 | assert.Nil(err) |
| 181 | w.Reset() |
| 182 | // assert.Equal(int64(248), n) |
| 183 | |
| 184 | mat2 := ParseMatrix(buf) |
| 185 | assert.NotNil(mat2) |
| 186 | assert.Equal(mat.sigma, mat2.sigma) |
| 187 | assert.Equal(mat.epsilon, mat2.epsilon) |
| 188 | assert.Equal(mat.unknown, mat2.unknown) |
| 189 | assert.Equal(mat.identity, mat2.identity) |
| 190 | assert.Equal(mat.stateCount, mat2.stateCount) |
| 191 | assert.Equal(len(mat.array), len(mat2.array)) |
| 192 | // assert.Equal(mat.array, mat2.array) |
| 193 | |
| 194 | assert.True(mat2.Transduce(strings.NewReader("der alte baum"), w)) |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 195 | assert.Equal("der\nalte\nbaum\n\n\n", w.String()) |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 196 | } |
| 197 | |
Akron | c9c0eae | 2021-10-22 19:49:43 +0200 | [diff] [blame] | 198 | func TestMatrixFullTokenizerTransduce(t *testing.T) { |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 199 | assert := assert.New(t) |
| 200 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 201 | if mat_de == nil { |
| 202 | mat_de = LoadMatrixFile("testdata/tokenizer.matok") |
Akron | 9fb63af | 2021-10-28 01:15:53 +0200 | [diff] [blame] | 203 | } |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 204 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 205 | assert.NotNil(mat_de) |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 206 | |
| 207 | b := make([]byte, 0, 2048) |
| 208 | w := bytes.NewBuffer(b) |
| 209 | var tokens []string |
| 210 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 211 | assert.True(mat_de.Transduce(strings.NewReader("tra. u Du?"), w)) |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 212 | |
| 213 | tokens = strings.Split(w.String(), "\n") |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 214 | assert.Equal("tra\n.\n\nu\nDu\n?\n\n\n", w.String()) |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 215 | assert.Equal("tra", tokens[0]) |
| 216 | assert.Equal(".", tokens[1]) |
| 217 | assert.Equal("", tokens[2]) |
| 218 | assert.Equal("u", tokens[3]) |
| 219 | assert.Equal("Du", tokens[4]) |
| 220 | assert.Equal("?", tokens[5]) |
| 221 | assert.Equal("", tokens[6]) |
| 222 | assert.Equal("", tokens[7]) |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 223 | assert.Equal(9, len(tokens)) |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 224 | |
| 225 | w.Reset() |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 226 | assert.True(mat_de.Transduce(strings.NewReader("\"John Doe\"@xx.com"), w)) |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 227 | assert.Equal("\"\nJohn\nDoe\n\"\n@xx\n.\n\ncom\n\n\n", w.String()) |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 228 | } |
| 229 | |
Akron | c9c0eae | 2021-10-22 19:49:43 +0200 | [diff] [blame] | 230 | func TestMatrixFullTokenizerMatrixSentenceSplitter(t *testing.T) { |
Akron | 5c82a92 | 2021-09-24 19:11:29 +0200 | [diff] [blame] | 231 | assert := assert.New(t) |
Akron | 9fb63af | 2021-10-28 01:15:53 +0200 | [diff] [blame] | 232 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 233 | if mat_de == nil { |
| 234 | mat_de = LoadMatrixFile("testdata/tokenizer.matok") |
Akron | 9fb63af | 2021-10-28 01:15:53 +0200 | [diff] [blame] | 235 | } |
Akron | 5c82a92 | 2021-09-24 19:11:29 +0200 | [diff] [blame] | 236 | |
| 237 | b := make([]byte, 0, 2048) |
| 238 | w := bytes.NewBuffer(b) |
| 239 | var sentences []string |
| 240 | |
| 241 | // testSentSplitterSimple |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 242 | assert.True(mat_de.Transduce(strings.NewReader("Der alte Mann."), w)) |
Akron | 5c82a92 | 2021-09-24 19:11:29 +0200 | [diff] [blame] | 243 | sentences = strings.Split(w.String(), "\n\n") |
| 244 | |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 245 | assert.Equal("Der\nalte\nMann\n.\n\n\n", w.String()) |
Akron | 5c82a92 | 2021-09-24 19:11:29 +0200 | [diff] [blame] | 246 | assert.Equal("Der\nalte\nMann\n.", sentences[0]) |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 247 | assert.Equal("\n", sentences[1]) |
Akron | 5c82a92 | 2021-09-24 19:11:29 +0200 | [diff] [blame] | 248 | assert.Equal(len(sentences), 2) |
| 249 | |
| 250 | w.Reset() |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 251 | assert.True(mat_de.Transduce(strings.NewReader("Der Vorsitzende der F.D.P. hat gewählt."), w)) |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 252 | sentences = strings.Split(w.String(), "\n\n") |
| 253 | assert.Equal(len(sentences), 2) |
| 254 | assert.Equal("Der\nVorsitzende\nder\nF.D.P.\nhat\ngewählt\n.", sentences[0]) |
| 255 | assert.Equal("\n", sentences[1]) |
| 256 | |
| 257 | w.Reset() |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 258 | assert.True(mat_de.Transduce(strings.NewReader("Der Vorsitzende der Abk. hat gewählt."), w)) |
Akron | 5c82a92 | 2021-09-24 19:11:29 +0200 | [diff] [blame] | 259 | sentences = strings.Split(w.String(), "\n\n") |
| 260 | assert.Equal(len(sentences), 2) |
| 261 | assert.Equal("Der\nVorsitzende\nder\nAbk.\nhat\ngewählt\n.", sentences[0]) |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 262 | assert.Equal("\n", sentences[1]) |
Akron | 5c82a92 | 2021-09-24 19:11:29 +0200 | [diff] [blame] | 263 | |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 264 | w.Reset() |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 265 | assert.True(mat_de.Transduce(strings.NewReader(""), w)) |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 266 | sentences = strings.Split(w.String(), "\n\n") |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 267 | assert.Equal(len(sentences), 2) |
| 268 | assert.Equal("", sentences[0]) |
| 269 | assert.Equal("", sentences[1]) |
Akron | 5c82a92 | 2021-09-24 19:11:29 +0200 | [diff] [blame] | 270 | |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 271 | w.Reset() |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 272 | assert.True(mat_de.Transduce(strings.NewReader("Gefunden auf wikipedia.org."), w)) |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 273 | sentences = strings.Split(w.String(), "\n\n") |
| 274 | assert.Equal(len(sentences), 2) |
Akron | 5c82a92 | 2021-09-24 19:11:29 +0200 | [diff] [blame] | 275 | |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 276 | w.Reset() |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 277 | assert.True(mat_de.Transduce(strings.NewReader("Ich bin unter korap@ids-mannheim.de erreichbar."), w)) |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 278 | sentences = strings.Split(w.String(), "\n\n") |
| 279 | assert.Equal(len(sentences), 2) |
Akron | 5c82a92 | 2021-09-24 19:11:29 +0200 | [diff] [blame] | 280 | |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 281 | w.Reset() |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 282 | assert.True(mat_de.Transduce(strings.NewReader("Unsere Website ist https://korap.ids-mannheim.de/?q=Baum"), w)) |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 283 | sentences = strings.Split(w.String(), "\n\n") |
| 284 | 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] | 285 | assert.Equal("\n", sentences[1]) |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 286 | assert.Equal(len(sentences), 2) |
Akron | 5c82a92 | 2021-09-24 19:11:29 +0200 | [diff] [blame] | 287 | |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 288 | w.Reset() |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 289 | assert.True(mat_de.Transduce(strings.NewReader("Unser Server ist 10.0.10.51."), w)) |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 290 | sentences = strings.Split(w.String(), "\n\n") |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 291 | assert.Equal("\n", sentences[1]) |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 292 | assert.Equal(len(sentences), 2) |
Akron | 5c82a92 | 2021-09-24 19:11:29 +0200 | [diff] [blame] | 293 | |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 294 | w.Reset() |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 295 | assert.True(mat_de.Transduce(strings.NewReader("Zu 50.4% ist es sicher"), w)) |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 296 | sentences = strings.Split(w.String(), "\n\n") |
| 297 | assert.Equal(len(sentences), 2) |
Akron | 5c82a92 | 2021-09-24 19:11:29 +0200 | [diff] [blame] | 298 | |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 299 | w.Reset() |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 300 | assert.True(mat_de.Transduce(strings.NewReader("Der Termin ist am 5.9.2018"), w)) |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 301 | sentences = strings.Split(w.String(), "\n\n") |
| 302 | assert.Equal(len(sentences), 2) |
Akron | 5c82a92 | 2021-09-24 19:11:29 +0200 | [diff] [blame] | 303 | |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 304 | w.Reset() |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 305 | assert.True(mat_de.Transduce(strings.NewReader("Ich habe die readme.txt heruntergeladen"), w)) |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 306 | sentences = strings.Split(w.String(), "\n\n") |
| 307 | assert.Equal(len(sentences), 2) |
| 308 | assert.Equal("Ich\nhabe\ndie\nreadme.txt\nheruntergeladen", sentences[0]) |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 309 | assert.Equal("\n", sentences[1]) |
Akron | 5c82a92 | 2021-09-24 19:11:29 +0200 | [diff] [blame] | 310 | |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 311 | w.Reset() |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 312 | assert.True(mat_de.Transduce(strings.NewReader("Ausschalten!!! Hast Du nicht gehört???"), w)) |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 313 | sentences = strings.Split(w.String(), "\n\n") |
| 314 | assert.Equal(len(sentences), 3) |
| 315 | assert.Equal("Ausschalten\n!!!", sentences[0]) |
| 316 | assert.Equal("Hast\nDu\nnicht\ngehört\n???", sentences[1]) |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 317 | assert.Equal("\n", sentences[2]) |
Akron | 5c82a92 | 2021-09-24 19:11:29 +0200 | [diff] [blame] | 318 | |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 319 | w.Reset() |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 320 | assert.True(mat_de.Transduce(strings.NewReader("Ich wohne in der Weststr. und Du?"), w)) |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 321 | sentences = strings.Split(w.String(), "\n\n") |
| 322 | assert.Equal(len(sentences), 2) |
Akron | e96895f | 2022-03-08 19:58:37 +0100 | [diff] [blame] | 323 | |
| 324 | w.Reset() |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 325 | assert.True(mat_de.Transduce(strings.NewReader("\"Alter!\", sagte er: \"Komm nicht wieder!\" Geh!!! \"Lass!\" Dann ging er."), w)) |
Akron | e96895f | 2022-03-08 19:58:37 +0100 | [diff] [blame] | 326 | sentences = strings.Split(w.String(), "\n\n") |
| 327 | assert.Equal(len(sentences), 5) |
| 328 | assert.Equal("\"\nAlter\n!\n\"\n,\nsagte\ner\n:\n\"\nKomm\nnicht\nwieder\n!\n\"", sentences[0]) |
| 329 | assert.Equal("Geh\n!!!", sentences[1]) |
| 330 | assert.Equal("\"\nLass\n!\n\"", sentences[2]) |
| 331 | assert.Equal("Dann\nging\ner\n.", sentences[3]) |
| 332 | |
| 333 | w.Reset() |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 334 | assert.True(mat_de.Transduce(strings.NewReader("\"Ausschalten!!!\", sagte er. \"Hast Du nicht gehört???\""), w)) |
Akron | e96895f | 2022-03-08 19:58:37 +0100 | [diff] [blame] | 335 | sentences = strings.Split(w.String(), "\n\n") |
| 336 | assert.Equal(len(sentences), 3) |
| 337 | assert.Equal("\"\nAusschalten\n!!!\n\"\n,\nsagte\ner\n.", sentences[0]) |
| 338 | assert.Equal("\"\nHast\nDu\nnicht\ngehört\n???\n\"", sentences[1]) |
Akron | ece3f01 | 2022-03-09 19:12:15 +0100 | [diff] [blame] | 339 | |
| 340 | w.Reset() |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 341 | assert.True(mat_de.Transduce(strings.NewReader("“Ausschalten!!!”, sagte er. «Hast Du nicht gehört???»"), w)) |
Akron | ece3f01 | 2022-03-09 19:12:15 +0100 | [diff] [blame] | 342 | sentences = strings.Split(w.String(), "\n\n") |
| 343 | assert.Equal(len(sentences), 3) |
| 344 | assert.Equal("“\nAusschalten\n!!!\n”\n,\nsagte\ner\n.", sentences[0]) |
| 345 | assert.Equal("«\nHast\nDu\nnicht\ngehört\n???\n»", sentences[1]) |
| 346 | |
| 347 | w.Reset() |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 348 | assert.True(mat_de.Transduce(strings.NewReader("“Ausschalten!!!”, sagte er. «Hast Du nicht gehört???»"), w)) |
Akron | ece3f01 | 2022-03-09 19:12:15 +0100 | [diff] [blame] | 349 | sentences = strings.Split(w.String(), "\n\n") |
| 350 | assert.Equal(len(sentences), 3) |
| 351 | assert.Equal("“\nAusschalten\n!!!\n”\n,\nsagte\ner\n.", sentences[0]) |
| 352 | assert.Equal("«\nHast\nDu\nnicht\ngehört\n???\n»", sentences[1]) |
| 353 | |
| 354 | text := `»Meinetwegen. Denkst du, daß ich darauf warte? Das fehlte noch. |
| 355 | Übrigens, ich kriege schon einen und vielleicht bald. Da ist mir nicht |
| 356 | bange. Neulich erst hat mir der kleine Ventivegni von drüben gesagt: |
| 357 | 'Fräulein Effi, was gilt die Wette, wir sind hier noch in diesem Jahre |
| 358 | zu Polterabend und Hochzeit.'« |
| 359 | |
| 360 | »Und was sagtest du da?«` |
| 361 | |
| 362 | w.Reset() |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 363 | assert.True(mat_de.Transduce(strings.NewReader(text), w)) |
Akron | ece3f01 | 2022-03-09 19:12:15 +0100 | [diff] [blame] | 364 | sentences = strings.Split(w.String(), "\n\n") |
| 365 | assert.Equal(len(sentences), 8) |
| 366 | assert.Equal("Neulich\nerst\nhat\nmir\nder\nkleine\nVentivegni\nvon\ndrüben\ngesagt\n:\n'\nFräulein\nEffi\n,\nwas\ngilt\ndie\nWette\n,\nwir\nsind\nhier\nnoch\nin\ndiesem\nJahre\nzu\nPolterabend\nund\nHochzeit\n.\n'\n«", sentences[5]) |
| 367 | assert.Equal("»\nUnd\nwas\nsagtest\ndu\nda\n?\n«", sentences[6]) |
Akron | 4222ac8 | 2022-03-11 01:06:21 +0100 | [diff] [blame] | 368 | |
| 369 | text = `»Nun, gib dich zufrieden, ich fange schon an ... Also Baron |
| 370 | Innstetten!` |
| 371 | |
| 372 | w.Reset() |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 373 | assert.True(mat_de.Transduce(strings.NewReader(text), w)) |
Akron | 4222ac8 | 2022-03-11 01:06:21 +0100 | [diff] [blame] | 374 | sentences = strings.Split(w.String(), "\n\n") |
| 375 | assert.Equal(len(sentences), 3) |
| 376 | assert.Equal("»\nNun\n,\ngib\ndich\nzufrieden\n,\nich\nfange\nschon\nan\n...", sentences[0]) |
| 377 | assert.Equal("Also\nBaron\nInnstetten\n!", sentences[1]) |
Akron | df27581 | 2022-03-27 12:54:46 +0200 | [diff] [blame] | 378 | |
Akron | b98e4cf | 2022-03-27 23:56:49 +0200 | [diff] [blame] | 379 | // Check parantheses at the end of the sentence |
Akron | f94b9ce | 2022-03-27 18:18:09 +0200 | [diff] [blame] | 380 | w.Reset() |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 381 | assert.True(mat_de.Transduce(strings.NewReader("(Er ging.) Und kam (später)."), w)) |
Akron | f94b9ce | 2022-03-27 18:18:09 +0200 | [diff] [blame] | 382 | sentences = strings.Split(w.String(), "\n\n") |
| 383 | assert.Equal(len(sentences), 3) |
| 384 | assert.Equal("(\nEr\nging\n.\n)", sentences[0]) |
| 385 | assert.Equal("Und\nkam\n(\nspäter\n)\n.", sentences[1]) |
Akron | 7aa1cbe | 2022-03-30 12:44:04 +0200 | [diff] [blame] | 386 | |
| 387 | // Check parantheses and quotes at the end of the sentence |
| 388 | w.Reset() |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 389 | assert.True(mat_de.Transduce(strings.NewReader("(Er sagte: \"Hallo!\") Dann ging er."), w)) |
Akron | 7aa1cbe | 2022-03-30 12:44:04 +0200 | [diff] [blame] | 390 | sentences = strings.Split(w.String(), "\n\n") |
| 391 | assert.Equal(len(sentences), 3) |
| 392 | assert.Equal("(\nEr\nsagte\n:\n\"\nHallo\n!\n\"\n)", sentences[0]) |
| 393 | assert.Equal("Dann\nging\ner\n.", sentences[1]) |
| 394 | |
Akron | df27581 | 2022-03-27 12:54:46 +0200 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | func TestMatrixFullTokenizerMatrixSentenceSplitterBug1(t *testing.T) { |
| 398 | assert := assert.New(t) |
| 399 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 400 | if mat_de == nil { |
| 401 | mat_de = LoadMatrixFile("testdata/tokenizer.matok") |
Akron | df27581 | 2022-03-27 12:54:46 +0200 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | b := make([]byte, 0, 2048) |
| 405 | w := bytes.NewBuffer(b) |
| 406 | var sentences []string |
| 407 | |
| 408 | text := `Wüllersdorf war aufgestanden. »Ich finde es furchtbar, daß Sie recht haben, aber Sie haben recht. Ich quäle Sie nicht länger mit meinem 'Muß es sein?'. Die Welt ist einmal, wie sie ist, und die Dinge verlaufen nicht, wie wir wollen, sondern wie die andern wollen. Das mit dem 'Gottesgericht', wie manche hochtrabend versichern, ist freilich ein Unsinn, nichts davon, umgekehrt, unser Ehrenkultus ist ein Götzendienst, aber wir müssen uns ihm unterwerfen, solange der Götze gilt.«` |
| 409 | |
| 410 | w.Reset() |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 411 | assert.True(mat_de.Transduce(strings.NewReader(text), w)) |
Akron | df27581 | 2022-03-27 12:54:46 +0200 | [diff] [blame] | 412 | sentences = strings.Split(w.String(), "\n\n") |
Akron | b428755 | 2022-03-27 14:11:24 +0200 | [diff] [blame] | 413 | assert.Equal(len(sentences), 6) |
Akron | df27581 | 2022-03-27 12:54:46 +0200 | [diff] [blame] | 414 | assert.Equal("Wüllersdorf\nwar\naufgestanden\n.", sentences[0]) |
| 415 | assert.Equal("»\nIch\nfinde\nes\nfurchtbar\n,\ndaß\nSie\nrecht\nhaben\n,\naber\nSie\nhaben\nrecht\n.", sentences[1]) |
Akron | b428755 | 2022-03-27 14:11:24 +0200 | [diff] [blame] | 416 | assert.Equal("Ich\nquäle\nSie\nnicht\nlänger\nmit\nmeinem\n'\nMuß\nes\nsein\n?\n'\n.", sentences[2]) |
| 417 | assert.Equal("Die\nWelt\nist\neinmal\n,\nwie\nsie\nist\n,\nund\ndie\nDinge\nverlaufen\nnicht\n,\nwie\nwir\nwollen\n,\nsondern\nwie\ndie\nandern\nwollen\n.", sentences[3]) |
| 418 | assert.Equal("Das\nmit\ndem\n'\nGottesgericht\n'\n,\nwie\nmanche\nhochtrabend\nversichern\n,\nist\nfreilich\nein\nUnsinn\n,\nnichts\ndavon\n,\numgekehrt\n,\nunser\nEhrenkultus\nist\nein\nGötzendienst\n,\naber\nwir\nmüssen\nuns\nihm\nunterwerfen\n,\nsolange\nder\nGötze\ngilt\n.\n«", sentences[4]) |
Akron | 1c34ce6 | 2021-09-23 23:27:39 +0200 | [diff] [blame] | 419 | } |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 420 | |
Akron | c9c0eae | 2021-10-22 19:49:43 +0200 | [diff] [blame] | 421 | func TestMatrixFullTokenizerTokenSplitter(t *testing.T) { |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 422 | assert := assert.New(t) |
| 423 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 424 | if mat_de == nil { |
| 425 | mat_de = LoadMatrixFile("testdata/tokenizer.matok") |
Akron | 9fb63af | 2021-10-28 01:15:53 +0200 | [diff] [blame] | 426 | } |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 427 | |
| 428 | b := make([]byte, 0, 2048) |
| 429 | w := bytes.NewBuffer(b) |
| 430 | var tokens []string |
| 431 | |
| 432 | // testTokenizerSimple |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 433 | tokens = ttokenize(mat_de, w, "Der alte Mann") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 434 | assert.Equal(tokens[0], "Der") |
| 435 | assert.Equal(tokens[1], "alte") |
| 436 | assert.Equal(tokens[2], "Mann") |
| 437 | assert.Equal(len(tokens), 3) |
| 438 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 439 | tokens = ttokenize(mat_de, w, "Der alte Mann.") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 440 | assert.Equal(tokens[0], "Der") |
| 441 | assert.Equal(tokens[1], "alte") |
| 442 | assert.Equal(tokens[2], "Mann") |
| 443 | assert.Equal(tokens[3], ".") |
| 444 | assert.Equal(len(tokens), 4) |
| 445 | |
| 446 | // testTokenizerAbbr |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 447 | tokens = ttokenize(mat_de, w, "Der Vorsitzende der F.D.P. hat gewählt") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 448 | assert.Equal(tokens[0], "Der") |
| 449 | assert.Equal(tokens[1], "Vorsitzende") |
| 450 | assert.Equal(tokens[2], "der") |
| 451 | assert.Equal(tokens[3], "F.D.P.") |
| 452 | assert.Equal(tokens[4], "hat") |
| 453 | assert.Equal(tokens[5], "gewählt") |
| 454 | assert.Equal(len(tokens), 6) |
| 455 | // Ignored in KorAP-Tokenizer |
| 456 | |
| 457 | // testTokenizerHost1 |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 458 | tokens = ttokenize(mat_de, w, "Gefunden auf wikipedia.org") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 459 | assert.Equal(tokens[0], "Gefunden") |
| 460 | assert.Equal(tokens[1], "auf") |
| 461 | assert.Equal(tokens[2], "wikipedia.org") |
| 462 | assert.Equal(len(tokens), 3) |
| 463 | |
| 464 | // testTokenizerWwwHost |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 465 | tokens = ttokenize(mat_de, w, "Gefunden auf www.wikipedia.org") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 466 | assert.Equal("Gefunden", tokens[0]) |
| 467 | assert.Equal("auf", tokens[1]) |
| 468 | assert.Equal("www.wikipedia.org", tokens[2]) |
| 469 | assert.Equal(3, len(tokens)) |
| 470 | |
| 471 | // testTokenizerWwwUrl |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 472 | tokens = ttokenize(mat_de, w, "Weitere Infos unter www.info.biz/info") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 473 | assert.Equal("www.info.biz/info", tokens[3]) |
| 474 | |
| 475 | // testTokenizerFtpHost |
| 476 | /* |
| 477 | tokens = tokenize(dat, w, "Kann von ftp.download.org heruntergeladen werden") |
| 478 | assert.Equal("Kann", tokens[0]) |
| 479 | assert.Equal("von", tokens[1]) |
| 480 | assert.Equal("ftp.download.org", tokens[2]) |
| 481 | assert.Equal(5, len(tokens)) |
| 482 | // Ignored in KorAP-Tokenizer |
| 483 | */ |
| 484 | |
| 485 | // testTokenizerDash |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 486 | tokens = ttokenize(mat_de, w, "Das war -- spitze") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 487 | assert.Equal(tokens[0], "Das") |
| 488 | assert.Equal(tokens[1], "war") |
| 489 | assert.Equal(tokens[2], "--") |
| 490 | assert.Equal(tokens[3], "spitze") |
| 491 | assert.Equal(len(tokens), 4) |
| 492 | |
| 493 | // testTokenizerEmail1 |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 494 | tokens = ttokenize(mat_de, w, "Ich bin unter korap@ids-mannheim.de erreichbar.") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 495 | assert.Equal(tokens[0], "Ich") |
| 496 | assert.Equal(tokens[1], "bin") |
| 497 | assert.Equal(tokens[2], "unter") |
| 498 | assert.Equal(tokens[3], "korap@ids-mannheim.de") |
| 499 | assert.Equal(tokens[4], "erreichbar") |
| 500 | assert.Equal(tokens[5], ".") |
| 501 | assert.Equal(len(tokens), 6) |
| 502 | |
| 503 | // testTokenizerEmail2 |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 504 | tokens = ttokenize(mat_de, w, "Oder unter korap[at]ids-mannheim[dot]de.") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 505 | assert.Equal(tokens[0], "Oder") |
| 506 | assert.Equal(tokens[1], "unter") |
| 507 | assert.Equal(tokens[2], "korap[at]ids-mannheim[dot]de") |
| 508 | assert.Equal(tokens[3], ".") |
| 509 | assert.Equal(len(tokens), 4) |
| 510 | |
| 511 | // testTokenizerEmail3 |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 512 | tokens = ttokenize(mat_de, w, "Oder unter korap(at)ids-mannheim(dot)de.") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 513 | assert.Equal(tokens[0], "Oder") |
| 514 | assert.Equal(tokens[1], "unter") |
| 515 | assert.Equal(tokens[2], "korap(at)ids-mannheim(dot)de") |
| 516 | assert.Equal(tokens[3], ".") |
| 517 | assert.Equal(len(tokens), 4) |
| 518 | // Ignored in KorAP-Tokenizer |
| 519 | |
| 520 | // testTokenizerDoNotAcceptQuotedEmailNames |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 521 | tokens = ttokenize(mat_de, w, "\"John Doe\"@xx.com") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 522 | assert.Equal("\"", tokens[0]) |
| 523 | assert.Equal("John", tokens[1]) |
| 524 | assert.Equal("Doe", tokens[2]) |
| 525 | assert.Equal("\"", tokens[3]) |
| 526 | assert.Equal("@xx", tokens[4]) |
| 527 | assert.Equal(".", tokens[5]) // Differs - as the sentence splitter splits here! |
| 528 | assert.Equal("com", tokens[6]) |
| 529 | assert.Equal(7, len(tokens)) |
| 530 | |
| 531 | // testTokenizerTwitter |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 532 | tokens = ttokenize(mat_de, w, "Folgt @korap und #korap") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 533 | assert.Equal(tokens[0], "Folgt") |
| 534 | assert.Equal(tokens[1], "@korap") |
| 535 | assert.Equal(tokens[2], "und") |
| 536 | assert.Equal(tokens[3], "#korap") |
| 537 | assert.Equal(len(tokens), 4) |
| 538 | |
| 539 | // testTokenizerWeb1 |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 540 | tokens = ttokenize(mat_de, w, "Unsere Website ist https://korap.ids-mannheim.de/?q=Baum") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 541 | assert.Equal(tokens[0], "Unsere") |
| 542 | assert.Equal(tokens[1], "Website") |
| 543 | assert.Equal(tokens[2], "ist") |
| 544 | assert.Equal(tokens[3], "https://korap.ids-mannheim.de/?q=Baum") |
| 545 | assert.Equal(len(tokens), 4) |
| 546 | |
| 547 | // testTokenizerWeb2 |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 548 | tokens = ttokenize(mat_de, w, "Wir sind auch im Internet (https://korap.ids-mannheim.de/?q=Baum)") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 549 | assert.Equal(tokens[0], "Wir") |
| 550 | assert.Equal(tokens[1], "sind") |
| 551 | assert.Equal(tokens[2], "auch") |
| 552 | assert.Equal(tokens[3], "im") |
| 553 | assert.Equal(tokens[4], "Internet") |
| 554 | assert.Equal(tokens[5], "(") |
| 555 | assert.Equal(tokens[6], "https://korap.ids-mannheim.de/?q=Baum") |
| 556 | assert.Equal(tokens[7], ")") |
| 557 | assert.Equal(len(tokens), 8) |
| 558 | // Ignored in KorAP-Tokenizer |
| 559 | |
| 560 | // testTokenizerWeb3 |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 561 | tokens = ttokenize(mat_de, w, "Die Adresse ist https://korap.ids-mannheim.de/?q=Baum.") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 562 | assert.Equal(tokens[0], "Die") |
| 563 | assert.Equal(tokens[1], "Adresse") |
| 564 | assert.Equal(tokens[2], "ist") |
| 565 | assert.Equal(tokens[3], "https://korap.ids-mannheim.de/?q=Baum") |
| 566 | assert.Equal(tokens[4], ".") |
| 567 | assert.Equal(len(tokens), 5) |
| 568 | // Ignored in KorAP-Tokenizer |
| 569 | |
| 570 | // testTokenizerServer |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 571 | tokens = ttokenize(mat_de, w, "Unser Server ist 10.0.10.51.") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 572 | assert.Equal(tokens[0], "Unser") |
| 573 | assert.Equal(tokens[1], "Server") |
| 574 | assert.Equal(tokens[2], "ist") |
| 575 | assert.Equal(tokens[3], "10.0.10.51") |
| 576 | assert.Equal(tokens[4], ".") |
| 577 | assert.Equal(len(tokens), 5) |
| 578 | |
| 579 | // testTokenizerNum |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 580 | tokens = ttokenize(mat_de, w, "Zu 50,4% ist es sicher") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 581 | assert.Equal(tokens[0], "Zu") |
| 582 | assert.Equal(tokens[1], "50,4%") |
| 583 | assert.Equal(tokens[2], "ist") |
| 584 | assert.Equal(tokens[3], "es") |
| 585 | assert.Equal(tokens[4], "sicher") |
| 586 | assert.Equal(len(tokens), 5) |
| 587 | // Differs from KorAP-Tokenizer |
| 588 | |
| 589 | // testTokenizerDate |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 590 | tokens = ttokenize(mat_de, w, "Der Termin ist am 5.9.2018") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 591 | assert.Equal(tokens[0], "Der") |
| 592 | assert.Equal(tokens[1], "Termin") |
| 593 | assert.Equal(tokens[2], "ist") |
| 594 | assert.Equal(tokens[3], "am") |
| 595 | assert.Equal(tokens[4], "5.9.2018") |
| 596 | assert.Equal(len(tokens), 5) |
| 597 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 598 | tokens = ttokenize(mat_de, w, "Der Termin ist am 5/9/2018") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 599 | assert.Equal(tokens[0], "Der") |
| 600 | assert.Equal(tokens[1], "Termin") |
| 601 | assert.Equal(tokens[2], "ist") |
| 602 | assert.Equal(tokens[3], "am") |
| 603 | assert.Equal(tokens[4], "5/9/2018") |
| 604 | assert.Equal(len(tokens), 5) |
| 605 | |
| 606 | // testTokenizerDateRange |
| 607 | /* |
| 608 | tokens = tokenize(dat, w, "Der Termin war vom 4.-5.9.2018") |
| 609 | assert.Equal(tokens[0], "Der") |
| 610 | assert.Equal(tokens[1], "Termin") |
| 611 | assert.Equal(tokens[2], "war") |
| 612 | assert.Equal(tokens[3], "vom") |
| 613 | assert.Equal(tokens[4], "4.") |
| 614 | assert.Equal(tokens[5], "-") |
| 615 | assert.Equal(tokens[6], "5.9.2018") |
| 616 | assert.Equal(len(tokens), 7) |
| 617 | // Ignored in KorAP-Tokenizer |
| 618 | */ |
| 619 | |
| 620 | // testTokenizerEmoji1 |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 621 | tokens = ttokenize(mat_de, w, "Das ist toll! ;)") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 622 | assert.Equal(tokens[0], "Das") |
| 623 | assert.Equal(tokens[1], "ist") |
| 624 | assert.Equal(tokens[2], "toll") |
| 625 | assert.Equal(tokens[3], "!") |
| 626 | assert.Equal(tokens[4], ";)") |
| 627 | assert.Equal(len(tokens), 5) |
| 628 | |
| 629 | // testTokenizerRef1 |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 630 | tokens = ttokenize(mat_de, w, "Kupietz und Schmidt (2018): Korpuslinguistik") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 631 | assert.Equal(tokens[0], "Kupietz") |
| 632 | assert.Equal(tokens[1], "und") |
| 633 | assert.Equal(tokens[2], "Schmidt") |
| 634 | assert.Equal(tokens[3], "(2018)") |
| 635 | assert.Equal(tokens[4], ":") |
| 636 | assert.Equal(tokens[5], "Korpuslinguistik") |
| 637 | assert.Equal(len(tokens), 6) |
| 638 | // Differs from KorAP-Tokenizer! |
| 639 | |
| 640 | // testTokenizerRef2 () { |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 641 | tokens = ttokenize(mat_de, w, "Kupietz und Schmidt [2018]: Korpuslinguistik") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 642 | assert.Equal(tokens[0], "Kupietz") |
| 643 | assert.Equal(tokens[1], "und") |
| 644 | assert.Equal(tokens[2], "Schmidt") |
| 645 | assert.Equal(tokens[3], "[2018]") |
| 646 | assert.Equal(tokens[4], ":") |
| 647 | assert.Equal(tokens[5], "Korpuslinguistik") |
| 648 | assert.Equal(len(tokens), 6) |
| 649 | // Differs from KorAP-Tokenizer! |
| 650 | |
| 651 | // testTokenizerOmission1 () { |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 652 | tokens = ttokenize(mat_de, w, "Er ist ein A****loch!") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 653 | assert.Equal(tokens[0], "Er") |
| 654 | assert.Equal(tokens[1], "ist") |
| 655 | assert.Equal(tokens[2], "ein") |
| 656 | assert.Equal(tokens[3], "A****loch") |
| 657 | assert.Equal(tokens[4], "!") |
| 658 | assert.Equal(len(tokens), 5) |
| 659 | |
| 660 | // testTokenizerOmission2 |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 661 | tokens = ttokenize(mat_de, w, "F*ck!") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 662 | assert.Equal(tokens[0], "F*ck") |
| 663 | assert.Equal(tokens[1], "!") |
| 664 | assert.Equal(len(tokens), 2) |
| 665 | |
| 666 | // testTokenizerOmission3 () { |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 667 | tokens = ttokenize(mat_de, w, "Dieses verf***** Kleid!") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 668 | assert.Equal(tokens[0], "Dieses") |
| 669 | assert.Equal(tokens[1], "verf*****") |
| 670 | assert.Equal(tokens[2], "Kleid") |
| 671 | assert.Equal(tokens[3], "!") |
| 672 | assert.Equal(len(tokens), 4) |
| 673 | |
| 674 | // Probably interpreted as HOST |
| 675 | // testTokenizerFileExtension1 |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 676 | tokens = ttokenize(mat_de, w, "Ich habe die readme.txt heruntergeladen") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 677 | assert.Equal(tokens[0], "Ich") |
| 678 | assert.Equal(tokens[1], "habe") |
| 679 | assert.Equal(tokens[2], "die") |
| 680 | assert.Equal(tokens[3], "readme.txt") |
| 681 | assert.Equal(tokens[4], "heruntergeladen") |
| 682 | assert.Equal(len(tokens), 5) |
| 683 | |
| 684 | // Probably interpreted as HOST |
| 685 | // testTokenizerFileExtension2 |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 686 | tokens = ttokenize(mat_de, w, "Nimm die README.TXT!") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 687 | assert.Equal(tokens[0], "Nimm") |
| 688 | assert.Equal(tokens[1], "die") |
| 689 | assert.Equal(tokens[2], "README.TXT") |
| 690 | assert.Equal(tokens[3], "!") |
| 691 | assert.Equal(len(tokens), 4) |
| 692 | |
| 693 | // Probably interpreted as HOST |
| 694 | // testTokenizerFileExtension3 |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 695 | tokens = ttokenize(mat_de, w, "Zeig mir profile.jpeg") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 696 | assert.Equal(tokens[0], "Zeig") |
| 697 | assert.Equal(tokens[1], "mir") |
| 698 | assert.Equal(tokens[2], "profile.jpeg") |
| 699 | assert.Equal(len(tokens), 3) |
| 700 | |
| 701 | // testTokenizerFile1 |
| 702 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 703 | tokens = ttokenize(mat_de, w, "Zeig mir c:\\Dokumente\\profile.docx") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 704 | assert.Equal(tokens[0], "Zeig") |
| 705 | assert.Equal(tokens[1], "mir") |
| 706 | assert.Equal(tokens[2], "c:\\Dokumente\\profile.docx") |
| 707 | assert.Equal(len(tokens), 3) |
| 708 | |
| 709 | // testTokenizerFile2 |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 710 | tokens = ttokenize(mat_de, w, "Gehe zu /Dokumente/profile.docx") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 711 | assert.Equal(tokens[0], "Gehe") |
| 712 | assert.Equal(tokens[1], "zu") |
| 713 | assert.Equal(tokens[2], "/Dokumente/profile.docx") |
| 714 | assert.Equal(len(tokens), 3) |
| 715 | |
| 716 | // testTokenizerFile3 |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 717 | tokens = ttokenize(mat_de, w, "Zeig mir c:\\Dokumente\\profile.jpeg") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 718 | assert.Equal(tokens[0], "Zeig") |
| 719 | assert.Equal(tokens[1], "mir") |
| 720 | assert.Equal(tokens[2], "c:\\Dokumente\\profile.jpeg") |
| 721 | assert.Equal(len(tokens), 3) |
| 722 | // Ignored in KorAP-Tokenizer |
| 723 | |
| 724 | // testTokenizerPunct |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 725 | tokens = ttokenize(mat_de, w, "Er sagte: \"Es geht mir gut!\", daraufhin ging er.") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 726 | assert.Equal(tokens[0], "Er") |
| 727 | assert.Equal(tokens[1], "sagte") |
| 728 | assert.Equal(tokens[2], ":") |
| 729 | assert.Equal(tokens[3], "\"") |
| 730 | assert.Equal(tokens[4], "Es") |
| 731 | assert.Equal(tokens[5], "geht") |
| 732 | assert.Equal(tokens[6], "mir") |
| 733 | assert.Equal(tokens[7], "gut") |
| 734 | assert.Equal(tokens[8], "!") |
| 735 | assert.Equal(tokens[9], "\"") |
| 736 | assert.Equal(tokens[10], ",") |
| 737 | assert.Equal(tokens[11], "daraufhin") |
| 738 | assert.Equal(tokens[12], "ging") |
| 739 | assert.Equal(tokens[13], "er") |
| 740 | assert.Equal(tokens[14], ".") |
| 741 | assert.Equal(len(tokens), 15) |
| 742 | |
| 743 | // testTokenizerPlusAmpersand |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 744 | tokens = ttokenize(mat_de, w, ""Das ist von C&A!"") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 745 | assert.Equal(tokens[0], """) |
| 746 | assert.Equal(tokens[1], "Das") |
| 747 | assert.Equal(tokens[2], "ist") |
| 748 | assert.Equal(tokens[3], "von") |
| 749 | assert.Equal(tokens[4], "C&A") |
| 750 | assert.Equal(tokens[5], "!") |
| 751 | assert.Equal(tokens[6], """) |
| 752 | assert.Equal(len(tokens), 7) |
| 753 | |
| 754 | // testTokenizerLongEnd |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 755 | tokens = ttokenize(mat_de, w, "Siehst Du?!!?") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 756 | assert.Equal(tokens[0], "Siehst") |
| 757 | assert.Equal(tokens[1], "Du") |
| 758 | assert.Equal(tokens[2], "?!!?") |
| 759 | assert.Equal(len(tokens), 3) |
| 760 | |
| 761 | // testTokenizerIrishO |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 762 | tokens = ttokenize(mat_de, w, "Peter O'Toole") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 763 | assert.Equal(tokens[0], "Peter") |
| 764 | assert.Equal(tokens[1], "O'Toole") |
| 765 | assert.Equal(len(tokens), 2) |
| 766 | |
| 767 | // testTokenizerAbr |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 768 | tokens = ttokenize(mat_de, w, "Früher bzw. später ...") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 769 | assert.Equal(tokens[0], "Früher") |
| 770 | assert.Equal(tokens[1], "bzw.") |
| 771 | assert.Equal(tokens[2], "später") |
| 772 | assert.Equal(tokens[3], "...") |
| 773 | assert.Equal(len(tokens), 4) |
| 774 | |
| 775 | // testTokenizerUppercaseRule |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 776 | tokens = ttokenize(mat_de, w, "Es war spät.Morgen ist es früh.") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 777 | assert.Equal(tokens[0], "Es") |
| 778 | assert.Equal(tokens[1], "war") |
| 779 | assert.Equal(tokens[2], "spät") |
| 780 | assert.Equal(tokens[3], ".") |
| 781 | assert.Equal(tokens[4], "Morgen") |
| 782 | assert.Equal(tokens[5], "ist") |
| 783 | assert.Equal(tokens[6], "es") |
| 784 | assert.Equal(tokens[7], "früh") |
| 785 | assert.Equal(tokens[8], ".") |
| 786 | assert.Equal(len(tokens), 9) |
| 787 | // Ignored in KorAP-Tokenizer |
| 788 | |
| 789 | // testTokenizerOrd |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 790 | tokens = ttokenize(mat_de, w, "Sie erreichte den 1. Platz!") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 791 | assert.Equal(tokens[0], "Sie") |
| 792 | assert.Equal(tokens[1], "erreichte") |
| 793 | assert.Equal(tokens[2], "den") |
| 794 | assert.Equal(tokens[3], "1.") |
| 795 | assert.Equal(tokens[4], "Platz") |
| 796 | assert.Equal(tokens[5], "!") |
| 797 | assert.Equal(len(tokens), 6) |
| 798 | |
| 799 | // testNoZipOuputArchive |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 800 | tokens = ttokenize(mat_de, w, "Archive: Ich bin kein zip\n") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 801 | assert.Equal(tokens[0], "Archive") |
| 802 | assert.Equal(tokens[1], ":") |
| 803 | assert.Equal(tokens[2], "Ich") |
| 804 | assert.Equal(tokens[3], "bin") |
| 805 | assert.Equal(tokens[4], "kein") |
| 806 | assert.Equal(tokens[5], "zip") |
| 807 | assert.Equal(6, len(tokens)) |
| 808 | |
| 809 | // testTokenizerStrasse |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 810 | tokens = ttokenize(mat_de, w, "Ich wohne in der Weststr. und Du?") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 811 | assert.Equal(tokens[4], "Weststr.") |
| 812 | assert.Equal(8, len(tokens)) |
| 813 | |
| 814 | // germanTokenizerKnowsGermanOmissionWords |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 815 | tokens = ttokenize(mat_de, w, "D'dorf Ku'damm Lu'hafen M'gladbach W'schaft") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 816 | assert.Equal("D'dorf", tokens[0]) |
| 817 | assert.Equal("Ku'damm", tokens[1]) |
| 818 | assert.Equal("Lu'hafen", tokens[2]) |
| 819 | assert.Equal("M'gladbach", tokens[3]) |
| 820 | assert.Equal("W'schaft", tokens[4]) |
| 821 | assert.Equal(5, len(tokens)) |
| 822 | |
| 823 | // germanTokenizerDoesNOTSeparateGermanContractions |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 824 | tokens = ttokenize(mat_de, w, "mach's macht's was'n ist's haste willste kannste biste kriegste") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 825 | assert.Equal("mach's", tokens[0]) |
| 826 | assert.Equal("macht's", tokens[1]) |
| 827 | assert.Equal("was'n", tokens[2]) |
| 828 | assert.Equal("ist's", tokens[3]) |
| 829 | assert.Equal("haste", tokens[4]) |
| 830 | assert.Equal("willste", tokens[5]) |
| 831 | assert.Equal("kannste", tokens[6]) |
| 832 | assert.Equal("biste", tokens[7]) |
| 833 | assert.Equal("kriegste", tokens[8]) |
| 834 | assert.Equal(9, len(tokens)) |
| 835 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 836 | tokens = ttokenize(mat_de, w, "Es ist gleich 2:30 Uhr.") |
Akron | 78dba06 | 2021-10-28 19:30:46 +0200 | [diff] [blame] | 837 | assert.Equal("Es", tokens[0]) |
| 838 | assert.Equal("ist", tokens[1]) |
| 839 | assert.Equal("gleich", tokens[2]) |
| 840 | assert.Equal("2:30", tokens[3]) |
| 841 | assert.Equal("Uhr", tokens[4]) |
| 842 | assert.Equal(".", tokens[5]) |
| 843 | assert.Equal(6, len(tokens)) |
| 844 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 845 | tokens = ttokenize(mat_de, w, "Sie schwamm die Strecke in 00:00:57,34 00:57,341 0:57 Stunden.") |
Akron | 17984c8 | 2021-10-30 11:44:37 +0200 | [diff] [blame] | 846 | assert.Equal("Sie", tokens[0]) |
| 847 | assert.Equal("schwamm", tokens[1]) |
| 848 | assert.Equal("die", tokens[2]) |
| 849 | assert.Equal("Strecke", tokens[3]) |
| 850 | assert.Equal("in", tokens[4]) |
| 851 | assert.Equal("00:00:57,34", tokens[5]) |
| 852 | assert.Equal("00:57,341", tokens[6]) |
| 853 | assert.Equal("0:57", tokens[7]) |
| 854 | assert.Equal("Stunden", tokens[8]) |
| 855 | assert.Equal(".", tokens[9]) |
| 856 | assert.Equal(10, len(tokens)) |
| 857 | |
Akron | f1106ec | 2021-11-05 13:04:44 +0100 | [diff] [blame] | 858 | // waste example |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 859 | tokens = ttokenize(mat_de, w, "Am 24.1.1806 feierte E. T. A. Hoffmann seinen 30. Geburtstag.") |
Akron | f1106ec | 2021-11-05 13:04:44 +0100 | [diff] [blame] | 860 | assert.Equal(tokens[0], "Am") |
| 861 | assert.Equal(tokens[1], "24.1.1806") |
| 862 | assert.Equal(tokens[2], "feierte") |
| 863 | assert.Equal(tokens[3], "E.") |
| 864 | assert.Equal(tokens[4], "T.") |
| 865 | assert.Equal(tokens[5], "A.") |
| 866 | assert.Equal(tokens[6], "Hoffmann") |
| 867 | assert.Equal(tokens[7], "seinen") |
| 868 | assert.Equal(tokens[8], "30.") |
| 869 | assert.Equal(tokens[9], "Geburtstag") |
| 870 | assert.Equal(tokens[10], ".") |
| 871 | assert.Equal(11, len(tokens)) |
| 872 | |
Akron | 9135b20 | 2021-11-06 13:16:07 +0100 | [diff] [blame] | 873 | // IPtest |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 874 | tokens = ttokenize(mat_de, w, "Meine IP ist 192.178.168.55.") |
Akron | 9135b20 | 2021-11-06 13:16:07 +0100 | [diff] [blame] | 875 | assert.Equal(tokens[0], "Meine") |
| 876 | assert.Equal(tokens[1], "IP") |
| 877 | assert.Equal(tokens[2], "ist") |
| 878 | assert.Equal(tokens[3], "192.178.168.55") |
| 879 | assert.Equal(tokens[4], ".") |
| 880 | assert.Equal(5, len(tokens)) |
| 881 | |
Akron | 6742b96 | 2021-11-09 01:17:20 +0100 | [diff] [blame] | 882 | // XML entities |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 883 | tokens = ttokenize(mat_de, w, "Das ist 1:30 Stunden&20 Minuten zu spät >.") |
Akron | 6742b96 | 2021-11-09 01:17:20 +0100 | [diff] [blame] | 884 | assert.Equal(tokens[0], "Das") |
| 885 | assert.Equal(tokens[1], "ist") |
| 886 | assert.Equal(tokens[2], " ") |
| 887 | assert.Equal(tokens[3], "1:30") |
| 888 | assert.Equal(tokens[4], "Stunden") |
| 889 | assert.Equal(tokens[5], "&") |
| 890 | assert.Equal(tokens[6], "20") |
| 891 | assert.Equal(tokens[7], "Minuten") |
| 892 | assert.Equal(tokens[8], "zu") |
| 893 | assert.Equal(tokens[9], "spät") |
| 894 | assert.Equal(tokens[10], ">") |
| 895 | assert.Equal(tokens[11], ".") |
| 896 | assert.Equal(12, len(tokens)) |
| 897 | |
Akron | 936c0f5 | 2021-12-07 11:30:53 +0100 | [diff] [blame] | 898 | // Plusampersand compounds (1) |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 899 | tokens = ttokenize(mat_de, w, "Die 2G+-Regel soll weitere Covid-19-Erkrankungen reduzieren.") |
Akron | e62e8eb | 2021-12-03 11:59:53 +0100 | [diff] [blame] | 900 | assert.Equal(tokens[0], "Die") |
| 901 | assert.Equal(tokens[1], "2G+-Regel") |
| 902 | assert.Equal(tokens[2], "soll") |
| 903 | assert.Equal(tokens[3], "weitere") |
| 904 | assert.Equal(tokens[4], "Covid-19-Erkrankungen") |
| 905 | assert.Equal(tokens[5], "reduzieren") |
| 906 | assert.Equal(tokens[6], ".") |
| 907 | assert.Equal(7, len(tokens)) |
| 908 | |
Akron | 936c0f5 | 2021-12-07 11:30:53 +0100 | [diff] [blame] | 909 | // Plusampersand compounds (2) |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 910 | tokens = ttokenize(mat_de, w, "Der Neu-C++-Programmierer.") |
Akron | 936c0f5 | 2021-12-07 11:30:53 +0100 | [diff] [blame] | 911 | assert.Equal(tokens[0], "Der") |
| 912 | assert.Equal(tokens[1], "Neu-C++-Programmierer") |
| 913 | assert.Equal(tokens[2], ".") |
| 914 | assert.Equal(3, len(tokens)) |
| 915 | |
Akron | 54ed7e7 | 2022-01-04 12:05:00 +0100 | [diff] [blame] | 916 | // z.B. |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 917 | tokens = ttokenize(mat_de, w, "Dies sind z.B. zwei Wörter - z. B. auch.") |
Akron | 54ed7e7 | 2022-01-04 12:05:00 +0100 | [diff] [blame] | 918 | assert.Equal(tokens[0], "Dies") |
| 919 | assert.Equal(tokens[1], "sind") |
| 920 | assert.Equal(tokens[2], "z.") |
| 921 | assert.Equal(tokens[3], "B.") |
| 922 | assert.Equal(tokens[4], "zwei") |
| 923 | assert.Equal(tokens[5], "Wörter") |
| 924 | assert.Equal(tokens[6], "-") |
| 925 | assert.Equal(tokens[7], "z.") |
| 926 | assert.Equal(tokens[8], "B.") |
| 927 | assert.Equal(tokens[9], "auch") |
| 928 | assert.Equal(tokens[10], ".") |
| 929 | assert.Equal(11, len(tokens)) |
| 930 | |
Akron | 9a59471 | 2022-01-14 11:12:21 +0100 | [diff] [blame] | 931 | // z.B. |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 932 | tokens = ttokenize(mat_de, w, "Dies sind z.B. zwei Wörter - z. B. auch.") |
Akron | 9a59471 | 2022-01-14 11:12:21 +0100 | [diff] [blame] | 933 | assert.Equal(tokens[0], "Dies") |
| 934 | assert.Equal(tokens[1], "sind") |
| 935 | assert.Equal(tokens[2], "z.") |
| 936 | assert.Equal(tokens[3], "B.") |
| 937 | assert.Equal(tokens[4], "zwei") |
| 938 | assert.Equal(tokens[5], "Wörter") |
| 939 | assert.Equal(tokens[6], "-") |
| 940 | assert.Equal(tokens[7], "z.") |
| 941 | assert.Equal(tokens[8], "B.") |
| 942 | assert.Equal(tokens[9], "auch") |
| 943 | assert.Equal(tokens[10], ".") |
| 944 | assert.Equal(11, len(tokens)) |
| 945 | |
| 946 | // Single quote handling |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 947 | tokens = ttokenize(mat_de, w, "Es heißt 'Leitungssportteams' und nicht anders.") |
Akron | 9a59471 | 2022-01-14 11:12:21 +0100 | [diff] [blame] | 948 | assert.Equal(tokens[0], "Es") |
| 949 | assert.Equal(tokens[1], "heißt") |
| 950 | assert.Equal(tokens[2], "'") |
| 951 | assert.Equal(tokens[3], "Leitungssportteams") |
| 952 | assert.Equal(tokens[4], "'") |
| 953 | assert.Equal(tokens[5], "und") |
| 954 | assert.Equal(tokens[6], "nicht") |
| 955 | assert.Equal(tokens[7], "anders") |
| 956 | assert.Equal(tokens[8], ".") |
| 957 | assert.Equal(9, len(tokens)) |
| 958 | |
Akron | b02ad07 | 2022-01-19 12:41:44 +0100 | [diff] [blame] | 959 | // Apostrophe handling |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 960 | tokens = ttokenize(mat_de, w, "Das ist Nils’ Einkaufskorb bei McDonald's.") |
Akron | b02ad07 | 2022-01-19 12:41:44 +0100 | [diff] [blame] | 961 | assert.Equal(tokens[0], "Das") |
| 962 | assert.Equal(tokens[1], "ist") |
| 963 | assert.Equal(tokens[2], "Nils’") |
| 964 | assert.Equal(tokens[3], "Einkaufskorb") |
| 965 | assert.Equal(tokens[4], "bei") |
| 966 | assert.Equal(tokens[5], "McDonald's") |
| 967 | assert.Equal(tokens[6], ".") |
| 968 | assert.Equal(7, len(tokens)) |
| 969 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 970 | } |
| 971 | |
| 972 | func TestMatrixFullTokenizerTokenSplitterEN(t *testing.T) { |
| 973 | assert := assert.New(t) |
| 974 | |
| 975 | if mat_en == nil { |
| 976 | mat_en = LoadMatrixFile("testdata/tokenizer_en.matok") |
| 977 | } |
| 978 | |
| 979 | b := make([]byte, 0, 2048) |
| 980 | w := bytes.NewBuffer(b) |
| 981 | var tokens []string |
| 982 | |
| 983 | // testEnglishTokenizerScienceAbbreviations |
| 984 | tokens = ttokenize(mat_en, 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.") |
| 985 | assert.Equal("Approx.", tokens[0]) |
| 986 | assert.Equal("in", tokens[1]) |
| 987 | assert.Equal("Sept.", tokens[2]) |
| 988 | assert.Equal("1954", tokens[3]) |
| 989 | assert.Equal(",", tokens[4]) |
| 990 | assert.Equal("Assoc.", tokens[5]) |
| 991 | assert.Equal("Prof.", tokens[6]) |
| 992 | assert.Equal("Dr.", tokens[7]) |
| 993 | assert.Equal("R.", tokens[8]) |
| 994 | assert.Equal("J.", tokens[9]) |
| 995 | assert.Equal("Ewing", tokens[10]) |
| 996 | assert.Equal("reviewed", tokens[11]) |
| 997 | assert.Equal("articles", tokens[12]) |
| 998 | assert.Equal("on", tokens[13]) |
| 999 | assert.Equal("Enzymol.", tokens[14]) |
| 1000 | assert.Equal("Bacteriol.", tokens[15]) |
| 1001 | assert.Equal("effects", tokens[16]) |
| 1002 | assert.Equal("later", tokens[17]) |
| 1003 | assert.Equal("published", tokens[18]) |
| 1004 | assert.Equal("in", tokens[19]) |
| 1005 | assert.Equal("Nutr.", tokens[20]) |
| 1006 | assert.Equal("Rheumatol.", tokens[21]) |
| 1007 | assert.Equal("No.", tokens[22]) |
| 1008 | assert.Equal("12", tokens[23]) |
| 1009 | assert.Equal("and", tokens[24]) |
| 1010 | assert.Equal("Nº.", tokens[25]) |
| 1011 | assert.Equal("13.", tokens[26]) |
| 1012 | assert.Equal(",", tokens[27]) |
| 1013 | assert.Equal("pp.", tokens[28]) |
| 1014 | assert.Equal("17-18", tokens[29]) |
| 1015 | assert.Equal(".", tokens[30]) |
| 1016 | /* |
| 1017 | |
| 1018 | // englishTokenizerCanGuessWhetherIIsAbbrev |
| 1019 | tokens = ttokenize(mat_en, w, "M. I. Baxter was born during World War I. So was I. He went to the Peter I. Hardy school. So did I.") |
| 1020 | assert.Equal("I.", tokens[1]) |
| 1021 | assert.Equal("I", tokens[8]) |
| 1022 | assert.Equal(".", tokens[9]) |
| 1023 | assert.Equal("I", tokens[12]) |
| 1024 | assert.Equal(".", tokens[13]) |
| 1025 | |
| 1026 | */ |
| 1027 | |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 1028 | /* |
| 1029 | @Test |
| 1030 | public void englishTokenizerSeparatesEnglishContractionsAndClitics () { |
| 1031 | DerekoDfaTokenizer_en tok = new DerekoDfaTokenizer_en(); |
| 1032 | tokens = tokenize(dat, w, "I've we'll you'd I'm we're Peter's isn't") |
| 1033 | assert.Equal("'ve", tokens[1]); |
| 1034 | assert.Equal("'ll", tokens[3]); |
| 1035 | assert.Equal("'d", tokens[5]); |
| 1036 | assert.Equal("'m", tokens[7]); |
| 1037 | assert.Equal("'re", tokens[9]); |
| 1038 | assert.Equal("'s", tokens[11]); |
| 1039 | assert.Equal("is", tokens[12]); |
| 1040 | assert.Equal("n't", tokens[13]); |
| 1041 | assert.Equal(14, len(tokens)); |
| 1042 | } |
| 1043 | |
| 1044 | @Test |
| 1045 | public void frenchTokenizerKnowsFrenchAbbreviations () { |
| 1046 | DerekoDfaTokenizer_fr tok = new DerekoDfaTokenizer_fr(); |
| 1047 | 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.") |
| 1048 | assert.Equal("Approx.", tokens[0]); |
| 1049 | assert.Equal("juill.", tokens[2]); |
| 1050 | assert.Equal("prof.", tokens[5]); |
| 1051 | assert.Equal("exerc.", tokens[15]); |
| 1052 | assert.Equal("no.", tokens[16]); |
| 1053 | assert.Equal("pp.", tokens[21]); |
| 1054 | } |
| 1055 | |
| 1056 | @Test |
| 1057 | public void frenchTokenizerKnowsFrenchContractions () { |
| 1058 | DerekoDfaTokenizer_fr tok = new DerekoDfaTokenizer_fr(); |
| 1059 | tokens = tokenize(dat, w, "J'ai j'habite qu'il d'un jusqu'à Aujourd'hui D'accord Quelqu'un Presqu'île") |
| 1060 | assert.Equal("J'", tokens[0]); |
| 1061 | assert.Equal("j'", tokens[2]); |
| 1062 | assert.Equal("qu'", tokens[4]); |
| 1063 | assert.Equal("d'", tokens[6]); |
| 1064 | assert.Equal("jusqu'", tokens[8]); |
| 1065 | assert.Equal("Aujourd'hui", tokens[10]); |
| 1066 | assert.Equal("D'", tokens[11]); // ’ |
| 1067 | assert.Equal("Quelqu'un", tokens[13]); // ’ |
| 1068 | assert.Equal("Presqu'île", tokens[14]); // ’ |
| 1069 | } |
| 1070 | |
| 1071 | @Test |
| 1072 | public void frenchTokenizerKnowsFrenchClitics () { |
| 1073 | DerekoDfaTokenizer_fr tok = new DerekoDfaTokenizer_fr(); |
| 1074 | tokens = tokenize(dat, w, "suis-je sont-elles ") |
| 1075 | assert.Equal("suis", tokens[0]); |
| 1076 | assert.Equal("-je", tokens[1]); |
| 1077 | assert.Equal("sont", tokens[2]); |
| 1078 | assert.Equal("-elles", tokens[3]); |
| 1079 | } |
| 1080 | |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 1081 | |
| 1082 | @Test |
| 1083 | public void testZipOuputArchive () { |
| 1084 | |
| 1085 | final ByteArrayOutputStream clearOut = new ByteArrayOutputStream(); |
| 1086 | System.setOut(new PrintStream(clearOut)); |
| 1087 | tokens = tokenize(dat, w, "Archive: ich/bin/ein.zip\n") |
| 1088 | assert.Equal(0, len(tokens)); |
| 1089 | } |
| 1090 | */ |
| 1091 | /* |
| 1092 | |
| 1093 | @Test |
| 1094 | public void testTextBreakOutputArchive () throws InstantiationException, IllegalAccessException, ClassNotFoundException { |
| 1095 | DerekoDfaTokenizer_de tok = (DerekoDfaTokenizer_de) new KorapTokenizer.Builder() |
| 1096 | .tokenizerClassName(DerekoDfaTokenizer_de.class.getName()) |
| 1097 | .printOffsets(true) |
| 1098 | .build(); |
| 1099 | Span[] tokens = tok.tokenizePos("Text1\004\nText2 Hallo\004Rumsdibums\004Das freut mich sehr.\n"); |
| 1100 | assert.Equal("Text1", tokens[0].getType()); |
| 1101 | assert.Equal(len(tokens), 9 ); |
| 1102 | } |
| 1103 | */ |
| 1104 | } |
| 1105 | |
Akron | b98e4cf | 2022-03-27 23:56:49 +0200 | [diff] [blame] | 1106 | func TestMatrixEmoticons(t *testing.T) { |
| 1107 | assert := assert.New(t) |
| 1108 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 1109 | if mat_de == nil { |
| 1110 | mat_de = LoadMatrixFile("testdata/tokenizer.matok") |
Akron | b98e4cf | 2022-03-27 23:56:49 +0200 | [diff] [blame] | 1111 | } |
| 1112 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 1113 | assert.NotNil(mat_de) |
Akron | b98e4cf | 2022-03-27 23:56:49 +0200 | [diff] [blame] | 1114 | |
| 1115 | b := make([]byte, 0, 2048) |
| 1116 | w := bytes.NewBuffer(b) |
| 1117 | var tokens []string |
| 1118 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 1119 | tokens = ttokenize(mat_de, w, ":-* ;) :)) :*( ^___^ T__T ^^; -_-;;; -_-^") |
Akron | b98e4cf | 2022-03-27 23:56:49 +0200 | [diff] [blame] | 1120 | assert.Equal(tokens[0], ":-*") |
| 1121 | assert.Equal(tokens[1], ";)") |
| 1122 | assert.Equal(tokens[2], ":))") |
| 1123 | assert.Equal(tokens[3], ":*(") |
| 1124 | assert.Equal(tokens[4], "^___^") |
| 1125 | assert.Equal(tokens[5], "T__T") |
| 1126 | assert.Equal(tokens[6], "^^;") |
| 1127 | assert.Equal(tokens[7], "-_-;;;") |
| 1128 | assert.Equal(tokens[8], "-_-^") |
| 1129 | assert.Equal(len(tokens), 9) |
Akron | 6dcb6ce | 2022-04-09 16:09:51 +0200 | [diff] [blame] | 1130 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 1131 | tokens = ttokenize(mat_de, w, "das -> Lustig<-!") |
Akron | 6dcb6ce | 2022-04-09 16:09:51 +0200 | [diff] [blame] | 1132 | assert.Equal("das", tokens[0]) |
| 1133 | assert.Equal("->", tokens[1]) |
| 1134 | assert.Equal("Lustig", tokens[2]) |
| 1135 | assert.Equal("<-", tokens[3]) |
| 1136 | assert.Equal("!", tokens[4]) |
| 1137 | assert.Equal(5, len(tokens)) |
Akron | b98e4cf | 2022-03-27 23:56:49 +0200 | [diff] [blame] | 1138 | } |
| 1139 | |
Akron | c9c0eae | 2021-10-22 19:49:43 +0200 | [diff] [blame] | 1140 | func TestMatrixFullTokenizerXML(t *testing.T) { |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 1141 | assert := assert.New(t) |
| 1142 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 1143 | if mat_de == nil { |
| 1144 | mat_de = LoadMatrixFile("testdata/tokenizer.matok") |
Akron | 9fb63af | 2021-10-28 01:15:53 +0200 | [diff] [blame] | 1145 | } |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 1146 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 1147 | assert.NotNil(mat_de) |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 1148 | |
| 1149 | b := make([]byte, 0, 2048) |
| 1150 | w := bytes.NewBuffer(b) |
| 1151 | var tokens []string |
| 1152 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 1153 | tokens = ttokenize(mat_de, w, "Das <b>beste</b> Fußballspiel") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 1154 | assert.Equal("Das", tokens[0]) |
| 1155 | assert.Equal("<b>", tokens[1]) |
| 1156 | assert.Equal("beste", tokens[2]) |
| 1157 | assert.Equal("</b>", tokens[3]) |
| 1158 | assert.Equal("Fußballspiel", tokens[4]) |
| 1159 | assert.Equal(5, len(tokens)) |
| 1160 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 1161 | tokens = ttokenize(mat_de, w, "Das <b class=\"c\">beste</b> Fußballspiel") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 1162 | assert.Equal("Das", tokens[0]) |
| 1163 | assert.Equal("<b class=\"c\">", tokens[1]) |
| 1164 | assert.Equal("beste", tokens[2]) |
| 1165 | assert.Equal("</b>", tokens[3]) |
| 1166 | assert.Equal("Fußballspiel", tokens[4]) |
| 1167 | assert.Equal(5, len(tokens)) |
| 1168 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 1169 | tokens = ttokenize(mat_de, w, "der<x y=\"alte \"> <x x> alte</x> etc. et. Mann.") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 1170 | assert.Equal("der", tokens[0]) |
| 1171 | assert.Equal("<x y=\"alte \">", tokens[1]) |
| 1172 | assert.Equal("<x x>", tokens[2]) |
| 1173 | assert.Equal("alte", tokens[3]) |
| 1174 | assert.Equal("</x>", tokens[4]) |
| 1175 | assert.Equal("etc.", tokens[5]) |
| 1176 | assert.Equal("et", tokens[6]) |
| 1177 | assert.Equal(".", tokens[7]) |
| 1178 | assert.Equal("Mann", tokens[8]) |
| 1179 | assert.Equal(".", tokens[9]) |
| 1180 | assert.Equal(10, len(tokens)) |
Akron | 066d99c | 2021-10-28 19:04:59 +0200 | [diff] [blame] | 1181 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 1182 | tokens = ttokenize(mat_de, w, "das<br class=\"br\" />ging.") |
Akron | 066d99c | 2021-10-28 19:04:59 +0200 | [diff] [blame] | 1183 | assert.Equal("das", tokens[0]) |
| 1184 | assert.Equal("<br class=\"br\" />", tokens[1]) |
| 1185 | assert.Equal("ging", tokens[2]) |
| 1186 | assert.Equal(".", tokens[3]) |
| 1187 | assert.Equal(4, len(tokens)) |
Akron | d47c67e | 2022-04-10 11:02:59 +0200 | [diff] [blame] | 1188 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 1189 | tokens = ttokenize(mat_de, w, "das <?robot xgh ?> <!-- hm hm --> <![CDATA[ cdata ]]> <br />") |
Akron | d47c67e | 2022-04-10 11:02:59 +0200 | [diff] [blame] | 1190 | assert.Equal("das", tokens[0]) |
| 1191 | assert.Equal("<?robot", tokens[1]) |
| 1192 | assert.Equal("xgh", tokens[2]) |
| 1193 | assert.Equal("?>", tokens[3]) |
| 1194 | assert.Equal("<!--", tokens[4]) |
| 1195 | assert.Equal("hm", tokens[5]) |
| 1196 | assert.Equal("hm", tokens[6]) |
| 1197 | assert.Equal("-->", tokens[7]) |
| 1198 | assert.Equal("<![CDATA[", tokens[8]) |
| 1199 | assert.Equal("cdata", tokens[9]) |
| 1200 | assert.Equal("]]>", tokens[10]) |
| 1201 | assert.Equal("<br />", tokens[11]) |
| 1202 | assert.Equal(12, len(tokens)) |
| 1203 | |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 1204 | } |
| 1205 | |
Akron | abcb6a5 | 2021-10-09 15:52:08 +0200 | [diff] [blame] | 1206 | func TestMatokDatokEquivalence(t *testing.T) { |
| 1207 | assert := assert.New(t) |
| 1208 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 1209 | if mat_de == nil { |
| 1210 | mat_de = LoadMatrixFile("testdata/tokenizer.matok") |
Akron | 9fb63af | 2021-10-28 01:15:53 +0200 | [diff] [blame] | 1211 | } |
Akron | abcb6a5 | 2021-10-09 15:52:08 +0200 | [diff] [blame] | 1212 | dat := LoadDatokFile("testdata/tokenizer.datok") |
| 1213 | |
| 1214 | r := strings.NewReader(s) |
| 1215 | |
| 1216 | tb := make([]byte, 0, 2048) |
| 1217 | w := bytes.NewBuffer(tb) |
| 1218 | |
| 1219 | // Transduce with double array representation |
| 1220 | dat.Transduce(r, w) |
| 1221 | |
| 1222 | datStr := w.String() |
| 1223 | |
| 1224 | r.Reset(s) |
| 1225 | w.Reset() |
| 1226 | |
| 1227 | // Transduce with matrix representation |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 1228 | mat_de.Transduce(r, w) |
Akron | abcb6a5 | 2021-10-09 15:52:08 +0200 | [diff] [blame] | 1229 | |
| 1230 | matStr := w.String() |
| 1231 | |
| 1232 | assert.Equal(datStr, matStr) |
| 1233 | } |
| 1234 | |
Akron | c9c0eae | 2021-10-22 19:49:43 +0200 | [diff] [blame] | 1235 | func TestMatrixFullTokenizerCallbackTransduce(t *testing.T) { |
Akron | e396a93 | 2021-10-19 01:06:13 +0200 | [diff] [blame] | 1236 | assert := assert.New(t) |
| 1237 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 1238 | if mat_de == nil { |
| 1239 | mat_de = LoadMatrixFile("testdata/tokenizer.matok") |
Akron | 9fb63af | 2021-10-28 01:15:53 +0200 | [diff] [blame] | 1240 | } |
Akron | e396a93 | 2021-10-19 01:06:13 +0200 | [diff] [blame] | 1241 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 1242 | assert.NotNil(mat_de) |
Akron | e396a93 | 2021-10-19 01:06:13 +0200 | [diff] [blame] | 1243 | |
| 1244 | b := make([]byte, 0, 2048) |
| 1245 | w := bytes.NewBuffer(b) |
Akron | e396a93 | 2021-10-19 01:06:13 +0200 | [diff] [blame] | 1246 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 1247 | assert.True(mat_de.Transduce(strings.NewReader("Der alte Baum. Er war schon alt."), w)) |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 1248 | |
| 1249 | matStr := w.String() |
| 1250 | |
| 1251 | assert.Equal("Der\nalte\nBaum\n.\n\nEr\nwar\nschon\nalt\n.\n\n\n", matStr) |
| 1252 | } |
| 1253 | |
Akron | c9c0eae | 2021-10-22 19:49:43 +0200 | [diff] [blame] | 1254 | func TestMatrixFullTokenizerTextTreatment(t *testing.T) { |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 1255 | assert := assert.New(t) |
| 1256 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 1257 | if mat_de == nil { |
| 1258 | mat_de = LoadMatrixFile("testdata/tokenizer.matok") |
Akron | 9fb63af | 2021-10-28 01:15:53 +0200 | [diff] [blame] | 1259 | } |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 1260 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 1261 | assert.NotNil(mat_de) |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 1262 | |
| 1263 | b := make([]byte, 0, 2048) |
| 1264 | w := bytes.NewBuffer(b) |
| 1265 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 1266 | assert.True(mat_de.Transduce(strings.NewReader("Erste.\n\n\n\n\x04\x0aNächst.\x04"), w)) |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 1267 | matStr := w.String() |
| 1268 | assert.Equal("Erste\n.\n\n\nNächst\n.\n\n\n", matStr) |
Akron | f6bdfdb | 2021-10-23 15:56:53 +0200 | [diff] [blame] | 1269 | } |
Akron | a854faa | 2021-10-22 19:31:08 +0200 | [diff] [blame] | 1270 | |
Akron | 22c565a | 2021-11-28 17:31:36 +0100 | [diff] [blame] | 1271 | func TestMatrixFullTokenizerLongText(t *testing.T) { |
| 1272 | assert := assert.New(t) |
| 1273 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 1274 | if mat_de == nil { |
| 1275 | mat_de = LoadMatrixFile("testdata/tokenizer.matok") |
Akron | 22c565a | 2021-11-28 17:31:36 +0100 | [diff] [blame] | 1276 | } |
| 1277 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 1278 | assert.NotNil(mat_de) |
Akron | 22c565a | 2021-11-28 17:31:36 +0100 | [diff] [blame] | 1279 | |
| 1280 | b := make([]byte, 0, 2048) |
| 1281 | w := bytes.NewBuffer(b) |
| 1282 | |
| 1283 | text := `The Project Gutenberg EBook of Effi Briest, by Theodor Fontane |
| 1284 | |
| 1285 | Copyright laws are changing all over the world. Be sure to check the |
| 1286 | copyright laws for your country before downloading or redistributing |
| 1287 | this or any other Project Gutenberg eBook. |
| 1288 | |
| 1289 | This header should be the first thing seen when viewing this Project |
| 1290 | Gutenberg file. Please do not remove it. Do not change or edit the |
| 1291 | header without written permission. |
| 1292 | |
| 1293 | Please read the "legal small print," and other information about the |
| 1294 | eBook and Project Gutenberg at the bottom of this file. Included is |
| 1295 | important information about your specific rights and restrictions in |
| 1296 | how the file may be used. You can also find out about how to make a |
| 1297 | donation to Project Gutenberg, and how to get involved. |
| 1298 | |
| 1299 | |
| 1300 | **Welcome To The World of Free Plain Vanilla Electronic Texts** |
| 1301 | |
| 1302 | **eBooks Readable By Both Humans and By Computers, Since 1971** |
| 1303 | |
| 1304 | *****These eBooks Were Prepared By Thousands of Volunteers!***** |
| 1305 | |
| 1306 | |
| 1307 | Title: Effi Briest |
| 1308 | |
| 1309 | Author: Theodor Fontane |
| 1310 | |
| 1311 | Release Date: March, 2004 [EBook #5323] |
| 1312 | ` |
| 1313 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 1314 | assert.True(mat_de.Transduce(strings.NewReader(text), w)) |
Akron | 22c565a | 2021-11-28 17:31:36 +0100 | [diff] [blame] | 1315 | |
| 1316 | assert.True(strings.Contains(w.String(), "Release")) |
| 1317 | } |
| 1318 | |
Akron | f6bdfdb | 2021-10-23 15:56:53 +0200 | [diff] [blame] | 1319 | func TestMatrixTrimming(t *testing.T) { |
| 1320 | assert := assert.New(t) |
| 1321 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 1322 | if mat_de == nil { |
| 1323 | mat_de = LoadMatrixFile("testdata/tokenizer.matok") |
Akron | 9fb63af | 2021-10-28 01:15:53 +0200 | [diff] [blame] | 1324 | } |
Akron | f6bdfdb | 2021-10-23 15:56:53 +0200 | [diff] [blame] | 1325 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 1326 | assert.NotNil(mat_de) |
Akron | f6bdfdb | 2021-10-23 15:56:53 +0200 | [diff] [blame] | 1327 | |
| 1328 | b := make([]byte, 0, 2048) |
| 1329 | w := bytes.NewBuffer(b) |
| 1330 | |
Akron | be3d366 | 2023-04-26 13:22:38 +0200 | [diff] [blame^] | 1331 | assert.True(mat_de.Transduce(strings.NewReader(" Erste."), w)) |
Akron | f6bdfdb | 2021-10-23 15:56:53 +0200 | [diff] [blame] | 1332 | matStr := w.String() |
| 1333 | assert.Equal("Erste\n.\n\n\n", matStr) |
Akron | e396a93 | 2021-10-19 01:06:13 +0200 | [diff] [blame] | 1334 | } |
| 1335 | |
Akron | c9c0eae | 2021-10-22 19:49:43 +0200 | [diff] [blame] | 1336 | func BenchmarkMatrixTransduce(b *testing.B) { |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 1337 | bu := make([]byte, 0, 2048) |
| 1338 | w := bytes.NewBuffer(bu) |
| 1339 | |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 1340 | r := strings.NewReader(s) |
| 1341 | |
Akron | 094a4e8 | 2021-10-02 18:37:00 +0200 | [diff] [blame] | 1342 | mat := LoadMatrixFile("testdata/tokenizer.matok") |
Akron | 28031b7 | 2021-10-02 13:07:25 +0200 | [diff] [blame] | 1343 | |
| 1344 | b.ResetTimer() |
| 1345 | |
| 1346 | for i := 0; i < b.N; i++ { |
| 1347 | w.Reset() |
| 1348 | r.Reset(s) |
| 1349 | ok := mat.Transduce(r, w) |
| 1350 | if !ok { |
| 1351 | fmt.Println("Fail!") |
| 1352 | fmt.Println(w.String()) |
| 1353 | os.Exit(1) |
| 1354 | } |
| 1355 | } |
| 1356 | } |