xref: /Lucene/lucene/analysis/common/src/java/org/tartarus/snowball/ext/PorterStemmer.java (revision 0b1d8ccba6cf394f707a09217813a25ec1504e50)
1 // Generated by Snowball 2.0.0 - https://snowballstem.org/
2 
3 package org.tartarus.snowball.ext;
4 
5 import org.tartarus.snowball.Among;
6 
7 /**
8  * This class implements the stemming algorithm defined by a snowball script.
9  *
10  * <p>Generated by Snowball 2.0.0 - https://snowballstem.org/
11  */
12 @SuppressWarnings("unused")
13 public class PorterStemmer extends org.tartarus.snowball.SnowballStemmer {
14 
15   private static final long serialVersionUID = 1L;
16   private static final java.lang.invoke.MethodHandles.Lookup methodObject =
17       java.lang.invoke.MethodHandles.lookup();
18 
19   private static final Among a_0[] = {
20     new Among("s", -1, 3), new Among("ies", 0, 2), new Among("sses", 0, 1), new Among("ss", 0, -1)
21   };
22 
23   private static final Among a_1[] = {
24     new Among("", -1, 3),
25     new Among("bb", 0, 2),
26     new Among("dd", 0, 2),
27     new Among("ff", 0, 2),
28     new Among("gg", 0, 2),
29     new Among("bl", 0, 1),
30     new Among("mm", 0, 2),
31     new Among("nn", 0, 2),
32     new Among("pp", 0, 2),
33     new Among("rr", 0, 2),
34     new Among("at", 0, 1),
35     new Among("tt", 0, 2),
36     new Among("iz", 0, 1)
37   };
38 
39   private static final Among a_2[] = {
40     new Among("ed", -1, 2), new Among("eed", 0, 1), new Among("ing", -1, 2)
41   };
42 
43   private static final Among a_3[] = {
44     new Among("anci", -1, 3),
45     new Among("enci", -1, 2),
46     new Among("abli", -1, 4),
47     new Among("eli", -1, 6),
48     new Among("alli", -1, 9),
49     new Among("ousli", -1, 11),
50     new Among("entli", -1, 5),
51     new Among("aliti", -1, 9),
52     new Among("biliti", -1, 13),
53     new Among("iviti", -1, 12),
54     new Among("tional", -1, 1),
55     new Among("ational", 10, 8),
56     new Among("alism", -1, 9),
57     new Among("ation", -1, 8),
58     new Among("ization", 13, 7),
59     new Among("izer", -1, 7),
60     new Among("ator", -1, 8),
61     new Among("iveness", -1, 12),
62     new Among("fulness", -1, 10),
63     new Among("ousness", -1, 11)
64   };
65 
66   private static final Among a_4[] = {
67     new Among("icate", -1, 2),
68     new Among("ative", -1, 3),
69     new Among("alize", -1, 1),
70     new Among("iciti", -1, 2),
71     new Among("ical", -1, 2),
72     new Among("ful", -1, 3),
73     new Among("ness", -1, 3)
74   };
75 
76   private static final Among a_5[] = {
77     new Among("ic", -1, 1),
78     new Among("ance", -1, 1),
79     new Among("ence", -1, 1),
80     new Among("able", -1, 1),
81     new Among("ible", -1, 1),
82     new Among("ate", -1, 1),
83     new Among("ive", -1, 1),
84     new Among("ize", -1, 1),
85     new Among("iti", -1, 1),
86     new Among("al", -1, 1),
87     new Among("ism", -1, 1),
88     new Among("ion", -1, 2),
89     new Among("er", -1, 1),
90     new Among("ous", -1, 1),
91     new Among("ant", -1, 1),
92     new Among("ent", -1, 1),
93     new Among("ment", 15, 1),
94     new Among("ement", 16, 1),
95     new Among("ou", -1, 1)
96   };
97 
98   private static final char g_v[] = {17, 65, 16, 1};
99 
100   private static final char g_v_WXY[] = {1, 17, 65, 208, 1};
101 
102   private boolean B_Y_found;
103   private int I_p2;
104   private int I_p1;
105 
r_shortv()106   private boolean r_shortv() {
107     if (!(out_grouping_b(g_v_WXY, 89, 121))) {
108       return false;
109     }
110     if (!(in_grouping_b(g_v, 97, 121))) {
111       return false;
112     }
113     if (!(out_grouping_b(g_v, 97, 121))) {
114       return false;
115     }
116     return true;
117   }
118 
r_R1()119   private boolean r_R1() {
120     if (!(I_p1 <= cursor)) {
121       return false;
122     }
123     return true;
124   }
125 
r_R2()126   private boolean r_R2() {
127     if (!(I_p2 <= cursor)) {
128       return false;
129     }
130     return true;
131   }
132 
r_Step_1a()133   private boolean r_Step_1a() {
134     int among_var;
135     ket = cursor;
136     among_var = find_among_b(a_0);
137     if (among_var == 0) {
138       return false;
139     }
140     bra = cursor;
141     switch (among_var) {
142       case 1:
143         slice_from("ss");
144         break;
145       case 2:
146         slice_from("i");
147         break;
148       case 3:
149         slice_del();
150         break;
151     }
152     return true;
153   }
154 
r_Step_1b()155   private boolean r_Step_1b() {
156     int among_var;
157     ket = cursor;
158     among_var = find_among_b(a_2);
159     if (among_var == 0) {
160       return false;
161     }
162     bra = cursor;
163     switch (among_var) {
164       case 1:
165         if (!r_R1()) {
166           return false;
167         }
168         slice_from("ee");
169         break;
170       case 2:
171         int v_1 = limit - cursor;
172         golab0:
173         while (true) {
174           lab1:
175           {
176             if (!(in_grouping_b(g_v, 97, 121))) {
177               break lab1;
178             }
179             break golab0;
180           }
181           if (cursor <= limit_backward) {
182             return false;
183           }
184           cursor--;
185         }
186         cursor = limit - v_1;
187         slice_del();
188         int v_3 = limit - cursor;
189         among_var = find_among_b(a_1);
190         if (among_var == 0) {
191           return false;
192         }
193         cursor = limit - v_3;
194         switch (among_var) {
195           case 1:
196             {
197               int c = cursor;
198               insert(cursor, cursor, "e");
199               cursor = c;
200             }
201             break;
202           case 2:
203             ket = cursor;
204             if (cursor <= limit_backward) {
205               return false;
206             }
207             cursor--;
208             bra = cursor;
209             slice_del();
210             break;
211           case 3:
212             if (cursor != I_p1) {
213               return false;
214             }
215             int v_4 = limit - cursor;
216             if (!r_shortv()) {
217               return false;
218             }
219             cursor = limit - v_4;
220             {
221               int c = cursor;
222               insert(cursor, cursor, "e");
223               cursor = c;
224             }
225             break;
226         }
227         break;
228     }
229     return true;
230   }
231 
r_Step_1c()232   private boolean r_Step_1c() {
233     ket = cursor;
234     lab0:
235     {
236       int v_1 = limit - cursor;
237       lab1:
238       {
239         if (!(eq_s_b("y"))) {
240           break lab1;
241         }
242         break lab0;
243       }
244       cursor = limit - v_1;
245       if (!(eq_s_b("Y"))) {
246         return false;
247       }
248     }
249     bra = cursor;
250     golab2:
251     while (true) {
252       lab3:
253       {
254         if (!(in_grouping_b(g_v, 97, 121))) {
255           break lab3;
256         }
257         break golab2;
258       }
259       if (cursor <= limit_backward) {
260         return false;
261       }
262       cursor--;
263     }
264     slice_from("i");
265     return true;
266   }
267 
r_Step_2()268   private boolean r_Step_2() {
269     int among_var;
270     ket = cursor;
271     among_var = find_among_b(a_3);
272     if (among_var == 0) {
273       return false;
274     }
275     bra = cursor;
276     if (!r_R1()) {
277       return false;
278     }
279     switch (among_var) {
280       case 1:
281         slice_from("tion");
282         break;
283       case 2:
284         slice_from("ence");
285         break;
286       case 3:
287         slice_from("ance");
288         break;
289       case 4:
290         slice_from("able");
291         break;
292       case 5:
293         slice_from("ent");
294         break;
295       case 6:
296         slice_from("e");
297         break;
298       case 7:
299         slice_from("ize");
300         break;
301       case 8:
302         slice_from("ate");
303         break;
304       case 9:
305         slice_from("al");
306         break;
307       case 10:
308         slice_from("ful");
309         break;
310       case 11:
311         slice_from("ous");
312         break;
313       case 12:
314         slice_from("ive");
315         break;
316       case 13:
317         slice_from("ble");
318         break;
319     }
320     return true;
321   }
322 
r_Step_3()323   private boolean r_Step_3() {
324     int among_var;
325     ket = cursor;
326     among_var = find_among_b(a_4);
327     if (among_var == 0) {
328       return false;
329     }
330     bra = cursor;
331     if (!r_R1()) {
332       return false;
333     }
334     switch (among_var) {
335       case 1:
336         slice_from("al");
337         break;
338       case 2:
339         slice_from("ic");
340         break;
341       case 3:
342         slice_del();
343         break;
344     }
345     return true;
346   }
347 
r_Step_4()348   private boolean r_Step_4() {
349     int among_var;
350     ket = cursor;
351     among_var = find_among_b(a_5);
352     if (among_var == 0) {
353       return false;
354     }
355     bra = cursor;
356     if (!r_R2()) {
357       return false;
358     }
359     switch (among_var) {
360       case 1:
361         slice_del();
362         break;
363       case 2:
364         lab0:
365         {
366           int v_1 = limit - cursor;
367           lab1:
368           {
369             if (!(eq_s_b("s"))) {
370               break lab1;
371             }
372             break lab0;
373           }
374           cursor = limit - v_1;
375           if (!(eq_s_b("t"))) {
376             return false;
377           }
378         }
379         slice_del();
380         break;
381     }
382     return true;
383   }
384 
r_Step_5a()385   private boolean r_Step_5a() {
386     ket = cursor;
387     if (!(eq_s_b("e"))) {
388       return false;
389     }
390     bra = cursor;
391     lab0:
392     {
393       int v_1 = limit - cursor;
394       lab1:
395       {
396         if (!r_R2()) {
397           break lab1;
398         }
399         break lab0;
400       }
401       cursor = limit - v_1;
402       if (!r_R1()) {
403         return false;
404       }
405       {
406         int v_2 = limit - cursor;
407         lab2:
408         {
409           if (!r_shortv()) {
410             break lab2;
411           }
412           return false;
413         }
414         cursor = limit - v_2;
415       }
416     }
417     slice_del();
418     return true;
419   }
420 
r_Step_5b()421   private boolean r_Step_5b() {
422     ket = cursor;
423     if (!(eq_s_b("l"))) {
424       return false;
425     }
426     bra = cursor;
427     if (!r_R2()) {
428       return false;
429     }
430     if (!(eq_s_b("l"))) {
431       return false;
432     }
433     slice_del();
434     return true;
435   }
436 
437   @Override
stem()438   public boolean stem() {
439     B_Y_found = false;
440     int v_1 = cursor;
441     lab0:
442     {
443       bra = cursor;
444       if (!(eq_s("y"))) {
445         break lab0;
446       }
447       ket = cursor;
448       slice_from("Y");
449       B_Y_found = true;
450     }
451     cursor = v_1;
452     int v_2 = cursor;
453     lab1:
454     {
455       while (true) {
456         int v_3 = cursor;
457         lab2:
458         {
459           golab3:
460           while (true) {
461             int v_4 = cursor;
462             lab4:
463             {
464               if (!(in_grouping(g_v, 97, 121))) {
465                 break lab4;
466               }
467               bra = cursor;
468               if (!(eq_s("y"))) {
469                 break lab4;
470               }
471               ket = cursor;
472               cursor = v_4;
473               break golab3;
474             }
475             cursor = v_4;
476             if (cursor >= limit) {
477               break lab2;
478             }
479             cursor++;
480           }
481           slice_from("Y");
482           B_Y_found = true;
483           continue;
484         }
485         cursor = v_3;
486         break;
487       }
488     }
489     cursor = v_2;
490     I_p1 = limit;
491     I_p2 = limit;
492     int v_5 = cursor;
493     lab5:
494     {
495       golab6:
496       while (true) {
497         lab7:
498         {
499           if (!(in_grouping(g_v, 97, 121))) {
500             break lab7;
501           }
502           break golab6;
503         }
504         if (cursor >= limit) {
505           break lab5;
506         }
507         cursor++;
508       }
509       golab8:
510       while (true) {
511         lab9:
512         {
513           if (!(out_grouping(g_v, 97, 121))) {
514             break lab9;
515           }
516           break golab8;
517         }
518         if (cursor >= limit) {
519           break lab5;
520         }
521         cursor++;
522       }
523       I_p1 = cursor;
524       golab10:
525       while (true) {
526         lab11:
527         {
528           if (!(in_grouping(g_v, 97, 121))) {
529             break lab11;
530           }
531           break golab10;
532         }
533         if (cursor >= limit) {
534           break lab5;
535         }
536         cursor++;
537       }
538       golab12:
539       while (true) {
540         lab13:
541         {
542           if (!(out_grouping(g_v, 97, 121))) {
543             break lab13;
544           }
545           break golab12;
546         }
547         if (cursor >= limit) {
548           break lab5;
549         }
550         cursor++;
551       }
552       I_p2 = cursor;
553     }
554     cursor = v_5;
555     limit_backward = cursor;
556     cursor = limit;
557     int v_10 = limit - cursor;
558     r_Step_1a();
559     cursor = limit - v_10;
560     int v_11 = limit - cursor;
561     r_Step_1b();
562     cursor = limit - v_11;
563     int v_12 = limit - cursor;
564     r_Step_1c();
565     cursor = limit - v_12;
566     int v_13 = limit - cursor;
567     r_Step_2();
568     cursor = limit - v_13;
569     int v_14 = limit - cursor;
570     r_Step_3();
571     cursor = limit - v_14;
572     int v_15 = limit - cursor;
573     r_Step_4();
574     cursor = limit - v_15;
575     int v_16 = limit - cursor;
576     r_Step_5a();
577     cursor = limit - v_16;
578     int v_17 = limit - cursor;
579     r_Step_5b();
580     cursor = limit - v_17;
581     cursor = limit_backward;
582     int v_18 = cursor;
583     lab14:
584     {
585       if (!(B_Y_found)) {
586         break lab14;
587       }
588       while (true) {
589         int v_19 = cursor;
590         lab15:
591         {
592           golab16:
593           while (true) {
594             int v_20 = cursor;
595             lab17:
596             {
597               bra = cursor;
598               if (!(eq_s("Y"))) {
599                 break lab17;
600               }
601               ket = cursor;
602               cursor = v_20;
603               break golab16;
604             }
605             cursor = v_20;
606             if (cursor >= limit) {
607               break lab15;
608             }
609             cursor++;
610           }
611           slice_from("y");
612           continue;
613         }
614         cursor = v_19;
615         break;
616       }
617     }
618     cursor = v_18;
619     return true;
620   }
621 
622   @Override
equals(Object o)623   public boolean equals(Object o) {
624     return o instanceof PorterStemmer;
625   }
626 
627   @Override
hashCode()628   public int hashCode() {
629     return PorterStemmer.class.getName().hashCode();
630   }
631 }
632