Main Page | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

ffpriv_genitive_stem.c

Go to the documentation of this file.
00001 /*
00002  * finflect - Algorithms and tools for inflecting Finnish nouns
00003  * Copyright (C) 2004, 2005  The FinFlect Team
00004  * 
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2.1 of the License, or (at your option) any later version.
00009  * 
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  * 
00019  * 
00020  * For the complete legal text of the GNU Lesser General Public License,
00021  * see the file LICENSE. For a complete list of authors and copyright
00022  * holders, see the file AUTHORS.
00023  */
00024 
00025 /**
00026  * @file ffpriv_genitive_stem.c Implements the genitive stem function
00027  * declared in ffpriv_genitive_stem.h.
00028  */
00029 
00030 #include "ffpriv_genitive_stem.h"
00031 #include "ffutil.h"
00032 #include "ffregex.h"
00033 #include "ffpriv_consonant_gradation.h"
00034 #include "ffpriv_ie_vowel_change.h"
00035 #include "ffpriv_ss_abnormal.h"
00036 
00037 ffint32 ffpriv_genitive_stem(ffword* word) {
00038   /*@@v GENb-03 **/
00039 
00040   ffint32 err;
00041 
00042   if(ffpriv_ie_genitive(word) > 0) {
00043     return 0; /*@@v GENb--01 **/
00044   }
00045 
00046 
00047   if(ffpriv_ss_genitive(word) > 0) {
00048     return 0; /*@@v GENb--02 **/
00049   }
00050 
00051 
00052   if (ffpriv_is_vowel( ffstring_last(&word->data))) {
00053     if (ffstring_last_equals_ci(&word->data,'e')) {
00054       /* TODO: *ope, ale */
00055       if (!ffstring_tail_equals_ci(&word->data, 2, "ee")
00056       &&  !ffstring_tail_equals_ci(&word->data, 3, "ope")
00057       &&  !ffstring_tail_equals_ci(&word->data, 5, "kolme") /* Numeral kolme */
00058       && (!ffstring_tail_equals_ci(&word->data, 3, "lle") || ffregex_match("([^nk]a|ii|[^p]e|uo)lle$", &word->data))) {
00059 
00060         if ((err = ffpriv_consonant_gradation(&word->data, 2, 1))) {
00061           return err;
00062         }
00063 
00064         word->metadata.relic = 1;
00065         return ffstring_append(&word->data,"e");
00066       }
00067     }
00068 
00069     if (word->metadata.cg) {
00070       if (ffstring_tail_equals_ci(&word->data, 3, "mpi")) {
00071         return ffstring_rfe(&word->data, 1, ffpriv_vowel_harmony(&word->data, "a", "ä")); /*@@v GENb--03 **/
00072       }
00073       return 0; /*@@v GENb--04 **/
00074     } else {
00075       if (!ffstring_compare_tail_ci(&word->data, 3, "mpi")) {
00076         return ffstring_rfe(&word->data, 2, ffpriv_vowel_harmony(&word->data, "ma", "mä")); /*@@v GENb--05 **/
00077       }
00078       return ffpriv_consonant_gradation(&word->data, 1, 1); /*@@v GENb--06 **/
00079     }
00080   }
00081 
00082 
00083   if (ffstring_last_equals_ci(&word->data,'s')) {
00084     if (ffstring_tail_equals_ci(&word->data, 3, "ias")) {
00085       return ffstring_rfe(&word->data, 1, "a"); /*@@v GENb--07 **/
00086     }
00087 
00088     if (ffstring_tail_equals_ci(&word->data, 3, "iäs")) {
00089       return ffstring_rfe(&word->data, 1, "ä"); /*@@v GENb--08 **/
00090     }
00091 
00092     if (ffstring_tail_equals_ci(&word->data, 3, "kas")) {
00093       return ffstring_rfe(&word->data, 2, "kaa"); /*@@v GENb--09 **/
00094     }
00095 
00096     if (ffstring_tail_equals_ci(&word->data, 3, "käs")) {
00097       return ffstring_rfe(&word->data, 2, "kää"); /*@@v GENb--10 **/
00098     }
00099 
00100     /* Try to catch adjectives */
00101 
00102     if (ffregex_match("^.*[aeiouyåäö][bcdfghjklmnpqrstvwxz][bcdfghjklmnpqrstvwxz]?[bcdfghjklmnpqrstvwxz]?[aeiouyåäöÅÄÖ][uy]s$", &word->data)
00103          && !ffstring_tail_equals_ci(&word->data, 3, "aus")  ) {
00104       return ffstring_rfe(&word->data, 1, "de"); /*@@v GENb--11 **/
00105     }
00106 
00107     return ffstring_rfe(&word->data, 1, "kse"); /*@@v GENb--12 **/ /* BUGFIX 2005-05-13: (2->1) */
00108 
00109   }
00110 
00111 
00112   if (ffstring_last_equals_ci(&word->data,'n')) {
00113     /* TODO: check_irregular('n'); */
00114 
00115     if (!ffstring_compare_ci(&word->data, "vasen")) {
00116       if (word->metadata.cg) {
00117         return ffstring_rfe(&word->data, 1, "mpa"); /*@@v GENb--14 **/
00118       } else {
00119         return ffstring_rfe(&word->data, 1, "mma"); /*@@v GENb--15 **/
00120       }
00121     }
00122 
00123     if (ffstring_tail_equals_ci(&word->data, 3, "nen")) {
00124       return ffstring_rfe(&word->data, 3, "se"); /*@@v GENb--16 **/
00125     }
00126 
00127     if (ffstring_tail_equals_ci(&word->data, 4, "ston")) {
00128       /* alaston */
00129       return ffstring_rfe(&word->data, 1, "ma"); /*@@v GENb--17 **/
00130     }
00131     if (ffstring_tail_equals_ci(&word->data, 3, "ton")) {
00132       return ffstring_rfe(&word->data, 2, "toma"); /*@@v GENb--18 **/
00133     }
00134 
00135     if (ffstring_tail_equals_ci(&word->data, 4, "stön")) {
00136       /* none, would be ylöstön */
00137       return ffstring_rfe(&word->data, 1, "mä"); /*@@v GENb--19 **/
00138     }
00139     if (ffstring_tail_equals_ci(&word->data, 3, "tön")) {
00140       return ffstring_rfe(&word->data, 2, "tömä"); /*@@v GENb--20 **/
00141     }
00142 
00143     /* -en */
00144 
00145     /* lämmin, kytkin, puhelin */
00146     if (ffstring_tail_equals_ci(&word->data, 2, "in")) {
00147       if (!ffregex_match("^.*(ä|ka|va|lj|t|is|nn)in$", &word->data)) {
00148         if (word->metadata.cg) {
00149           /* TODO: vokaalisointu */
00150           return ffstring_rfe(&word->data, 1, ffpriv_vowel_harmony(&word->data, "mpa", "mpä")); /*@@v GENb--21 **/
00151         } else {
00152           return ffstring_rfe(&word->data, 1, ffpriv_vowel_harmony(&word->data, "mma", "mmä")); /*@@v GENb--22 **/
00153         }
00154       }
00155     }
00156 
00157     /* TODO: astevaihtelu */
00158     return ffstring_rfe(&word->data, 1, "me"); /*@@v GENb--23 **/
00159   }
00160 
00161 
00162   if (ffstring_last_equals_ci(&word->data,'l') || ffstring_last_equals_ci(&word->data,'r')) {
00163     if ((err = ffpriv_consonant_gradation(&word->data, 2, 1))) {
00164       return err;
00165     }
00166     return ffstring_append(&word->data,"e"); /*@@v GENb--24 **/
00167   }
00168 
00169 
00170   if (ffstring_last_equals_ci(&word->data,'t')) {
00171     if (ffstring_tail_equals_ci(&word->data, 2, "ät")) {
00172       return ffstring_rfe(&word->data, 1, "ä"); /*@@v GENb--25 **/
00173     }
00174 
00175     /* TODO: numeraalit */
00176 
00177     /* NOTE 2005-05-17
00178      * This now handles correctly everything expect plural form words
00179      */
00180     if (ffstring_tail_equals_ci(&word->data, 2, "ut") || ffstring_tail_equals_ci(&word->data, 2, "yt")) {
00181       /* BUGFIX 2005-05-17
00182        * Fixed the funny regexp which was totally funnied up
00183        * Matched more than it should and not even all what of it should had matches
00184        */
00185       if (ffregex_match("^.*(((rr|ll|n)(u|y))|[^t]s(u|y))t$", &word->data)) {
00186         return ffstring_rfe(&word->data, 2, "ee"); /*@@v GENb--26 **/
00187       }
00188 
00189       /* BUGFIX 2005-05-17
00190        * Replace only one last letter instead of two
00191        * Broke: ehyt -> ehe -> eheen (all Ut which were not participles)
00192        */
00193       return ffstring_rfe(&word->data, 1, "e"); /*@@v GENb--27 **/
00194     }
00195   }
00196 
00197   /* FALL TROUGH */
00198   word->metadata.loan = 1;
00199   return ffstring_append(&word->data,"i"); /*@@v GENb--28 **/
00200 
00201 }
00202 

Generated on Thu Jun 2 23:16:59 2005 for FinFlect by  doxygen 1.4.2