-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswedish_stemmer.ts
231 lines (220 loc) · 4.79 KB
/
swedish_stemmer.ts
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
import { Rule, Stemmer } from "./_stemmer.ts";
const a_0: Rule[] = [
["a", -1, 1],
["arna", 0, 1],
["erna", 0, 1],
["heterna", 2, 1],
["orna", 0, 1],
["ad", -1, 1],
["e", -1, 1],
["ade", 6, 1],
["ande", 6, 1],
["arne", 6, 1],
["are", 6, 1],
["aste", 6, 1],
["en", -1, 1],
["anden", 12, 1],
["aren", 12, 1],
["heten", 12, 1],
["ern", -1, 1],
["ar", -1, 1],
["er", -1, 1],
["heter", 18, 1],
["or", -1, 1],
["s", -1, 2],
["as", 21, 1],
["arnas", 22, 1],
["ernas", 22, 1],
["ornas", 22, 1],
["es", 21, 1],
["ades", 26, 1],
["andes", 26, 1],
["ens", 21, 1],
["arens", 29, 1],
["hetens", 29, 1],
["erns", 21, 1],
["at", -1, 1],
["andet", -1, 1],
["het", -1, 1],
["ast", -1, 1],
];
const a_1: Rule[] = [
["dd", -1, -1],
["gd", -1, -1],
["nn", -1, -1],
["dt", -1, -1],
["gt", -1, -1],
["kt", -1, -1],
["tt", -1, -1],
];
const a_2: Rule[] = [
["ig", -1, 1],
["lig", 0, 1],
["els", -1, 1],
["fullt", -1, 3],
["l\u00F6st", -1, 2],
];
const g_v = [17, 65, 16, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 32];
const g_s_ending = [119, 127, 149];
/** Stemmer for the Swedish language */
export class SwedishStemmer extends Stemmer {
private I_x = 0;
private I_p1 = 0;
private r_mark_regions() {
this.I_p1 = this.limit;
const v_1 = this.cursor;
{
const c1 = this.cursor + 3;
if (c1 > this.limit) {
return false;
}
this.cursor = c1;
}
this.I_x = this.cursor;
this.cursor = v_1;
golab0:
while (true) {
const v_2 = this.cursor;
lab1: {
if (!this.in_grouping(g_v, 97, 246)) {
break lab1;
}
this.cursor = v_2;
break golab0;
}
this.cursor = v_2;
if (this.cursor >= this.limit) {
return false;
}
this.cursor++;
}
golab2:
while (true) {
lab3: {
if (!this.out_grouping(g_v, 97, 246)) {
break lab3;
}
break golab2;
}
if (this.cursor >= this.limit) {
return false;
}
this.cursor++;
}
this.I_p1 = this.cursor;
lab4: {
if (!(this.I_p1 < this.I_x)) {
break lab4;
}
this.I_p1 = this.I_x;
}
return true;
}
private r_main_suffix() {
if (this.cursor < this.I_p1) {
return false;
}
const v_2 = this.limit_backward;
this.limit_backward = this.I_p1;
this.ket = this.cursor;
const among_var = this.find_among_b(a_0);
if (among_var == 0) {
this.limit_backward = v_2;
return false;
}
this.bra = this.cursor;
this.limit_backward = v_2;
switch (among_var) {
case 1:
if (!this.slice_del()) {
return false;
}
break;
case 2:
if (!this.in_grouping_b(g_s_ending, 98, 121)) {
return false;
}
if (!this.slice_del()) {
return false;
}
break;
}
return true;
}
private r_consonant_pair() {
if (this.cursor < this.I_p1) {
return false;
}
const v_2 = this.limit_backward;
this.limit_backward = this.I_p1;
const v_3 = this.limit - this.cursor;
if (this.find_among_b(a_1) == 0) {
this.limit_backward = v_2;
return false;
}
this.cursor = this.limit - v_3;
this.ket = this.cursor;
if (this.cursor <= this.limit_backward) {
this.limit_backward = v_2;
return false;
}
this.cursor--;
this.bra = this.cursor;
if (!this.slice_del()) {
return false;
}
this.limit_backward = v_2;
return true;
}
private r_other_suffix() {
if (this.cursor < this.I_p1) {
return false;
}
const v_2 = this.limit_backward;
this.limit_backward = this.I_p1;
this.ket = this.cursor;
const among_var = this.find_among_b(a_2);
if (among_var == 0) {
this.limit_backward = v_2;
return false;
}
this.bra = this.cursor;
switch (among_var) {
case 1:
if (!this.slice_del()) {
return false;
}
break;
case 2:
if (!this.slice_from("l\u00F6s")) {
return false;
}
break;
case 3:
if (!this.slice_from("full")) {
return false;
}
break;
}
this.limit_backward = v_2;
return true;
}
_stemHelper() {
const v_1 = this.cursor;
this.r_mark_regions();
this.cursor = v_1;
this.limit_backward = this.cursor;
this.cursor = this.limit;
const v_2 = this.limit - this.cursor;
this.r_main_suffix();
this.cursor = this.limit - v_2;
const v_3 = this.limit - this.cursor;
this.r_consonant_pair();
this.cursor = this.limit - v_3;
const v_4 = this.limit - this.cursor;
this.r_other_suffix();
this.cursor = this.limit - v_4;
this.cursor = this.limit_backward;
return true;
}
}