00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "ffpriv_plural_stem.h"
00031 #include "ffpriv_genitive_stem.h"
00032 #include "ffpriv_essive_stem.h"
00033 #include "ffutil.h"
00034 #include "ffstring.h"
00035 #include "ffword.h"
00036 #include "ffregex.h"
00037 #include "ffpriv_ie_vowel_change.h"
00038
00039 ffint32 ffpriv_plural_stem(ffword* word) {
00040
00041 ffword gen;
00042 ffint32 err;
00043
00044
00045
00046
00047 if(!word->metadata.loan) {
00048 if (ffpriv_is_vowel(ffstring_last(&word->data))) {
00049
00050 if ((err = ffword_copy(word, &gen))) {
00051 return err;
00052 }
00053
00054 if ((err = ffpriv_genitive_stem(&gen))) {
00055 ffword_delete(&gen);
00056 return err;
00057 }
00058
00059
00060 if (gen.metadata.relic) {
00061 ffword_swap_delete(&gen,word);
00062 return ffstring_rfe(&word->data, 1 , "i");
00063 }
00064
00065
00066 if (ffstring_tail_equals_ci(&word->data, 5, "kolme")) {
00067 ffword_delete(&gen);
00068 return ffstring_rfe(&word->data, 1 , "i");
00069 }
00070
00071 if (ffstring_last_equals_ci(&word->data, 'i')) {
00072 ffword ori;
00073 ffint32 result;
00074
00075 if ((err = ffword_copy(word, &ori))) {
00076 ffword_delete(&gen);
00077 return err;
00078 }
00079
00080
00081
00082
00083 if (word->metadata.cg) {
00084 result = ffpriv_ie_partitive(word);
00085 } else {
00086 result = ffpriv_ie_genitive(word);
00087 }
00088
00089 if (result > 0) {
00090 ffword_delete(&gen);
00091
00092 if (ffstring_tail_equals_ci(&ori.data, 2, "si")) {
00093 ffword_swap_delete(&ori,word);
00094 return 0;
00095 }
00096
00097 ffword_delete(&ori);
00098 if (ffstring_last(&word->data) == 'e') {
00099 return ffstring_rfe(&word->data, 1 , "i");
00100 } else {
00101 return ffstring_append(&word->data, "i");
00102 }
00103 }
00104
00105 if (ffregex_match_ci("^.[aoeuyäö]i$", &word->data)) {
00106 return 0;
00107 }
00108
00109 ffword_delete(&ori);
00110 ffword_swap_delete(&gen,word);
00111 return ffstring_rfe(&word->data, 1 , "ei");
00112 }
00113
00114 if (ffregex_match_ci("^.(ie|uo|yö)$", &word->data)) {
00115 ffword_delete(&gen);
00116 return -!ffregex_replace_ci("(.).(.)", "${1}${2}i", &word->data);
00117 }
00118
00119
00120
00121
00122
00123 if (ffregex_match_ci("^.+(aa|ää|ee|ii|oo|öö|uu|yy)$", &word->data)) {
00124 ffword_swap_delete(&gen,word);
00125 return ffstring_rfe(&word->data, 1 , "i");
00126 }
00127
00128 if (ffstring_tail_equals_ci(&word->data, 3, "aja") || ffstring_tail_equals_ci(&word->data, 3, "äjä")) {
00129 ffword_swap_delete(&gen,word);
00130 return ffstring_rfe(&word->data, 1 , "i");
00131 }
00132
00133
00134
00135
00136
00137 if (ffstring_last_equals_ci(&word->data, 'ä')) {
00138 if (ffregex_match_ci("^[^aeiouyåäöÅÄÖ]*[aeiouyåäöÅÄÖ]+[^aeiouyåäöÅÄÖ]+[aeiouyåäöÅÄÖ]+[^aeiouyåäöÅÄÖ]ä$", &word->data)) {
00139 ffword_swap_delete(&gen,word);
00140 return ffstring_rfe(&word->data, 1 , "öi");
00141 }
00142
00143 ffword_swap_delete(&gen,word);
00144 return ffstring_rfe(&word->data, 1 , "i");
00145
00146 }
00147
00148 if (ffstring_last_equals_ci(&word->data, 'a')) {
00149 if (ffstring_tail_equals_ci(&word->data, 2, "ea") || ffregex_match_ci("^[^aeiouyåäöÅÄÖ][ou][aeiouyåäöÅÄÖ]*[^aeiouyåäöÅÄÖ]+a$", &word->data)) {
00150 ffword_swap_delete(&gen,word);
00151 return ffstring_rfe(&word->data, 1 , "i");
00152 }
00153
00154 ffword_swap_delete(&gen,word);
00155 return ffstring_rfe(&word->data, 1 , "oi");
00156
00157 }
00158
00159 ffword_swap_delete(&gen,word);
00160 return ffstring_append(&word->data, "i");
00161
00162 } else {
00163
00164 if (word->metadata.cg ) {
00165 ffword ess;
00166
00167 if ((err = ffword_copy(word, &ess))) {
00168 return err;
00169 }
00170
00171 if ((err = ffpriv_essive_stem(&ess))) {
00172 ffword_delete(&ess);
00173 return err;
00174 }
00175
00176 if (ffstring_tail_equals(&ess.data, 3, "nte")) {
00177 ffword_swap_delete(&ess,word);
00178 return ffstring_rfe(&word->data, 2, "si");
00179 }
00180
00181 if (ffstring_tail_equals(&ess.data, 2, "te")) {
00182 ffword_swap_delete(&ess,word);
00183 return ffstring_rfe(&word->data, 2, "ksi");
00184 }
00185
00186
00187
00188
00189
00190
00191
00192
00193 ffword_delete(&ess);
00194
00195 } else {
00196
00197 if ((err = ffword_copy(word, &gen))) {
00198 return err;
00199 }
00200
00201 if ((err = ffpriv_genitive_stem(&gen))) {
00202 ffword_delete(&gen);
00203 return err;
00204 }
00205
00206 if (ffstring_tail_equals_ci(&gen.data, 2, "de")) {
00207 ffword_swap_delete(&gen,word);
00208 return ffstring_rfe(&word->data, 2, "ksi");
00209 }
00210
00211 if (ffstring_tail_equals_ci(&gen.data, 3, "nne")) {
00212 ffword_swap_delete(&gen,word);
00213 return ffstring_rfe(&word->data, 2, "si");
00214 }
00215
00216
00217
00218 ffword_delete(&gen);
00219 }
00220 }
00221 }
00222
00223 if ((err = ffword_copy(word, &gen))) {
00224 return err;
00225 }
00226
00227 if ((err = ffpriv_genitive_stem(&gen))) {
00228 ffword_delete(&gen);
00229 return err;
00230 }
00231
00232
00233 ffword_swap_delete(&gen,word);
00234 if (ffstring_last_equals_ci(&word->data, 'i') && !ffstring_tail_equals_ci(&word->data, 2, "ii")) {
00235 word->metadata.loan = 1;
00236 return ffstring_rfe(&word->data, 1, "ei");
00237 } else {
00238 return ffstring_rfe(&word->data, 1, "i");
00239 }
00240
00241 }