Line data Source code
1 : /* Generated from indonesian.sbl by Snowball 3.0.0 - https://snowballstem.org/ */
2 :
3 : #include "stem_UTF_8_indonesian.h"
4 :
5 : #include <stddef.h>
6 :
7 : #include "snowball_runtime.h"
8 :
9 : struct SN_local {
10 : struct SN_env z;
11 : int i_prefix;
12 : int i_measure;
13 : };
14 :
15 : typedef struct SN_local SN_local;
16 :
17 : #ifdef __cplusplus
18 : extern "C" {
19 : #endif
20 : extern int indonesian_UTF_8_stem(struct SN_env * z);
21 : #ifdef __cplusplus
22 : }
23 : #endif
24 :
25 : static int r_remove_suffix(struct SN_env * z);
26 : static int r_remove_second_order_prefix(struct SN_env * z);
27 : static int r_remove_first_order_prefix(struct SN_env * z);
28 : static int r_remove_possessive_pronoun(struct SN_env * z);
29 : static int r_remove_particle(struct SN_env * z);
30 :
31 : static const symbol s_0[] = { 's' };
32 : static const symbol s_1[] = { 's' };
33 : static const symbol s_2[] = { 'p' };
34 : static const symbol s_3[] = { 'p' };
35 : static const symbol s_4[] = { 'a', 'j', 'a', 'r' };
36 : static const symbol s_5[] = { 'a', 'j', 'a', 'r' };
37 : static const symbol s_6[] = { 'e', 'r' };
38 :
39 : static const symbol s_0_0[3] = { 'k', 'a', 'h' };
40 : static const symbol s_0_1[3] = { 'l', 'a', 'h' };
41 : static const symbol s_0_2[3] = { 'p', 'u', 'n' };
42 : static const struct among a_0[3] = {
43 : { 3, s_0_0, 0, 1, 0},
44 : { 3, s_0_1, 0, 1, 0},
45 : { 3, s_0_2, 0, 1, 0}
46 : };
47 :
48 : static const symbol s_1_0[3] = { 'n', 'y', 'a' };
49 : static const symbol s_1_1[2] = { 'k', 'u' };
50 : static const symbol s_1_2[2] = { 'm', 'u' };
51 : static const struct among a_1[3] = {
52 : { 3, s_1_0, 0, 1, 0},
53 : { 2, s_1_1, 0, 1, 0},
54 : { 2, s_1_2, 0, 1, 0}
55 : };
56 :
57 : static const symbol s_2_0[1] = { 'i' };
58 : static const symbol s_2_1[2] = { 'a', 'n' };
59 : static const struct among a_2[2] = {
60 : { 1, s_2_0, 0, 2, 0},
61 : { 2, s_2_1, 0, 1, 0}
62 : };
63 :
64 : static const symbol s_3_0[2] = { 'd', 'i' };
65 : static const symbol s_3_1[2] = { 'k', 'e' };
66 : static const symbol s_3_2[2] = { 'm', 'e' };
67 : static const symbol s_3_3[3] = { 'm', 'e', 'm' };
68 : static const symbol s_3_4[3] = { 'm', 'e', 'n' };
69 : static const symbol s_3_5[4] = { 'm', 'e', 'n', 'g' };
70 : static const symbol s_3_6[3] = { 'p', 'e', 'm' };
71 : static const symbol s_3_7[3] = { 'p', 'e', 'n' };
72 : static const symbol s_3_8[4] = { 'p', 'e', 'n', 'g' };
73 : static const symbol s_3_9[3] = { 't', 'e', 'r' };
74 : static const struct among a_3[10] = {
75 : { 2, s_3_0, 0, 1, 0},
76 : { 2, s_3_1, 0, 3, 0},
77 : { 2, s_3_2, 0, 1, 0},
78 : { 3, s_3_3, -1, 5, 0},
79 : { 3, s_3_4, -2, 2, 0},
80 : { 4, s_3_5, -1, 1, 0},
81 : { 3, s_3_6, 0, 6, 0},
82 : { 3, s_3_7, 0, 4, 0},
83 : { 4, s_3_8, -1, 3, 0},
84 : { 3, s_3_9, 0, 1, 0}
85 : };
86 :
87 : static const symbol s_4_0[2] = { 'b', 'e' };
88 : static const symbol s_4_1[2] = { 'p', 'e' };
89 : static const struct among a_4[2] = {
90 : { 2, s_4_0, 0, 2, 0},
91 : { 2, s_4_1, 0, 1, 0}
92 : };
93 :
94 : static const unsigned char g_vowel[] = { 17, 65, 16 };
95 :
96 0 : static int r_remove_particle(struct SN_env * z) {
97 0 : z->ket = z->c;
98 0 : if (z->c - 2 <= z->lb || (z->p[z->c - 1] != 104 && z->p[z->c - 1] != 110)) return 0;
99 0 : if (!find_among_b(z, a_0, 3, 0)) return 0;
100 0 : z->bra = z->c;
101 : {
102 0 : int ret = slice_del(z);
103 0 : if (ret < 0) return ret;
104 : }
105 0 : ((SN_local *)z)->i_measure -= 1;
106 0 : return 1;
107 : }
108 :
109 0 : static int r_remove_possessive_pronoun(struct SN_env * z) {
110 0 : z->ket = z->c;
111 0 : if (z->c - 1 <= z->lb || (z->p[z->c - 1] != 97 && z->p[z->c - 1] != 117)) return 0;
112 0 : if (!find_among_b(z, a_1, 3, 0)) return 0;
113 0 : z->bra = z->c;
114 : {
115 0 : int ret = slice_del(z);
116 0 : if (ret < 0) return ret;
117 : }
118 0 : ((SN_local *)z)->i_measure -= 1;
119 0 : return 1;
120 : }
121 :
122 0 : static int r_remove_suffix(struct SN_env * z) {
123 : int among_var;
124 0 : z->ket = z->c;
125 0 : if (z->c <= z->lb || (z->p[z->c - 1] != 105 && z->p[z->c - 1] != 110)) return 0;
126 0 : among_var = find_among_b(z, a_2, 2, 0);
127 0 : if (!among_var) return 0;
128 0 : z->bra = z->c;
129 0 : switch (among_var) {
130 0 : case 1:
131 : do {
132 0 : int v_1 = z->l - z->c;
133 0 : if (((SN_local *)z)->i_prefix == 3) goto lab0;
134 0 : if (((SN_local *)z)->i_prefix == 2) goto lab0;
135 0 : if (z->c <= z->lb || z->p[z->c - 1] != 'k') goto lab0;
136 0 : z->c--;
137 0 : z->bra = z->c;
138 0 : break;
139 0 : lab0:
140 0 : z->c = z->l - v_1;
141 0 : if (((SN_local *)z)->i_prefix == 1) return 0;
142 : } while (0);
143 0 : break;
144 0 : case 2:
145 0 : if (((SN_local *)z)->i_prefix > 2) return 0;
146 : {
147 0 : int v_2 = z->l - z->c;
148 0 : if (z->c <= z->lb || z->p[z->c - 1] != 's') goto lab1;
149 0 : z->c--;
150 0 : return 0;
151 0 : lab1:
152 0 : z->c = z->l - v_2;
153 : }
154 0 : break;
155 : }
156 : {
157 0 : int ret = slice_del(z);
158 0 : if (ret < 0) return ret;
159 : }
160 0 : ((SN_local *)z)->i_measure -= 1;
161 0 : return 1;
162 : }
163 :
164 0 : static int r_remove_first_order_prefix(struct SN_env * z) {
165 : int among_var;
166 0 : z->bra = z->c;
167 0 : if (z->c + 1 >= z->l || (z->p[z->c + 1] != 105 && z->p[z->c + 1] != 101)) return 0;
168 0 : among_var = find_among(z, a_3, 10, 0);
169 0 : if (!among_var) return 0;
170 0 : z->ket = z->c;
171 0 : switch (among_var) {
172 0 : case 1:
173 : {
174 0 : int ret = slice_del(z);
175 0 : if (ret < 0) return ret;
176 : }
177 0 : ((SN_local *)z)->i_prefix = 1;
178 0 : ((SN_local *)z)->i_measure -= 1;
179 0 : break;
180 0 : case 2:
181 : do {
182 0 : int v_1 = z->c;
183 0 : if (z->c == z->l || z->p[z->c] != 'y') goto lab0;
184 0 : z->c++;
185 : {
186 0 : int v_2 = z->c;
187 0 : if (in_grouping_U(z, g_vowel, 97, 117, 0)) goto lab0;
188 0 : z->c = v_2;
189 : }
190 0 : z->ket = z->c;
191 : {
192 0 : int ret = slice_from_s(z, 1, s_0);
193 0 : if (ret < 0) return ret;
194 : }
195 0 : ((SN_local *)z)->i_prefix = 1;
196 0 : ((SN_local *)z)->i_measure -= 1;
197 0 : break;
198 0 : lab0:
199 0 : z->c = v_1;
200 : {
201 0 : int ret = slice_del(z);
202 0 : if (ret < 0) return ret;
203 : }
204 0 : ((SN_local *)z)->i_prefix = 1;
205 0 : ((SN_local *)z)->i_measure -= 1;
206 : } while (0);
207 0 : break;
208 0 : case 3:
209 : {
210 0 : int ret = slice_del(z);
211 0 : if (ret < 0) return ret;
212 : }
213 0 : ((SN_local *)z)->i_prefix = 3;
214 0 : ((SN_local *)z)->i_measure -= 1;
215 0 : break;
216 0 : case 4:
217 : do {
218 0 : int v_3 = z->c;
219 0 : if (z->c == z->l || z->p[z->c] != 'y') goto lab1;
220 0 : z->c++;
221 : {
222 0 : int v_4 = z->c;
223 0 : if (in_grouping_U(z, g_vowel, 97, 117, 0)) goto lab1;
224 0 : z->c = v_4;
225 : }
226 0 : z->ket = z->c;
227 : {
228 0 : int ret = slice_from_s(z, 1, s_1);
229 0 : if (ret < 0) return ret;
230 : }
231 0 : ((SN_local *)z)->i_prefix = 3;
232 0 : ((SN_local *)z)->i_measure -= 1;
233 0 : break;
234 0 : lab1:
235 0 : z->c = v_3;
236 : {
237 0 : int ret = slice_del(z);
238 0 : if (ret < 0) return ret;
239 : }
240 0 : ((SN_local *)z)->i_prefix = 3;
241 0 : ((SN_local *)z)->i_measure -= 1;
242 : } while (0);
243 0 : break;
244 0 : case 5:
245 0 : ((SN_local *)z)->i_prefix = 1;
246 0 : ((SN_local *)z)->i_measure -= 1;
247 : do {
248 0 : int v_5 = z->c;
249 : {
250 0 : int v_6 = z->c;
251 0 : if (in_grouping_U(z, g_vowel, 97, 117, 0)) goto lab2;
252 0 : z->c = v_6;
253 : {
254 0 : int ret = slice_from_s(z, 1, s_2);
255 0 : if (ret < 0) return ret;
256 : }
257 : }
258 0 : break;
259 0 : lab2:
260 0 : z->c = v_5;
261 : {
262 0 : int ret = slice_del(z);
263 0 : if (ret < 0) return ret;
264 : }
265 : } while (0);
266 0 : break;
267 0 : case 6:
268 0 : ((SN_local *)z)->i_prefix = 3;
269 0 : ((SN_local *)z)->i_measure -= 1;
270 : do {
271 0 : int v_7 = z->c;
272 : {
273 0 : int v_8 = z->c;
274 0 : if (in_grouping_U(z, g_vowel, 97, 117, 0)) goto lab3;
275 0 : z->c = v_8;
276 : {
277 0 : int ret = slice_from_s(z, 1, s_3);
278 0 : if (ret < 0) return ret;
279 : }
280 : }
281 0 : break;
282 0 : lab3:
283 0 : z->c = v_7;
284 : {
285 0 : int ret = slice_del(z);
286 0 : if (ret < 0) return ret;
287 : }
288 : } while (0);
289 0 : break;
290 : }
291 0 : return 1;
292 : }
293 :
294 0 : static int r_remove_second_order_prefix(struct SN_env * z) {
295 : int among_var;
296 0 : z->bra = z->c;
297 0 : if (z->c + 1 >= z->l || z->p[z->c + 1] != 101) return 0;
298 0 : among_var = find_among(z, a_4, 2, 0);
299 0 : if (!among_var) return 0;
300 0 : switch (among_var) {
301 0 : case 1:
302 : do {
303 0 : int v_1 = z->c;
304 0 : if (z->c == z->l || z->p[z->c] != 'r') goto lab0;
305 0 : z->c++;
306 0 : z->ket = z->c;
307 0 : ((SN_local *)z)->i_prefix = 2;
308 0 : break;
309 0 : lab0:
310 0 : z->c = v_1;
311 0 : if (z->c == z->l || z->p[z->c] != 'l') goto lab1;
312 0 : z->c++;
313 0 : z->ket = z->c;
314 0 : if (!(eq_s(z, 4, s_4))) goto lab1;
315 0 : break;
316 0 : lab1:
317 0 : z->c = v_1;
318 0 : z->ket = z->c;
319 0 : ((SN_local *)z)->i_prefix = 2;
320 : } while (0);
321 0 : break;
322 0 : case 2:
323 : do {
324 0 : int v_2 = z->c;
325 0 : if (z->c == z->l || z->p[z->c] != 'r') goto lab2;
326 0 : z->c++;
327 0 : z->ket = z->c;
328 0 : break;
329 0 : lab2:
330 0 : z->c = v_2;
331 0 : if (z->c == z->l || z->p[z->c] != 'l') goto lab3;
332 0 : z->c++;
333 0 : z->ket = z->c;
334 0 : if (!(eq_s(z, 4, s_5))) goto lab3;
335 0 : break;
336 0 : lab3:
337 0 : z->c = v_2;
338 0 : z->ket = z->c;
339 0 : if (out_grouping_U(z, g_vowel, 97, 117, 0)) return 0;
340 0 : if (!(eq_s(z, 2, s_6))) return 0;
341 : } while (0);
342 0 : ((SN_local *)z)->i_prefix = 4;
343 0 : break;
344 : }
345 0 : ((SN_local *)z)->i_measure -= 1;
346 : {
347 0 : int ret = slice_del(z);
348 0 : if (ret < 0) return ret;
349 : }
350 0 : return 1;
351 : }
352 :
353 0 : extern int indonesian_UTF_8_stem(struct SN_env * z) {
354 0 : ((SN_local *)z)->i_measure = 0;
355 : {
356 0 : int v_1 = z->c;
357 0 : while (1) {
358 0 : int v_2 = z->c;
359 : {
360 0 : int ret = out_grouping_U(z, g_vowel, 97, 117, 1);
361 0 : if (ret < 0) goto lab1;
362 0 : z->c += ret;
363 : }
364 0 : ((SN_local *)z)->i_measure += 1;
365 0 : continue;
366 0 : lab1:
367 0 : z->c = v_2;
368 0 : break;
369 : }
370 0 : z->c = v_1;
371 : }
372 0 : if (((SN_local *)z)->i_measure <= 2) return 0;
373 0 : ((SN_local *)z)->i_prefix = 0;
374 0 : z->lb = z->c; z->c = z->l;
375 : {
376 0 : int v_3 = z->l - z->c;
377 : {
378 0 : int ret = r_remove_particle(z);
379 0 : if (ret < 0) return ret;
380 : }
381 0 : z->c = z->l - v_3;
382 : }
383 0 : if (((SN_local *)z)->i_measure <= 2) return 0;
384 : {
385 0 : int v_4 = z->l - z->c;
386 : {
387 0 : int ret = r_remove_possessive_pronoun(z);
388 0 : if (ret < 0) return ret;
389 : }
390 0 : z->c = z->l - v_4;
391 : }
392 0 : z->c = z->lb;
393 0 : if (((SN_local *)z)->i_measure <= 2) return 0;
394 : do {
395 0 : int v_5 = z->c;
396 : {
397 0 : int v_6 = z->c;
398 : {
399 0 : int ret = r_remove_first_order_prefix(z);
400 0 : if (ret == 0) goto lab2;
401 0 : if (ret < 0) return ret;
402 : }
403 : {
404 0 : int v_7 = z->c;
405 : {
406 0 : int v_8 = z->c;
407 0 : if (((SN_local *)z)->i_measure <= 2) goto lab3;
408 0 : z->lb = z->c; z->c = z->l;
409 : {
410 0 : int ret = r_remove_suffix(z);
411 0 : if (ret == 0) goto lab3;
412 0 : if (ret < 0) return ret;
413 : }
414 0 : z->c = z->lb;
415 0 : z->c = v_8;
416 : }
417 0 : if (((SN_local *)z)->i_measure <= 2) goto lab3;
418 : {
419 0 : int ret = r_remove_second_order_prefix(z);
420 0 : if (ret == 0) goto lab3;
421 0 : if (ret < 0) return ret;
422 : }
423 0 : lab3:
424 0 : z->c = v_7;
425 : }
426 0 : z->c = v_6;
427 : }
428 0 : break;
429 0 : lab2:
430 0 : z->c = v_5;
431 : {
432 0 : int v_9 = z->c;
433 : {
434 0 : int ret = r_remove_second_order_prefix(z);
435 0 : if (ret < 0) return ret;
436 : }
437 0 : z->c = v_9;
438 : }
439 : {
440 0 : int v_10 = z->c;
441 0 : if (((SN_local *)z)->i_measure <= 2) goto lab4;
442 0 : z->lb = z->c; z->c = z->l;
443 : {
444 0 : int ret = r_remove_suffix(z);
445 0 : if (ret == 0) goto lab4;
446 0 : if (ret < 0) return ret;
447 : }
448 0 : z->c = z->lb;
449 0 : lab4:
450 0 : z->c = v_10;
451 : }
452 : } while (0);
453 0 : return 1;
454 : }
455 :
456 0 : extern struct SN_env * indonesian_UTF_8_create_env(void) {
457 0 : struct SN_env * z = SN_new_env(sizeof(SN_local));
458 0 : if (z) {
459 0 : ((SN_local *)z)->i_prefix = 0;
460 0 : ((SN_local *)z)->i_measure = 0;
461 : }
462 0 : return z;
463 : }
464 :
465 0 : extern void indonesian_UTF_8_close_env(struct SN_env * z) {
466 0 : SN_delete_env(z);
467 0 : }
468 :
|