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 {
00039   /*@@v GENb-01 **/
00040 
00041   /* Exceptions: ie, ss, TODO: n (below) */
00042 
00043   if(ffpriv_ie_genitive(word) > 0) {
00044     return 0; /*@@v GENb--01 **/
00045   }
00046 
00047 
00048   if(ffpriv_ss_genitive(word) > 0) {
00049     return 0; /*@@v GENb--02 **/
00050   }
00051 
00052 
00053   if ( ffpriv_is_vowel( ffstring_last(&word->data) ) ) {        
00054 
00055     if (word->metadata.cg) {
00056       if ( ffstring_tail_equals_ci(&word->data, 3, "mpi") ) {
00057         return ffstring_rfe(&word->data, 1, ffpriv_vowel_harmony(&word->data, "a", "ä")); /*@@v GENb--03 **/
00058       }
00059       return 0; /*@@v GENb--04 **/
00060     } else {
00061       if ( !ffstring_compare_tail_ci(&word->data, 3, "mpi") ) {
00062         return ffstring_rfe(&word->data, 2, ffpriv_vowel_harmony(&word->data, "ma", "mä")); /*@@v GENb--05 **/
00063       }
00064       return ffpriv_consonant_gradation(&word->data, 1, 1); /*@@v GENb--06 **/
00065     }
00066   }
00067 
00068 
00069   if ( ffstring_last_equals_ci(&word->data,'s') ) {
00070 
00071     if (ffstring_tail_equals_ci(&word->data, 3, "ias") ) {
00072       return ffstring_rfe(&word->data, 1, "a"); /*@@v GENb--07 **/
00073     }
00074 
00075     if (ffstring_tail_equals_ci(&word->data, 3, "iäs") ) {
00076       return ffstring_rfe(&word->data, 1, "ä"); /*@@v GENb--08 **/
00077     }
00078 
00079     if (ffstring_tail_equals_ci(&word->data, 3, "kas") ) {
00080       return ffstring_rfe(&word->data, 2, "kaa"); /*@@v GENb--09 **/
00081     }
00082 
00083     if (ffstring_tail_equals_ci(&word->data, 3, "käs") ) {
00084       return ffstring_rfe(&word->data, 2, "kää"); /*@@v GENb--10 **/
00085     }
00086 
00087     /* Try to catch adjectives */
00088 
00089     if (  ffregex_match("^.*[aeiouyåäö][bcdfghjklmnpqrstvwxz][bcdfghjklmnpqrstvwxz]?[bcdfghjklmnpqrstvwxz]?[aeiouyåäöÅÄÖ][uy]s$", &word->data)
00090         && !ffstring_tail_equals_ci(&word->data, 3, "aus")  ) {
00091       return ffstring_rfe(&word->data, 1, "de"); /*@@v GENb--11 **/
00092     }
00093 
00094     return ffstring_rfe(&word->data, 1, "kse"); /*@@v GENb--12 **/ /* BUGFIX 2005-05-13: (2->1) */
00095 
00096   }
00097 
00098 
00099   if ( ffstring_last_equals_ci(&word->data,'n') ) {
00100 
00101     /* TODO: check_irregular('n'); */
00102 
00103     if ( !ffstring_compare_ci(&word->data, "vasen") ) {
00104       if (word->metadata.cg) {
00105         return ffstring_rfe(&word->data, 1, "mpa"); /*@@v GENb--14 **/
00106       } else {
00107         return ffstring_rfe(&word->data, 1, "mma"); /*@@v GENb--15 **/
00108       }
00109     }
00110 
00111     if (ffstring_tail_equals_ci(&word->data, 3, "nen") ) {
00112       return ffstring_rfe(&word->data, 3, "se"); /*@@v GENb--16 **/
00113     }
00114 
00115     if (ffstring_tail_equals_ci(&word->data, 3, "ton") ) {
00116       return ffstring_rfe(&word->data, 2, "toma"); /*@@v GENb--17 **/
00117     }
00118 
00119     if ( ffstring_tail_equals_ci(&word->data, 3, "tön") ) {
00120       return ffstring_rfe(&word->data, 2, "tömä"); /*@@v GENb--18 **/
00121     }
00122 
00123     /* -en */
00124 
00125     /* lämmin, kytkin, puhelin */
00126     if ( ffstring_tail_equals_ci(&word->data, 2, "in") ) {
00127       if ( !ffregex_match("^.*(ä|ka|va|lj|t|is)in$", &word->data) ) {
00128         if (word->metadata.cg) {
00129           /* TODO: vokaalisointu */
00130           return ffstring_rfe(&word->data, 1, ffpriv_vowel_harmony(&word->data, "mpa", "mpä")); /*@@v GENb--19 **/
00131         } else {
00132           return ffstring_rfe(&word->data, 1, ffpriv_vowel_harmony(&word->data, "mma", "mmä")); /*@@v GENb--20 **/
00133         }
00134       }
00135     }
00136 
00137     /* TODO: astevaihtelu */
00138     return ffstring_rfe(&word->data, 1, "me"); /*@@v GENb--21 **/
00139   }
00140 
00141 
00142   if ( ffstring_last_equals_ci(&word->data,'l') || ffstring_last_equals_ci(&word->data,'r') ) {
00143     /* TODO: vahva astevaihtelu */
00144     return ffstring_append(&word->data,"e"); /*@@v GENb--22 **/
00145   }
00146 
00147 
00148   if ( ffstring_last_equals_ci(&word->data,'t') ) {
00149 
00150     if ( ffstring_tail_equals_ci(&word->data, 2, "ät") ) {
00151       return ffstring_rfe(&word->data, 1, "ä"); /*@@v GENb--23 **/
00152     }
00153 
00154     /* TODO: numeraalit */
00155 
00156     if ( !ffregex_match("^.*(((rr|ll|n)(u|t)t)|[^t]s(u|y))t$", &word->data) ) {
00157       return ffstring_rfe(&word->data, 2, "ee"); /*@@v GENb--24 **/
00158     }
00159 
00160     if ( ffstring_tail_equals_ci(&word->data, 2, "ut") || ffstring_tail_equals_ci(&word->data, 2, "yt") ) {
00161       return ffstring_rfe(&word->data, 2, "e"); /*@@v GENb--25 **/
00162     }
00163   }
00164 
00165   /* FALL TROUGH */
00166 
00167   return ffstring_append(&word->data,"i"); /*@@v GENb--26 **/
00168 
00169 }
00170 

Generated on Sun May 15 21:50:47 2005 for FinFlect by  doxygen 1.4.1