summaryrefslogtreecommitdiffstats
path: root/web/server/h2o/libh2o/misc/oktavia/src/stemmer/danish-stemmer.jsx
blob: ffebd8815ac266d5338f7bad4da2f7db70063607 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
// This file was generated automatically by the Snowball to JSX compiler

import "base-stemmer.jsx";
import "among.jsx";

 /**
  * This class was automatically generated by a Snowball to JSX compiler
  * It implements the stemming algorithm defined by a snowball script.
  */

class DanishStemmer extends BaseStemmer
{
    static const serialVersionUID = 1;
    static const methodObject = new DanishStemmer();

    static const a_0 = [
        new Among("hed", -1, 1),
        new Among("ethed", 0, 1),
        new Among("ered", -1, 1),
        new Among("e", -1, 1),
        new Among("erede", 3, 1),
        new Among("ende", 3, 1),
        new Among("erende", 5, 1),
        new Among("ene", 3, 1),
        new Among("erne", 3, 1),
        new Among("ere", 3, 1),
        new Among("en", -1, 1),
        new Among("heden", 10, 1),
        new Among("eren", 10, 1),
        new Among("er", -1, 1),
        new Among("heder", 13, 1),
        new Among("erer", 13, 1),
        new Among("s", -1, 2),
        new Among("heds", 16, 1),
        new Among("es", 16, 1),
        new Among("endes", 18, 1),
        new Among("erendes", 19, 1),
        new Among("enes", 18, 1),
        new Among("ernes", 18, 1),
        new Among("eres", 18, 1),
        new Among("ens", 16, 1),
        new Among("hedens", 24, 1),
        new Among("erens", 24, 1),
        new Among("ers", 16, 1),
        new Among("ets", 16, 1),
        new Among("erets", 28, 1),
        new Among("et", -1, 1),
        new Among("eret", 30, 1)
    ];

    static const a_1 = [
        new Among("gd", -1, -1),
        new Among("dt", -1, -1),
        new Among("gt", -1, -1),
        new Among("kt", -1, -1)
    ];

    static const a_2 = [
        new Among("ig", -1, 1),
        new Among("lig", 0, 1),
        new Among("elig", 1, 1),
        new Among("els", -1, 1),
        new Among("l\u00F8st", -1, 2)
    ];

    static const g_v = [17, 65, 16, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48, 0, 128] : int[];

    static const g_s_ending = [239, 254, 42, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16] : int[];

    var I_x : int = 0;
    var I_p1 : int = 0;
    var S_ch : string = "";

    function copy_from (other : DanishStemmer) : void
    {
        this.I_x = other.I_x;
        this.I_p1 = other.I_p1;
        this.S_ch = other.S_ch;
        super.copy_from(other);
    }

    function r_mark_regions () : boolean
    {
        var v_1 : int;
        var v_2 : int;
        // (, line 29
        this.I_p1 = this.limit;
        // test, line 33
        v_1 = this.cursor;
        // (, line 33
        // hop, line 33
        {
            var c : int = this.cursor + 3;
            if (0 > c || c > this.limit)
            {
                return false;
            }
            this.cursor = c;
        }
        // setmark x, line 33
        this.I_x = this.cursor;
        this.cursor = v_1;
        // goto, line 34
        golab0: while(true)
        {
            v_2 = this.cursor;
            var lab1 = true;
            lab1: while (lab1 == true)
            {
                lab1 = false;
                if (!(this.in_grouping(DanishStemmer.g_v, 97, 248)))
                {
                    break lab1;
                }
                this.cursor = v_2;
                break golab0;
            }
            this.cursor = v_2;
            if (this.cursor >= this.limit)
            {
                return false;
            }
            this.cursor++;
        }
        // gopast, line 34
        golab2: while(true)
        {
            var lab3 = true;
            lab3: while (lab3 == true)
            {
                lab3 = false;
                if (!(this.out_grouping(DanishStemmer.g_v, 97, 248)))
                {
                    break lab3;
                }
                break golab2;
            }
            if (this.cursor >= this.limit)
            {
                return false;
            }
            this.cursor++;
        }
        // setmark p1, line 34
        this.I_p1 = this.cursor;
        // try, line 35
        var lab4 = true;
        lab4: while (lab4 == true)
        {
            lab4 = false;
            // (, line 35
            if (!(this.I_p1 < this.I_x))
            {
                break lab4;
            }
            this.I_p1 = this.I_x;
        }
        return true;
    }

    function r_main_suffix () : boolean
    {
        var among_var : int;
        var v_1 : int;
        var v_2 : int;
        // (, line 40
        // setlimit, line 41
        v_1 = this.limit - this.cursor;
        // tomark, line 41
        if (this.cursor < this.I_p1)
        {
            return false;
        }
        this.cursor = this.I_p1;
        v_2 = this.limit_backward;
        this.limit_backward = this.cursor;
        this.cursor = this.limit - v_1;
        // (, line 41
        // [, line 41
        this.ket = this.cursor;
        // substring, line 41
        among_var = this.find_among_b(DanishStemmer.a_0, 32);
        if (among_var == 0)
        {
            this.limit_backward = v_2;
            return false;
        }
        // ], line 41
        this.bra = this.cursor;
        this.limit_backward = v_2;
        switch (among_var) {
            case 0:
                return false;
            case 1:
                // (, line 48
                // delete, line 48
                if (!this.slice_del())
                {
                    return false;
                }
                break;
            case 2:
                // (, line 50
                if (!(this.in_grouping_b(DanishStemmer.g_s_ending, 97, 229)))
                {
                    return false;
                }
                // delete, line 50
                if (!this.slice_del())
                {
                    return false;
                }
                break;
        }
        return true;
    }

    function r_consonant_pair () : boolean
    {
        var v_1 : int;
        var v_2 : int;
        var v_3 : int;
        // (, line 54
        // test, line 55
        v_1 = this.limit - this.cursor;
        // (, line 55
        // setlimit, line 56
        v_2 = this.limit - this.cursor;
        // tomark, line 56
        if (this.cursor < this.I_p1)
        {
            return false;
        }
        this.cursor = this.I_p1;
        v_3 = this.limit_backward;
        this.limit_backward = this.cursor;
        this.cursor = this.limit - v_2;
        // (, line 56
        // [, line 56
        this.ket = this.cursor;
        // substring, line 56
        if (this.find_among_b(DanishStemmer.a_1, 4) == 0)
        {
            this.limit_backward = v_3;
            return false;
        }
        // ], line 56
        this.bra = this.cursor;
        this.limit_backward = v_3;
        this.cursor = this.limit - v_1;
        // next, line 62
        if (this.cursor <= this.limit_backward)
        {
            return false;
        }
        this.cursor--;
        // ], line 62
        this.bra = this.cursor;
        // delete, line 62
        if (!this.slice_del())
        {
            return false;
        }
        return true;
    }

    function r_other_suffix () : boolean
    {
        var among_var : int;
        var v_1 : int;
        var v_2 : int;
        var v_3 : int;
        var v_4 : int;
        // (, line 65
        // do, line 66
        v_1 = this.limit - this.cursor;
        var lab0 = true;
        lab0: while (lab0 == true)
        {
            lab0 = false;
            // (, line 66
            // [, line 66
            this.ket = this.cursor;
            // literal, line 66
            if (!(this.eq_s_b(2, "st")))
            {
                break lab0;
            }
            // ], line 66
            this.bra = this.cursor;
            // literal, line 66
            if (!(this.eq_s_b(2, "ig")))
            {
                break lab0;
            }
            // delete, line 66
            if (!this.slice_del())
            {
                return false;
            }
        }
        this.cursor = this.limit - v_1;
        // setlimit, line 67
        v_2 = this.limit - this.cursor;
        // tomark, line 67
        if (this.cursor < this.I_p1)
        {
            return false;
        }
        this.cursor = this.I_p1;
        v_3 = this.limit_backward;
        this.limit_backward = this.cursor;
        this.cursor = this.limit - v_2;
        // (, line 67
        // [, line 67
        this.ket = this.cursor;
        // substring, line 67
        among_var = this.find_among_b(DanishStemmer.a_2, 5);
        if (among_var == 0)
        {
            this.limit_backward = v_3;
            return false;
        }
        // ], line 67
        this.bra = this.cursor;
        this.limit_backward = v_3;
        switch (among_var) {
            case 0:
                return false;
            case 1:
                // (, line 70
                // delete, line 70
                if (!this.slice_del())
                {
                    return false;
                }
                // do, line 70
                v_4 = this.limit - this.cursor;
                var lab1 = true;
                lab1: while (lab1 == true)
                {
                    lab1 = false;
                    // call consonant_pair, line 70
                    if (!this.r_consonant_pair())
                    {
                        break lab1;
                    }
                }
                this.cursor = this.limit - v_4;
                break;
            case 2:
                // (, line 72
                // <-, line 72
                if (!this.slice_from("l\u00F8s"))
                {
                    return false;
                }
                break;
        }
        return true;
    }

    function r_undouble () : boolean
    {
        var v_1 : int;
        var v_2 : int;
        // (, line 75
        // setlimit, line 76
        v_1 = this.limit - this.cursor;
        // tomark, line 76
        if (this.cursor < this.I_p1)
        {
            return false;
        }
        this.cursor = this.I_p1;
        v_2 = this.limit_backward;
        this.limit_backward = this.cursor;
        this.cursor = this.limit - v_1;
        // (, line 76
        // [, line 76
        this.ket = this.cursor;
        if (!(this.out_grouping_b(DanishStemmer.g_v, 97, 248)))
        {
            this.limit_backward = v_2;
            return false;
        }
        // ], line 76
        this.bra = this.cursor;
        // -> ch, line 76
        this.S_ch = this.slice_to(this.S_ch);
        if (this.S_ch == '')
        {
            return false;
        }
        this.limit_backward = v_2;
        // name ch, line 77
        if (!(this.eq_v_b(this.S_ch)))
        {
            return false;
        }
        // delete, line 78
        if (!this.slice_del())
        {
            return false;
        }
        return true;
    }

    override function stem () : boolean
    {
        var v_1 : int;
        var v_2 : int;
        var v_3 : int;
        var v_4 : int;
        var v_5 : int;
        // (, line 82
        // do, line 84
        v_1 = this.cursor;
        var lab0 = true;
        lab0: while (lab0 == true)
        {
            lab0 = false;
            // call mark_regions, line 84
            if (!this.r_mark_regions())
            {
                break lab0;
            }
        }
        this.cursor = v_1;
        // backwards, line 85
        this.limit_backward = this.cursor; this.cursor = this.limit;
        // (, line 85
        // do, line 86
        v_2 = this.limit - this.cursor;
        var lab1 = true;
        lab1: while (lab1 == true)
        {
            lab1 = false;
            // call main_suffix, line 86
            if (!this.r_main_suffix())
            {
                break lab1;
            }
        }
        this.cursor = this.limit - v_2;
        // do, line 87
        v_3 = this.limit - this.cursor;
        var lab2 = true;
        lab2: while (lab2 == true)
        {
            lab2 = false;
            // call consonant_pair, line 87
            if (!this.r_consonant_pair())
            {
                break lab2;
            }
        }
        this.cursor = this.limit - v_3;
        // do, line 88
        v_4 = this.limit - this.cursor;
        var lab3 = true;
        lab3: while (lab3 == true)
        {
            lab3 = false;
            // call other_suffix, line 88
            if (!this.r_other_suffix())
            {
                break lab3;
            }
        }
        this.cursor = this.limit - v_4;
        // do, line 89
        v_5 = this.limit - this.cursor;
        var lab4 = true;
        lab4: while (lab4 == true)
        {
            lab4 = false;
            // call undouble, line 89
            if (!this.r_undouble())
            {
                break lab4;
            }
        }
        this.cursor = this.limit - v_5;
        this.cursor = this.limit_backward;        return true;
    }

    function equals (o : variant) : boolean {
        return o instanceof DanishStemmer;
    }

    function hashCode() : int
    {
        //http://stackoverflow.com/questions/194846/is-there-any-kind-of-hashcode-function-in-javascript
        var classname = "DanishStemmer";
        var hash = 0;
        if (classname.length == 0) return hash;
        for (var i = 0; i < classname.length; i++) {
            var char = classname.charCodeAt(i);
            hash = ((hash << 5) - hash) + char;
            hash = hash & hash; // Convert to 32bit integer
        }
        return hash;
    }

}