summaryrefslogtreecommitdiffstats
path: root/web/server/h2o/libh2o/misc/oktavia/src/stemmer/german-stemmer.jsx
blob: 7659b3a7cbd30f286e6fa3af3b38dd67dadacb63 (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
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
// 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 GermanStemmer extends BaseStemmer
{
    static const serialVersionUID = 1;
    static const methodObject = new GermanStemmer();

    static const a_0 = [
        new Among("", -1, 6),
        new Among("U", 0, 2),
        new Among("Y", 0, 1),
        new Among("\u00E4", 0, 3),
        new Among("\u00F6", 0, 4),
        new Among("\u00FC", 0, 5)
    ];

    static const a_1 = [
        new Among("e", -1, 2),
        new Among("em", -1, 1),
        new Among("en", -1, 2),
        new Among("ern", -1, 1),
        new Among("er", -1, 1),
        new Among("s", -1, 3),
        new Among("es", 5, 2)
    ];

    static const a_2 = [
        new Among("en", -1, 1),
        new Among("er", -1, 1),
        new Among("st", -1, 2),
        new Among("est", 2, 1)
    ];

    static const a_3 = [
        new Among("ig", -1, 1),
        new Among("lich", -1, 1)
    ];

    static const a_4 = [
        new Among("end", -1, 1),
        new Among("ig", -1, 2),
        new Among("ung", -1, 1),
        new Among("lich", -1, 3),
        new Among("isch", -1, 2),
        new Among("ik", -1, 2),
        new Among("heit", -1, 3),
        new Among("keit", -1, 4)
    ];

    static const g_v = [17, 65, 16, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 32, 8] : int[];

    static const g_s_ending = [117, 30, 5] : int[];

    static const g_st_ending = [117, 30, 4] : int[];

    var I_x : int = 0;
    var I_p2 : int = 0;
    var I_p1 : int = 0;

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

    function r_prelude () : boolean
    {
        var v_1 : int;
        var v_2 : int;
        var v_3 : int;
        var v_4 : int;
        var v_5 : int;
        var v_6 : int;
        // (, line 33
        // test, line 35
        v_1 = this.cursor;
        // repeat, line 35
        replab0: while(true)
        {
            v_2 = this.cursor;
            var lab1 = true;
            lab1: while (lab1 == true)
            {
                lab1 = false;
                // (, line 35
                // or, line 38
                var lab2 = true;
                lab2: while (lab2 == true)
                {
                    lab2 = false;
                    v_3 = this.cursor;
                    var lab3 = true;
                    lab3: while (lab3 == true)
                    {
                        lab3 = false;
                        // (, line 36
                        // [, line 37
                        this.bra = this.cursor;
                        // literal, line 37
                        if (!(this.eq_s(1, "\u00DF")))
                        {
                            break lab3;
                        }
                        // ], line 37
                        this.ket = this.cursor;
                        // <-, line 37
                        if (!this.slice_from("ss"))
                        {
                            return false;
                        }
                        break lab2;
                    }
                    this.cursor = v_3;
                    // next, line 38
                    if (this.cursor >= this.limit)
                    {
                        break lab1;
                    }
                    this.cursor++;
                }
                continue replab0;
            }
            this.cursor = v_2;
            break replab0;
        }
        this.cursor = v_1;
        // repeat, line 41
        replab4: while(true)
        {
            v_4 = this.cursor;
            var lab5 = true;
            lab5: while (lab5 == true)
            {
                lab5 = false;
                // goto, line 41
                golab6: while(true)
                {
                    v_5 = this.cursor;
                    var lab7 = true;
                    lab7: while (lab7 == true)
                    {
                        lab7 = false;
                        // (, line 41
                        if (!(this.in_grouping(GermanStemmer.g_v, 97, 252)))
                        {
                            break lab7;
                        }
                        // [, line 42
                        this.bra = this.cursor;
                        // or, line 42
                        var lab8 = true;
                        lab8: while (lab8 == true)
                        {
                            lab8 = false;
                            v_6 = this.cursor;
                            var lab9 = true;
                            lab9: while (lab9 == true)
                            {
                                lab9 = false;
                                // (, line 42
                                // literal, line 42
                                if (!(this.eq_s(1, "u")))
                                {
                                    break lab9;
                                }
                                // ], line 42
                                this.ket = this.cursor;
                                if (!(this.in_grouping(GermanStemmer.g_v, 97, 252)))
                                {
                                    break lab9;
                                }
                                // <-, line 42
                                if (!this.slice_from("U"))
                                {
                                    return false;
                                }
                                break lab8;
                            }
                            this.cursor = v_6;
                            // (, line 43
                            // literal, line 43
                            if (!(this.eq_s(1, "y")))
                            {
                                break lab7;
                            }
                            // ], line 43
                            this.ket = this.cursor;
                            if (!(this.in_grouping(GermanStemmer.g_v, 97, 252)))
                            {
                                break lab7;
                            }
                            // <-, line 43
                            if (!this.slice_from("Y"))
                            {
                                return false;
                            }
                        }
                        this.cursor = v_5;
                        break golab6;
                    }
                    this.cursor = v_5;
                    if (this.cursor >= this.limit)
                    {
                        break lab5;
                    }
                    this.cursor++;
                }
                continue replab4;
            }
            this.cursor = v_4;
            break replab4;
        }
        return true;
    }

    function r_mark_regions () : boolean
    {
        var v_1 : int;
        // (, line 47
        this.I_p1 = this.limit;
        this.I_p2 = this.limit;
        // test, line 52
        v_1 = this.cursor;
        // (, line 52
        // hop, line 52
        {
            var c : int = this.cursor + 3;
            if (0 > c || c > this.limit)
            {
                return false;
            }
            this.cursor = c;
        }
        // setmark x, line 52
        this.I_x = this.cursor;
        this.cursor = v_1;
        // gopast, line 54
        golab0: while(true)
        {
            var lab1 = true;
            lab1: while (lab1 == true)
            {
                lab1 = false;
                if (!(this.in_grouping(GermanStemmer.g_v, 97, 252)))
                {
                    break lab1;
                }
                break golab0;
            }
            if (this.cursor >= this.limit)
            {
                return false;
            }
            this.cursor++;
        }
        // gopast, line 54
        golab2: while(true)
        {
            var lab3 = true;
            lab3: while (lab3 == true)
            {
                lab3 = false;
                if (!(this.out_grouping(GermanStemmer.g_v, 97, 252)))
                {
                    break lab3;
                }
                break golab2;
            }
            if (this.cursor >= this.limit)
            {
                return false;
            }
            this.cursor++;
        }
        // setmark p1, line 54
        this.I_p1 = this.cursor;
        // try, line 55
        var lab4 = true;
        lab4: while (lab4 == true)
        {
            lab4 = false;
            // (, line 55
            if (!(this.I_p1 < this.I_x))
            {
                break lab4;
            }
            this.I_p1 = this.I_x;
        }
        // gopast, line 56
        golab5: while(true)
        {
            var lab6 = true;
            lab6: while (lab6 == true)
            {
                lab6 = false;
                if (!(this.in_grouping(GermanStemmer.g_v, 97, 252)))
                {
                    break lab6;
                }
                break golab5;
            }
            if (this.cursor >= this.limit)
            {
                return false;
            }
            this.cursor++;
        }
        // gopast, line 56
        golab7: while(true)
        {
            var lab8 = true;
            lab8: while (lab8 == true)
            {
                lab8 = false;
                if (!(this.out_grouping(GermanStemmer.g_v, 97, 252)))
                {
                    break lab8;
                }
                break golab7;
            }
            if (this.cursor >= this.limit)
            {
                return false;
            }
            this.cursor++;
        }
        // setmark p2, line 56
        this.I_p2 = this.cursor;
        return true;
    }

    function r_postlude () : boolean
    {
        var among_var : int;
        var v_1 : int;
        // repeat, line 60
        replab0: while(true)
        {
            v_1 = this.cursor;
            var lab1 = true;
            lab1: while (lab1 == true)
            {
                lab1 = false;
                // (, line 60
                // [, line 62
                this.bra = this.cursor;
                // substring, line 62
                among_var = this.find_among(GermanStemmer.a_0, 6);
                if (among_var == 0)
                {
                    break lab1;
                }
                // ], line 62
                this.ket = this.cursor;
                switch (among_var) {
                    case 0:
                        break lab1;
                    case 1:
                        // (, line 63
                        // <-, line 63
                        if (!this.slice_from("y"))
                        {
                            return false;
                        }
                        break;
                    case 2:
                        // (, line 64
                        // <-, line 64
                        if (!this.slice_from("u"))
                        {
                            return false;
                        }
                        break;
                    case 3:
                        // (, line 65
                        // <-, line 65
                        if (!this.slice_from("a"))
                        {
                            return false;
                        }
                        break;
                    case 4:
                        // (, line 66
                        // <-, line 66
                        if (!this.slice_from("o"))
                        {
                            return false;
                        }
                        break;
                    case 5:
                        // (, line 67
                        // <-, line 67
                        if (!this.slice_from("u"))
                        {
                            return false;
                        }
                        break;
                    case 6:
                        // (, line 68
                        // next, line 68
                        if (this.cursor >= this.limit)
                        {
                            break lab1;
                        }
                        this.cursor++;
                        break;
                }
                continue replab0;
            }
            this.cursor = v_1;
            break replab0;
        }
        return true;
    }

    function r_R1 () : boolean
    {
        if (!(this.I_p1 <= this.cursor))
        {
            return false;
        }
        return true;
    }

    function r_R2 () : boolean
    {
        if (!(this.I_p2 <= this.cursor))
        {
            return false;
        }
        return true;
    }

    function r_standard_suffix () : boolean
    {
        var among_var : int;
        var v_1 : int;
        var v_2 : int;
        var v_3 : int;
        var v_4 : int;
        var v_5 : int;
        var v_6 : int;
        var v_7 : int;
        var v_8 : int;
        var v_9 : int;
        var v_10 : int;
        // (, line 78
        // do, line 79
        v_1 = this.limit - this.cursor;
        var lab0 = true;
        lab0: while (lab0 == true)
        {
            lab0 = false;
            // (, line 79
            // [, line 80
            this.ket = this.cursor;
            // substring, line 80
            among_var = this.find_among_b(GermanStemmer.a_1, 7);
            if (among_var == 0)
            {
                break lab0;
            }
            // ], line 80
            this.bra = this.cursor;
            // call R1, line 80
            if (!this.r_R1())
            {
                break lab0;
            }
            switch (among_var) {
                case 0:
                    break lab0;
                case 1:
                    // (, line 82
                    // delete, line 82
                    if (!this.slice_del())
                    {
                        return false;
                    }
                    break;
                case 2:
                    // (, line 85
                    // delete, line 85
                    if (!this.slice_del())
                    {
                        return false;
                    }
                    // try, line 86
                    v_2 = this.limit - this.cursor;
                    var lab1 = true;
                    lab1: while (lab1 == true)
                    {
                        lab1 = false;
                        // (, line 86
                        // [, line 86
                        this.ket = this.cursor;
                        // literal, line 86
                        if (!(this.eq_s_b(1, "s")))
                        {
                            this.cursor = this.limit - v_2;
                            break lab1;
                        }
                        // ], line 86
                        this.bra = this.cursor;
                        // literal, line 86
                        if (!(this.eq_s_b(3, "nis")))
                        {
                            this.cursor = this.limit - v_2;
                            break lab1;
                        }
                        // delete, line 86
                        if (!this.slice_del())
                        {
                            return false;
                        }
                    }
                    break;
                case 3:
                    // (, line 89
                    if (!(this.in_grouping_b(GermanStemmer.g_s_ending, 98, 116)))
                    {
                        break lab0;
                    }
                    // delete, line 89
                    if (!this.slice_del())
                    {
                        return false;
                    }
                    break;
            }
        }
        this.cursor = this.limit - v_1;
        // do, line 93
        v_3 = this.limit - this.cursor;
        var lab2 = true;
        lab2: while (lab2 == true)
        {
            lab2 = false;
            // (, line 93
            // [, line 94
            this.ket = this.cursor;
            // substring, line 94
            among_var = this.find_among_b(GermanStemmer.a_2, 4);
            if (among_var == 0)
            {
                break lab2;
            }
            // ], line 94
            this.bra = this.cursor;
            // call R1, line 94
            if (!this.r_R1())
            {
                break lab2;
            }
            switch (among_var) {
                case 0:
                    break lab2;
                case 1:
                    // (, line 96
                    // delete, line 96
                    if (!this.slice_del())
                    {
                        return false;
                    }
                    break;
                case 2:
                    // (, line 99
                    if (!(this.in_grouping_b(GermanStemmer.g_st_ending, 98, 116)))
                    {
                        break lab2;
                    }
                    // hop, line 99
                    {
                        var c : int = this.cursor - 3;
                        if (this.limit_backward > c || c > this.limit)
                        {
                            break lab2;
                        }
                        this.cursor = c;
                    }
                    // delete, line 99
                    if (!this.slice_del())
                    {
                        return false;
                    }
                    break;
            }
        }
        this.cursor = this.limit - v_3;
        // do, line 103
        v_4 = this.limit - this.cursor;
        var lab3 = true;
        lab3: while (lab3 == true)
        {
            lab3 = false;
            // (, line 103
            // [, line 104
            this.ket = this.cursor;
            // substring, line 104
            among_var = this.find_among_b(GermanStemmer.a_4, 8);
            if (among_var == 0)
            {
                break lab3;
            }
            // ], line 104
            this.bra = this.cursor;
            // call R2, line 104
            if (!this.r_R2())
            {
                break lab3;
            }
            switch (among_var) {
                case 0:
                    break lab3;
                case 1:
                    // (, line 106
                    // delete, line 106
                    if (!this.slice_del())
                    {
                        return false;
                    }
                    // try, line 107
                    v_5 = this.limit - this.cursor;
                    var lab4 = true;
                    lab4: while (lab4 == true)
                    {
                        lab4 = false;
                        // (, line 107
                        // [, line 107
                        this.ket = this.cursor;
                        // literal, line 107
                        if (!(this.eq_s_b(2, "ig")))
                        {
                            this.cursor = this.limit - v_5;
                            break lab4;
                        }
                        // ], line 107
                        this.bra = this.cursor;
                        // not, line 107
                        {
                            v_6 = this.limit - this.cursor;
                            var lab5 = true;
                            lab5: while (lab5 == true)
                            {
                                lab5 = false;
                                // literal, line 107
                                if (!(this.eq_s_b(1, "e")))
                                {
                                    break lab5;
                                }
                                this.cursor = this.limit - v_5;
                                break lab4;
                            }
                            this.cursor = this.limit - v_6;
                        }
                        // call R2, line 107
                        if (!this.r_R2())
                        {
                            this.cursor = this.limit - v_5;
                            break lab4;
                        }
                        // delete, line 107
                        if (!this.slice_del())
                        {
                            return false;
                        }
                    }
                    break;
                case 2:
                    // (, line 110
                    // not, line 110
                    {
                        v_7 = this.limit - this.cursor;
                        var lab6 = true;
                        lab6: while (lab6 == true)
                        {
                            lab6 = false;
                            // literal, line 110
                            if (!(this.eq_s_b(1, "e")))
                            {
                                break lab6;
                            }
                            break lab3;
                        }
                        this.cursor = this.limit - v_7;
                    }
                    // delete, line 110
                    if (!this.slice_del())
                    {
                        return false;
                    }
                    break;
                case 3:
                    // (, line 113
                    // delete, line 113
                    if (!this.slice_del())
                    {
                        return false;
                    }
                    // try, line 114
                    v_8 = this.limit - this.cursor;
                    var lab7 = true;
                    lab7: while (lab7 == true)
                    {
                        lab7 = false;
                        // (, line 114
                        // [, line 115
                        this.ket = this.cursor;
                        // or, line 115
                        var lab8 = true;
                        lab8: while (lab8 == true)
                        {
                            lab8 = false;
                            v_9 = this.limit - this.cursor;
                            var lab9 = true;
                            lab9: while (lab9 == true)
                            {
                                lab9 = false;
                                // literal, line 115
                                if (!(this.eq_s_b(2, "er")))
                                {
                                    break lab9;
                                }
                                break lab8;
                            }
                            this.cursor = this.limit - v_9;
                            // literal, line 115
                            if (!(this.eq_s_b(2, "en")))
                            {
                                this.cursor = this.limit - v_8;
                                break lab7;
                            }
                        }
                        // ], line 115
                        this.bra = this.cursor;
                        // call R1, line 115
                        if (!this.r_R1())
                        {
                            this.cursor = this.limit - v_8;
                            break lab7;
                        }
                        // delete, line 115
                        if (!this.slice_del())
                        {
                            return false;
                        }
                    }
                    break;
                case 4:
                    // (, line 119
                    // delete, line 119
                    if (!this.slice_del())
                    {
                        return false;
                    }
                    // try, line 120
                    v_10 = this.limit - this.cursor;
                    var lab10 = true;
                    lab10: while (lab10 == true)
                    {
                        lab10 = false;
                        // (, line 120
                        // [, line 121
                        this.ket = this.cursor;
                        // substring, line 121
                        among_var = this.find_among_b(GermanStemmer.a_3, 2);
                        if (among_var == 0)
                        {
                            this.cursor = this.limit - v_10;
                            break lab10;
                        }
                        // ], line 121
                        this.bra = this.cursor;
                        // call R2, line 121
                        if (!this.r_R2())
                        {
                            this.cursor = this.limit - v_10;
                            break lab10;
                        }
                        switch (among_var) {
                            case 0:
                                this.cursor = this.limit - v_10;
                                break lab10;
                            case 1:
                                // (, line 123
                                // delete, line 123
                                if (!this.slice_del())
                                {
                                    return false;
                                }
                                break;
                        }
                    }
                    break;
            }
        }
        this.cursor = this.limit - v_4;
        return true;
    }

    override function stem () : boolean
    {
        var v_1 : int;
        var v_2 : int;
        var v_3 : int;
        var v_4 : int;
        // (, line 133
        // do, line 134
        v_1 = this.cursor;
        var lab0 = true;
        lab0: while (lab0 == true)
        {
            lab0 = false;
            // call prelude, line 134
            if (!this.r_prelude())
            {
                break lab0;
            }
        }
        this.cursor = v_1;
        // do, line 135
        v_2 = this.cursor;
        var lab1 = true;
        lab1: while (lab1 == true)
        {
            lab1 = false;
            // call mark_regions, line 135
            if (!this.r_mark_regions())
            {
                break lab1;
            }
        }
        this.cursor = v_2;
        // backwards, line 136
        this.limit_backward = this.cursor; this.cursor = this.limit;
        // do, line 137
        v_3 = this.limit - this.cursor;
        var lab2 = true;
        lab2: while (lab2 == true)
        {
            lab2 = false;
            // call standard_suffix, line 137
            if (!this.r_standard_suffix())
            {
                break lab2;
            }
        }
        this.cursor = this.limit - v_3;
        this.cursor = this.limit_backward;        // do, line 138
        v_4 = this.cursor;
        var lab3 = true;
        lab3: while (lab3 == true)
        {
            lab3 = false;
            // call postlude, line 138
            if (!this.r_postlude())
            {
                break lab3;
            }
        }
        this.cursor = v_4;
        return true;
    }

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

    function hashCode() : int
    {
        //http://stackoverflow.com/questions/194846/is-there-any-kind-of-hashcode-function-in-javascript
        var classname = "GermanStemmer";
        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;
    }

}