| 1 |
/* |
| 2 |
* Authors: |
| 3 |
* - Assem Chelli, < assem [dot] ch [at] gmail > |
| 4 |
* - Abdelkrim Aries <ab [underscore] aries [at] esi [dot] dz> |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
stringescapes { } |
| 9 |
|
| 10 |
/* the Arabic letters in Unicode */ |
| 11 |
// Hamza |
| 12 |
stringdef o hex '621' // Hamza |
| 13 |
stringdef ao hex '623' // Hamza above Alef |
| 14 |
stringdef ao_ hex '625' // Hamza below Alef |
| 15 |
stringdef a~ hex '622' // Alef madda |
| 16 |
stringdef wo hex '624' // Hamza above waw |
| 17 |
stringdef yo hex '626' // Hamza above yeh |
| 18 |
|
| 19 |
// Letters |
| 20 |
stringdef a hex '627' // Alef |
| 21 |
stringdef a_ hex '649' // Alef Maksura |
| 22 |
stringdef b hex '628' // Beh |
| 23 |
stringdef t_ hex '629' // Teh_Marbuta |
| 24 |
stringdef t hex '62a' // Teh |
| 25 |
stringdef th hex '62b' // Theh |
| 26 |
stringdef j hex '62c' // Jeem |
| 27 |
stringdef h hex '62d' // Hah |
| 28 |
stringdef x hex '62e' // Khah |
| 29 |
stringdef d hex '62f' // Dal |
| 30 |
stringdef dz hex '630' // Thal |
| 31 |
stringdef r hex '631' // Reh |
| 32 |
stringdef z hex '632' // Zain |
| 33 |
stringdef s hex '633' // Seen |
| 34 |
stringdef sh hex '634' // Sheen |
| 35 |
stringdef c hex '635' // Sad |
| 36 |
stringdef dh hex '636' // Dad |
| 37 |
stringdef tt hex '637' // Tah |
| 38 |
stringdef zh hex '638' // Zah |
| 39 |
stringdef i hex '639' // Ain |
| 40 |
stringdef gh hex '63a' // Ghain |
| 41 |
stringdef f hex '641' // Feh |
| 42 |
stringdef q hex '642' // Qaf |
| 43 |
stringdef k hex '643' // Kaf |
| 44 |
stringdef l hex '644' // Lam |
| 45 |
stringdef m hex '645' // Meem |
| 46 |
stringdef n hex '646' // Noon |
| 47 |
stringdef e hex '647' // Heh |
| 48 |
stringdef w hex '648' // Waw |
| 49 |
stringdef y hex '64a' // Yeh |
| 50 |
|
| 51 |
// Diacritics |
| 52 |
stringdef aan hex '64b' // FatHatan |
| 53 |
stringdef uun hex '64c' // Dammatan |
| 54 |
stringdef iin hex '64d' // Kasratan |
| 55 |
stringdef aa hex '64e' // FatHa |
| 56 |
stringdef uu hex '64f' // Damma |
| 57 |
stringdef ii hex '650' // Kasra |
| 58 |
stringdef oo hex '652' // Sukun |
| 59 |
stringdef ~ hex '651' // Shadda |
| 60 |
|
| 61 |
// Hindu–Arabic numerals |
| 62 |
stringdef 0 hex '0660' |
| 63 |
stringdef 1 hex '0661' |
| 64 |
stringdef 2 hex '0662' |
| 65 |
stringdef 3 hex '0663' |
| 66 |
stringdef 4 hex '0664' |
| 67 |
stringdef 5 hex '0665' |
| 68 |
stringdef 6 hex '0666' |
| 69 |
stringdef 7 hex '0667' |
| 70 |
stringdef 8 hex '0668' |
| 71 |
stringdef 9 hex '0669' |
| 72 |
stringdef % hex '066a' // PERCENT |
| 73 |
stringdef . hex '066b' // DECIMAL |
| 74 |
stringdef ' hex '066c' // THOUSANDS |
| 75 |
|
| 76 |
// Kasheeda |
| 77 |
stringdef _ hex '640' // Kasheeda, Tatweel |
| 78 |
|
| 79 |
// Ponctuation marks |
| 80 |
stringdef , hex '060C' // COMMA |
| 81 |
stringdef ; hex '061B' // SEMICOLON |
| 82 |
stringdef ? hex '061F' // QUESTION |
| 83 |
|
| 84 |
// Shaped forms |
| 85 |
stringdef o1 hex 'fe80' // HAMZA |
| 86 |
stringdef ao1 hex 'fe83' // ALEF_HAMZA_ABOVE |
| 87 |
stringdef ao2 hex 'fe84' // ALEF_HAMZA_ABOVE |
| 88 |
stringdef ao_1 hex 'fe87' // ALEF_HAMZA_BELOW |
| 89 |
stringdef ao_2 hex 'fe88' // ALEF_HAMZA_BELOW |
| 90 |
stringdef yo1 hex 'fe8b' // YEH_HAMZA |
| 91 |
stringdef yo2 hex 'fe8c' // YEH_HAMZA |
| 92 |
stringdef yo3 hex 'fe89' // YEH_HAMZA |
| 93 |
stringdef yo4 hex 'fe8a' // YEH_HAMZA |
| 94 |
stringdef a~1 hex 'fe81' // ALEF_MADDA |
| 95 |
stringdef a~2 hex 'fe82' // ALEF_MADDA |
| 96 |
stringdef wo1 hex 'fe85' // WAW_HAMZA |
| 97 |
stringdef wo2 hex 'fe86' // WAW_HAMZA |
| 98 |
stringdef a1 hex 'fe8d' // ALEF |
| 99 |
stringdef a2 hex 'fe8e' // ALEF |
| 100 |
stringdef b1 hex 'fe8f' // BEH |
| 101 |
stringdef b2 hex 'fe90' // BEH |
| 102 |
stringdef b3 hex 'fe91' // BEH |
| 103 |
stringdef b4 hex 'fe92' // BEH |
| 104 |
stringdef t_1 hex 'fe93' // TEH_MARBUTA |
| 105 |
stringdef t_2 hex 'fe94' // TEH_MARBUTA |
| 106 |
stringdef t1 hex 'fe97' // TEH |
| 107 |
stringdef t2 hex 'fe98' // TEH |
| 108 |
stringdef t3 hex 'fe95' // TEH |
| 109 |
stringdef t4 hex 'fe96' // TEH |
| 110 |
stringdef th1 hex 'fe9b' // THEH |
| 111 |
stringdef th2 hex 'fe9c' // THEH |
| 112 |
stringdef th3 hex 'fe9a' // THEH |
| 113 |
stringdef th4 hex 'fe99' // THEH |
| 114 |
stringdef j1 hex 'fe9f' // JEEM |
| 115 |
stringdef j2 hex 'fea0' // JEEM |
| 116 |
stringdef j3 hex 'fe9d' // JEEM |
| 117 |
stringdef j4 hex 'fe9e' // JEEM |
| 118 |
stringdef h1 hex 'fea3' // HAH |
| 119 |
stringdef h2 hex 'fea4' // HAH |
| 120 |
stringdef h3 hex 'fea1' // HAH |
| 121 |
stringdef h4 hex 'fea2' // HAH |
| 122 |
stringdef x1 hex 'fea7' // KHAH |
| 123 |
stringdef x2 hex 'fea8' // KHAH |
| 124 |
stringdef x3 hex 'fea5' // KHAH |
| 125 |
stringdef x4 hex 'fea6' // KHAH |
| 126 |
stringdef d1 hex 'fea9' // DAL |
| 127 |
stringdef d2 hex 'feaa' // DAL |
| 128 |
stringdef dz1 hex 'feab' // THAL |
| 129 |
stringdef dz2 hex 'feac' // THAL |
| 130 |
stringdef r1 hex 'fead' // REH |
| 131 |
stringdef r2 hex 'feae' // REH |
| 132 |
stringdef z1 hex 'feaf' // ZAIN |
| 133 |
stringdef z2 hex 'feb0' // ZAIN |
| 134 |
stringdef s1 hex 'feb3' // SEEN |
| 135 |
stringdef s2 hex 'feb4' // SEEN |
| 136 |
stringdef s3 hex 'feb1' // SEEN |
| 137 |
stringdef s4 hex 'feb2' // SEEN |
| 138 |
stringdef sh1 hex 'feb7' // SHEEN |
| 139 |
stringdef sh2 hex 'feb8' // SHEEN |
| 140 |
stringdef sh3 hex 'feb5' // SHEEN |
| 141 |
stringdef sh4 hex 'feb6' // SHEEN |
| 142 |
stringdef c1 hex 'febb' // SAD |
| 143 |
stringdef c2 hex 'febc' // SAD |
| 144 |
stringdef c3 hex 'feb9' // SAD |
| 145 |
stringdef c4 hex 'feba' // SAD |
| 146 |
stringdef dh1 hex 'febf' // DAD |
| 147 |
stringdef dh2 hex 'fec0' // DAD |
| 148 |
stringdef dh3 hex 'febd' // DAD |
| 149 |
stringdef dh4 hex 'febe' // DAD |
| 150 |
stringdef tt1 hex 'fec3' // TAH |
| 151 |
stringdef tt2 hex 'fec4' // TAH |
| 152 |
stringdef tt3 hex 'fec1' // TAH |
| 153 |
stringdef tt4 hex 'fec2' // TAH |
| 154 |
stringdef zh1 hex 'fec7' // ZAH |
| 155 |
stringdef zh2 hex 'fec8' // ZAH |
| 156 |
stringdef zh3 hex 'fec5' // ZAH |
| 157 |
stringdef zh4 hex 'fec6' // ZAH |
| 158 |
stringdef i1 hex 'fecb' // AIN |
| 159 |
stringdef i2 hex 'fecc' // AIN |
| 160 |
stringdef i3 hex 'fec9' // AIN |
| 161 |
stringdef i4 hex 'feca' // AIN |
| 162 |
stringdef gh1 hex 'fecf' // GHAIN |
| 163 |
stringdef gh2 hex 'fed0' // GHAIN |
| 164 |
stringdef gh3 hex 'fecd' // GHAIN |
| 165 |
stringdef gh4 hex 'fece' // GHAIN |
| 166 |
stringdef f1 hex 'fed3' // FEH |
| 167 |
stringdef f2 hex 'fed4' // FEH |
| 168 |
stringdef f3 hex 'fed1' // FEH |
| 169 |
stringdef f4 hex 'fed2' // FEH |
| 170 |
stringdef q1 hex 'fed7' // QAF |
| 171 |
stringdef q2 hex 'fed8' // QAF |
| 172 |
stringdef q3 hex 'fed5' // QAF |
| 173 |
stringdef q4 hex 'fed6' // QAF |
| 174 |
stringdef k1 hex 'fedb' // KAF |
| 175 |
stringdef k2 hex 'fedc' // KAF |
| 176 |
stringdef k3 hex 'fed9' // KAF |
| 177 |
stringdef k4 hex 'feda' // KAF |
| 178 |
stringdef l1 hex 'fedf' // LAM |
| 179 |
stringdef l2 hex 'fee0' // LAM |
| 180 |
stringdef l3 hex 'fedd' // LAM |
| 181 |
stringdef l4 hex 'fede' // LAM |
| 182 |
stringdef m1 hex 'fee3' // MEEM |
| 183 |
stringdef m2 hex 'fee4' // MEEM |
| 184 |
stringdef m3 hex 'fee1' // MEEM |
| 185 |
stringdef m4 hex 'fee2' // MEEM |
| 186 |
stringdef n1 hex 'fee7' // NOON |
| 187 |
stringdef n2 hex 'fee8' // NOON |
| 188 |
stringdef n3 hex 'fee5' // NOON |
| 189 |
stringdef n4 hex 'fee6' // NOON |
| 190 |
stringdef e1 hex 'feeb' // HEH |
| 191 |
stringdef e2 hex 'feec' // HEH |
| 192 |
stringdef e3 hex 'fee9' // HEH |
| 193 |
stringdef e4 hex 'feea' // HEH |
| 194 |
stringdef w1 hex 'feed' // WAW |
| 195 |
stringdef w2 hex 'feee' // WAW |
| 196 |
stringdef a_1 hex 'feef' // ALEF_MAKSURA |
| 197 |
stringdef a_2 hex 'fef0' // ALEF_MAKSURA |
| 198 |
stringdef y1 hex 'fef3' // YEH |
| 199 |
stringdef y2 hex 'fef4' // YEH |
| 200 |
stringdef y3 hex 'fef1' // YEH |
| 201 |
stringdef y4 hex 'fef2' // YEH |
| 202 |
|
| 203 |
// Ligatures Lam-Alef |
| 204 |
stringdef la hex 'fefb' // LAM_ALEF |
| 205 |
stringdef la2 hex 'fefc' // LAM_ALEF |
| 206 |
stringdef lao hex 'fef7' // LAM_ALEF_HAMZA_ABOVE |
| 207 |
stringdef lao2 hex 'fef8' // LAM_ALEF_HAMZA_ABOVE |
| 208 |
stringdef lao_ hex 'fef9' // LAM_ALEF_HAMZA_BELOW |
| 209 |
stringdef lao_2 hex 'fefa' // LAM_ALEF_HAMZA_BELOW |
| 210 |
stringdef la~ hex 'fef5' // LAM_ALEF_MADDA_ABOVE |
| 211 |
stringdef la~2 hex 'fef6' // LAM_ALEF_MADDA_ABOVE |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
integers ( |
| 216 |
word_len |
| 217 |
) |
| 218 |
|
| 219 |
booleans ( |
| 220 |
is_noun |
| 221 |
is_verb |
| 222 |
is_defined |
| 223 |
) |
| 224 |
|
| 225 |
routines ( |
| 226 |
Prefix_Step1 |
| 227 |
Prefix_Step2 |
| 228 |
Prefix_Step3a_Noun |
| 229 |
Prefix_Step3b_Noun |
| 230 |
Prefix_Step3_Verb |
| 231 |
Prefix_Step4_Verb |
| 232 |
|
| 233 |
Suffix_All_alef_maqsura |
| 234 |
Suffix_Noun_Step1a |
| 235 |
Suffix_Noun_Step1b |
| 236 |
Suffix_Noun_Step2a |
| 237 |
Suffix_Noun_Step2b |
| 238 |
Suffix_Noun_Step2c1 |
| 239 |
Suffix_Noun_Step2c2 |
| 240 |
Suffix_Noun_Step3 |
| 241 |
Suffix_Verb_Step1 |
| 242 |
Suffix_Verb_Step2a |
| 243 |
Suffix_Verb_Step2b |
| 244 |
Suffix_Verb_Step2c |
| 245 |
|
| 246 |
Normalize_post |
| 247 |
Normalize_pre |
| 248 |
|
| 249 |
Checks1 |
| 250 |
) |
| 251 |
|
| 252 |
externals ( stem ) |
| 253 |
|
| 254 |
groupings ( ) |
| 255 |
|
| 256 |
|
| 257 |
// Normalizations |
| 258 |
define Normalize_pre as ( |
| 259 |
loop len ( |
| 260 |
( |
| 261 |
[substring] among ( |
| 262 |
'{aan}' '{uun}' '{iin}' '{aa}' '{uu}' '{ii}' '{oo}' '{~}'( delete ) // strip vocalization |
| 263 |
'{_}' ( delete ) // strip kasheeda |
| 264 |
|
| 265 |
// Ponctuation marks |
| 266 |
'.' ',' ';' ':' '?' '!' '/' '*' '%' '\' '"' ( delete) // General |
| 267 |
'{,}' '{;}' '{?}' ( delete ) // Arabic-specific |
| 268 |
|
| 269 |
// Hindu–Arabic numerals |
| 270 |
'{0}' ( <- '0') |
| 271 |
'{1}' ( <- '1') |
| 272 |
'{2}' ( <- '2') |
| 273 |
'{3}' ( <- '3') |
| 274 |
'{4}' ( <- '4') |
| 275 |
'{5}' ( <- '5') |
| 276 |
'{6}' ( <- '6') |
| 277 |
'{7}' ( <- '7') |
| 278 |
'{8}' ( <- '8') |
| 279 |
'{9}' ( <- '9') |
| 280 |
'{%}' '{.}' '{'}' ( delete ) |
| 281 |
|
| 282 |
// Shaped forms |
| 283 |
'{o1}' ( <- '{o}' ) // HAMZA |
| 284 |
'{ao1}' '{ao2}' ( <- '{ao}' ) // ALEF_HAMZA_ABOVE |
| 285 |
'{ao_1}' '{ao_2}' ( <- '{ao_}' ) // ALEF_HAMZA_BELOW |
| 286 |
'{yo1}' '{yo2}' '{yo3}' '{yo4}' ( <- '{yo}' ) // YEH_HAMZA |
| 287 |
'{a~1}' '{a~2}'( <- '{a~}' ) // ALEF_MADDA |
| 288 |
'{wo1}' '{wo2}'( <- '{wo}' ) // WAW_HAMZA |
| 289 |
'{a1}' '{a2}' ( <- '{a}' ) // ALEF |
| 290 |
'{b1}' '{b2}' '{b3}' '{b4}' ( <- '{b}' ) // BEH |
| 291 |
'{t_1}' '{t_2}' ( <- '{t_}' ) // TEH_MARBUTA |
| 292 |
'{t1}' '{t2}' '{t3}' '{t4}' ( <- '{t}' ) // TEH |
| 293 |
'{th1}' '{th2}' '{th3}' '{th4}' ( <- '{th}' ) // THEH |
| 294 |
'{j1}' '{j2}' '{j3}' '{j4}'( <- '{j}' ) // JEEM |
| 295 |
'{h1}' '{h2}' '{h3}' '{h4}' ( <- '{h}' ) // HAH |
| 296 |
'{x1}' '{x2}' '{x3}' '{x4}'( <- '{x}' ) // KHAH |
| 297 |
'{d1}' '{d2}' ( <- '{d}' ) // DAL |
| 298 |
'{dz1}''{dz2}' ( <- '{dz}' ) // THAL |
| 299 |
'{r1}' '{r2}'( <- '{r}' ) // REH |
| 300 |
'{z1}' '{z2}' ( <- '{z}' ) // ZAIN |
| 301 |
'{s1}' '{s2}' '{s3}' '{s4}'( <- '{s}' ) // SEEN |
| 302 |
'{sh1}' '{sh2}' '{sh3}' '{sh4}' ( <- '{sh}' ) // SHEEN |
| 303 |
'{c1}' '{c2}' '{c3}' '{c4}'( <- '{c}' ) // SAD |
| 304 |
'{dh1}' '{dh2}' '{dh3}' '{dh4}'( <- '{dh}' ) // DAD |
| 305 |
'{tt1}' '{tt2}' '{tt3}' '{tt4}' ( <- '{tt}' ) // TAH |
| 306 |
'{zh1}' '{zh2}' '{zh3}' '{zh4}'( <- '{zh}' ) // ZAH |
| 307 |
'{i1}' '{i2}' '{i3}' '{i4}'( <- '{i}' ) // AIN |
| 308 |
'{gh1}' '{gh2}' '{gh3}' '{gh4}'( <- '{gh}' ) // GHAIN |
| 309 |
'{f1}' '{f2}' '{f3}' '{f4}' ( <- '{f}' ) // FEH |
| 310 |
'{q1}' '{q2}' '{q3}' '{q4}' ( <- '{q}' ) // QAF |
| 311 |
'{k1}' '{k2}' '{k3}' '{k4}'( <- '{k}' ) // KAF |
| 312 |
'{l1}' '{l2}' '{l3}' '{l4}'( <- '{l}' ) // LAM |
| 313 |
'{m1}' '{m2}' '{m3}' '{m4}' ( <- '{m}' ) // MEEM |
| 314 |
'{n1}' '{n2}' '{n3}' '{n4}'( <- '{n}' ) // NOON |
| 315 |
'{e1}' '{e2}' '{e3}' '{e4}' ( <- '{e}' ) // HEH |
| 316 |
'{w1}' '{w2}' ( <- '{w}' ) // WAW |
| 317 |
'{a_1}' '{a_2}' ( <- '{a_}' ) // ALEF_MAKSURA |
| 318 |
'{y1}' '{y2}' '{y3}' '{y4}' ( <- '{y}' ) // YEH |
| 319 |
|
| 320 |
// Ligatures Lam-Alef |
| 321 |
'{la}' '{la2}' (<- '{l}{a}') |
| 322 |
'{lao}' '{lao2}' (<- '{l}{ao}') |
| 323 |
'{lao_}' '{lao_2}' (<- '{l}{ao_}') |
| 324 |
'{la~}' '{la~2}' (<- '{l}{a~}') |
| 325 |
|
| 326 |
) |
| 327 |
) |
| 328 |
or |
| 329 |
next |
| 330 |
) |
| 331 |
) |
| 332 |
|
| 333 |
define Normalize_post as ( |
| 334 |
|
| 335 |
do ( |
| 336 |
// normalize last hamza |
| 337 |
backwards ( |
| 338 |
[substring] among ( |
| 339 |
'{ao}''{ao_}' '{a~}' ( <- '{o}') |
| 340 |
'{wo}' ( <- '{o}') |
| 341 |
'{yo}' ( <- '{o}') |
| 342 |
) |
| 343 |
) |
| 344 |
) |
| 345 |
|
| 346 |
do loop word_len ( |
| 347 |
( |
| 348 |
// normalize other hamza's |
| 349 |
[substring] among ( |
| 350 |
'{ao}''{ao_}' '{a~}' ( <- '{a}') |
| 351 |
'{wo}' ( <- '{w}') |
| 352 |
'{yo}' ( <- '{y}') |
| 353 |
) |
| 354 |
) |
| 355 |
or |
| 356 |
next |
| 357 |
) |
| 358 |
) |
| 359 |
|
| 360 |
// Checks |
| 361 |
define Checks1 as ( |
| 362 |
$word_len = len |
| 363 |
[substring] among ( |
| 364 |
'{b}{a}{l}' '{k}{a}{l}' ($word_len > 4 set is_noun unset is_verb set is_defined) |
| 365 |
'{l}{l}' '{a}{l}' ($word_len > 3 set is_noun unset is_verb set is_defined) |
| 366 |
) |
| 367 |
) |
| 368 |
|
| 369 |
|
| 370 |
//prefixes |
| 371 |
define Prefix_Step1 as ( |
| 372 |
$word_len = len |
| 373 |
[substring] among ( |
| 374 |
'{ao}{ao}' ($word_len > 3 <- '{ao}' ) |
| 375 |
'{ao}{a~}' ($word_len > 3 <- '{a~}' ) |
| 376 |
'{ao}{wo}' ($word_len > 3 <- '{ao}' ) |
| 377 |
'{ao}{a}' ($word_len > 3 <- '{a}' ) |
| 378 |
'{ao}{ao_}' ($word_len > 3 <- '{ao_}' ) |
| 379 |
// '{ao}' ($word_len > 3 delete) //rare case |
| 380 |
) |
| 381 |
) |
| 382 |
|
| 383 |
define Prefix_Step2 as ( |
| 384 |
$word_len = len |
| 385 |
not '{f}{a}' |
| 386 |
not '{w}{a}' |
| 387 |
[substring] among ( |
| 388 |
'{f}' ($word_len > 3 delete) |
| 389 |
'{w}' ($word_len > 3 delete) |
| 390 |
) |
| 391 |
) |
| 392 |
|
| 393 |
define Prefix_Step3a_Noun as ( // it is noun and defined |
| 394 |
$word_len = len |
| 395 |
[substring] among ( |
| 396 |
'{b}{a}{l}' '{k}{a}{l}' ($word_len > 5 delete) |
| 397 |
'{l}{l}' '{a}{l}' ($word_len > 4 delete) |
| 398 |
) |
| 399 |
) |
| 400 |
|
| 401 |
define Prefix_Step3b_Noun as ( // probably noun and defined |
| 402 |
$word_len = len |
| 403 |
not '{b}{a}' // exception |
| 404 |
[substring] among ( |
| 405 |
'{b}' ($word_len > 3 delete) |
| 406 |
// '{k}' '{l}' ($word_len > 3 delete) // BUG: cause confusion |
| 407 |
'{b}{b}' ($word_len > 3 <- '{b}' ) |
| 408 |
'{k}{k}' ($word_len > 3 <- '{k}' ) |
| 409 |
) |
| 410 |
|
| 411 |
) |
| 412 |
|
| 413 |
define Prefix_Step3_Verb as ( |
| 414 |
$word_len = len |
| 415 |
[substring] among ( |
| 416 |
//'{s}' ($word_len > 4 delete)// BUG: cause confusion |
| 417 |
'{s}{y}' ($word_len > 4 <- '{y}' ) |
| 418 |
'{s}{t}' ($word_len > 4 <- '{t}') |
| 419 |
'{s}{n}' ($word_len > 4 <- '{n}') |
| 420 |
'{s}{ao}' ($word_len > 4 <- '{ao}') |
| 421 |
) |
| 422 |
) |
| 423 |
|
| 424 |
define Prefix_Step4_Verb as ( |
| 425 |
$word_len = len |
| 426 |
[substring] among ( |
| 427 |
'{y}{s}{t}' '{n}{s}{t}' '{t}{s}{t}' ($word_len > 4 set is_verb unset is_noun <- '{a}{s}{t}' ) |
| 428 |
) |
| 429 |
) |
| 430 |
|
| 431 |
// suffixes |
| 432 |
backwardmode ( |
| 433 |
|
| 434 |
define Suffix_Noun_Step1a as ( |
| 435 |
$word_len = len |
| 436 |
[substring] among ( |
| 437 |
'{y}' '{k}' '{e}' ($word_len >= 4 delete) |
| 438 |
'{n}{a}' '{k}{m}' '{e}{a}' '{e}{n}' '{e}{m}' ($word_len >= 5 delete) |
| 439 |
'{k}{m}{a}' '{e}{m}{a}' ($word_len >= 6 delete) |
| 440 |
) |
| 441 |
) |
| 442 |
define Suffix_Noun_Step1b as ( |
| 443 |
$word_len = len |
| 444 |
[substring] among ( |
| 445 |
'{n}' ($word_len > 5 delete) |
| 446 |
) |
| 447 |
) |
| 448 |
|
| 449 |
define Suffix_Noun_Step2a as ( |
| 450 |
$word_len = len |
| 451 |
[substring] among ( |
| 452 |
'{a}' '{y}' '{w}' ($word_len > 4 delete) |
| 453 |
) |
| 454 |
) |
| 455 |
|
| 456 |
define Suffix_Noun_Step2b as ( |
| 457 |
$word_len = len |
| 458 |
[substring] among ( |
| 459 |
'{a}{t}' ($word_len >= 5 delete) |
| 460 |
) |
| 461 |
) |
| 462 |
|
| 463 |
define Suffix_Noun_Step2c1 as ( |
| 464 |
$word_len = len |
| 465 |
[substring] among ( |
| 466 |
'{t}' ($word_len >= 4 delete) |
| 467 |
) |
| 468 |
) |
| 469 |
define Suffix_Noun_Step2c2 as ( // feminine t_ |
| 470 |
$word_len = len |
| 471 |
[substring] among ( |
| 472 |
'{t_}' ($word_len >= 4 delete) |
| 473 |
) |
| 474 |
) |
| 475 |
define Suffix_Noun_Step3 as ( // ya' nisbiya |
| 476 |
$word_len = len |
| 477 |
[substring] among ( |
| 478 |
'{y}' ($word_len >= 3 delete) |
| 479 |
) |
| 480 |
) |
| 481 |
|
| 482 |
define Suffix_Verb_Step1 as ( |
| 483 |
$word_len = len |
| 484 |
[substring] among ( |
| 485 |
'{e}' '{k}' ($word_len >= 4 delete) |
| 486 |
'{n}{y}' '{n}{a}' '{e}{a}' '{e}{m}' '{e}{n}' '{k}{m}' '{k}{n}' ($word_len >= 5 delete) |
| 487 |
'{e}{m}{a}' '{k}{m}{a}' '{k}{m}{w}'($word_len >= 6 delete) |
| 488 |
) |
| 489 |
) |
| 490 |
define Suffix_Verb_Step2a as ( |
| 491 |
$word_len = len |
| 492 |
[substring] among ( |
| 493 |
'{t}' ($word_len >= 4 delete) |
| 494 |
'{a}' '{n}' '{y}' ($word_len >= 4 delete) |
| 495 |
'{n}{a}' '{t}{a}' '{t}{n}' ($word_len >= 5 delete)// past |
| 496 |
'{a}{n}' '{w}{n}' '{y}{n}' ($word_len > 5 delete) // present |
| 497 |
'{t}{m}{a}' ($word_len >= 6 delete) |
| 498 |
) |
| 499 |
) |
| 500 |
|
| 501 |
define Suffix_Verb_Step2b as ( |
| 502 |
$word_len = len |
| 503 |
[substring] among ( |
| 504 |
'{w}{a}' '{t}{m}' ($word_len >= 5 delete) // len >= 5 |
| 505 |
) |
| 506 |
) |
| 507 |
|
| 508 |
|
| 509 |
define Suffix_Verb_Step2c as ( |
| 510 |
$word_len = len |
| 511 |
[substring] among ( |
| 512 |
'{w}' ($word_len >= 4 delete) |
| 513 |
'{t}{m}{w}' ($word_len >= 6 delete) |
| 514 |
) |
| 515 |
) |
| 516 |
|
| 517 |
define Suffix_All_alef_maqsura as ( |
| 518 |
$word_len = len |
| 519 |
[substring] among ( |
| 520 |
'{a_}' ( <- '{y}' ) // spell error |
| 521 |
// '{a_}' ( delete ) // if noun > 3 |
| 522 |
// '{a_}' ( <- '{a}') // if verb |
| 523 |
) |
| 524 |
) |
| 525 |
) |
| 526 |
|
| 527 |
define stem as ( |
| 528 |
// set initial values |
| 529 |
set is_noun |
| 530 |
set is_verb |
| 531 |
unset is_defined |
| 532 |
|
| 533 |
// guess type and properties |
| 534 |
do Checks1 |
| 535 |
|
| 536 |
// normalization pre-stemming |
| 537 |
do Normalize_pre |
| 538 |
|
| 539 |
|
| 540 |
backwards ( |
| 541 |
|
| 542 |
do ( |
| 543 |
//Suffixes for verbs |
| 544 |
( |
| 545 |
is_verb |
| 546 |
( |
| 547 |
( |
| 548 |
(atleast 1 Suffix_Verb_Step1) |
| 549 |
( Suffix_Verb_Step2a or Suffix_Verb_Step2c or next) |
| 550 |
) |
| 551 |
or Suffix_Verb_Step2b |
| 552 |
or Suffix_Verb_Step2a |
| 553 |
) |
| 554 |
) |
| 555 |
//Suffixes for nouns |
| 556 |
or ( |
| 557 |
is_noun |
| 558 |
( |
| 559 |
|
| 560 |
try ( |
| 561 |
Suffix_Noun_Step2c2 |
| 562 |
or (not is_defined Suffix_Noun_Step1a ( |
| 563 |
Suffix_Noun_Step2a |
| 564 |
or Suffix_Noun_Step2b |
| 565 |
or Suffix_Noun_Step2c1 |
| 566 |
or next)) |
| 567 |
or (Suffix_Noun_Step1b ( |
| 568 |
Suffix_Noun_Step2a |
| 569 |
or Suffix_Noun_Step2b |
| 570 |
or Suffix_Noun_Step2c1)) |
| 571 |
or (not is_defined Suffix_Noun_Step2a) |
| 572 |
or (Suffix_Noun_Step2b) |
| 573 |
) |
| 574 |
Suffix_Noun_Step3 |
| 575 |
) |
| 576 |
|
| 577 |
) |
| 578 |
|
| 579 |
// Suffixes for alef maqsura |
| 580 |
or Suffix_All_alef_maqsura |
| 581 |
) |
| 582 |
) |
| 583 |
|
| 584 |
//Prefixes |
| 585 |
do ( |
| 586 |
try Prefix_Step1 |
| 587 |
try Prefix_Step2 |
| 588 |
( Prefix_Step3a_Noun |
| 589 |
or (is_noun Prefix_Step3b_Noun) |
| 590 |
or (is_verb try Prefix_Step3_Verb Prefix_Step4_Verb) |
| 591 |
) |
| 592 |
) |
| 593 |
|
| 594 |
// normalization post-stemming |
| 595 |
do Normalize_post |
| 596 |
|
| 597 |
) |