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

ffpriv_basic_cases.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_basic_cases.c Implements the basic case inflection functions
00027  * defined in ffpriv_basic_cases.h.
00028  */
00029 
00030 #include "ffpriv_basic_cases.h"
00031 #include "ffpriv_genitive_stem.h"
00032 #include "ffpriv_partitive_stem.h"
00033 #include "ffpriv_plural_stem.h"
00034 #include "ffpriv_ie_vowel_change.h"
00035 #include "ffutil.h"
00036 #include "ffregex.h"
00037 #include "ffcase.h"
00038 #include "ffpriv_single_letter.h"
00039 
00040 ffint32 ffpriv_nominative_singular(ffword* word) {
00041   return 0;
00042 }
00043 
00044 ffint32 ffpriv_nominative_plural(ffword* word) {
00045   ffint32 err;
00046 
00047   if (word->data.len < 2) {
00048     return ffpriv_single_letter(word, FFCASE_NOMINATIVE, FFCOUNT_PLURAL);
00049   }
00050 
00051   if ((err = ffpriv_genitive_stem(word))) {
00052     return err;
00053   }
00054 
00055   return ffstring_append(&word->data,"t");
00056 }
00057 
00058 ffint32 ffpriv_genitive_singular(ffword* word) {
00059   ffint32 err;
00060 
00061   if (word->data.len < 2) {
00062     return ffpriv_single_letter(word, FFCASE_GENITIVE, FFCOUNT_SINGULAR);
00063   }
00064 
00065   if ((err = ffpriv_genitive_stem(word))) {
00066     return err;
00067   }
00068 
00069   return ffstring_append(&word->data,"n");
00070 }
00071 
00072 ffint32 ffpriv_genitive_plural(ffword* word) {
00073   ffint32 err;
00074 
00075   if (word->data.len < 2) {
00076     return ffpriv_single_letter(word, FFCASE_GENITIVE, FFCOUNT_PLURAL);
00077   }
00078 
00079   /* BUGFIX 2005-05-18
00080    * Forgot to set the word to use strong grade
00081    * Broke: hätä -> hädien
00082    */
00083   /* Strong grade */
00084   word->metadata.cg = 1;
00085 
00086   if(!word->metadata.loan) {
00087     /*
00088      * Non-loan words
00089      */
00090 
00091     ffword orig;
00092 
00093     /*
00094      * We will be operating on the parameter string, but need also the
00095      * original string - so copy it
00096      */
00097     if((err = ffword_copy(word, &orig))) {
00098       return err;
00099     }
00100 
00101     /*
00102      * Most genitive plurals are formed from the general plural stem
00103      */
00104     if((err = ffpriv_plural_stem(word))) {
00105       ffword_delete(&orig);
00106       return 0;
00107     }
00108 
00109     /*
00110      * If set in plural_stem function
00111      */
00112     if(word->metadata.loan) {
00113       ffword_delete(&orig);
00114       return ffstring_rfe(&word->data, 2, "ien");
00115     }
00116 
00117     /*
00118      * Words that end in a vowel:
00119      */
00120     if (ffpriv_is_vowel( ffstring_last(&orig.data))) {
00121       /**
00122        * @todo RELIC consonant
00123        */
00124       /*
00125       * Words that end in two vowels
00126       */
00127       if(ffregex_match("^.*[bcdfghjklmnpqrstvwxz][aeiouyåäö]{2}$", &orig.data)) {
00128         ffword_delete(&orig);
00129         return ffstring_append(&word->data, "den");
00130       }
00131   
00132       /**
00133       * @todo Check this regex
00134       */
00135       /*
00136       * Three or more syllable words ending in [vm][aä]
00137       */
00138       if(ffregex_match("^.*[aeiouyåäö][bcdfghjklmnpqrstvwxz]{1,2}[aeiouyåäö]{1,2}[vm][aä]$", &orig.data)) {
00139         ffword_delete(&orig);
00140         return ffstring_rfe(&word->data, 1, "ien");
00141       }
00142   
00143       /*
00144       * Three or more syllable words ending in [aä]
00145       */
00146       /* BUGFIX 2005-05-18
00147       * Fixed the ji-clause
00148       * Broke: ??
00149       */
00150       if(ffregex_match("^.*[aeiouyåäö][bcdfghjklmnpqrstvwxz]{1,3}[aeiouyåäö][bcdfghjklmnpqrstvwxz]{1,2}[aä]$", &orig.data)
00151           && (!ffstring_tail_equals(&word->data, 2, "ji"))) {
00152         ffword_delete(&orig);
00153         return ffstring_append(&word->data, "den");
00154       }
00155   
00156       /**
00157       * @todo Consider writing ffstring_tail_equals_many
00158       */
00159       /*
00160       * Words ending in [aeouyäö]
00161       */
00162       if(ffregex_match("^.*[aeouyäö]$", &orig.data)) {
00163         ffword_delete(&orig);
00164   
00165         if(ffpriv_is_vowel(word->data.str[word->data.len - 2])) {
00166           /* BUGFIX 2005-05-18
00167           * Removed else
00168           * Broke: siivilä -> siivilöi -> siivilö
00169           */
00170           return ffstring_rfe(&word->data, 1, "jen");
00171         }
00172   
00173         return ffstring_append(&word->data, "en");
00174       }
00175   
00176       /*
00177       * Words ending in i
00178       */
00179   
00180       if(ffstring_tail_equals(&word->data, 2, "ei")) {
00181         ffword_delete(&orig);
00182         return ffstring_rfe(&word->data, 2, "ien");
00183       }
00184     }
00185 
00186     /* BUGFIX 2005-05-17
00187      * Use orig instead of word.
00188      */
00189     if(ffstring_last_equals(&orig.data, 'i')) {
00190       ffword_delete(&orig);
00191       return ffstring_append(&word->data, "en");
00192     }
00193 
00194     /*
00195      * Words ending in [lnr]
00196      */
00197     if(ffregex_match("^.*[lnr]$", &orig.data)) {
00198       ffword_delete(&orig);
00199       return ffstring_append(&word->data, "en");
00200     }
00201 
00202     /*
00203      * Words ending in a consonant:
00204      */
00205 
00206     /*
00207      * Words ending in s
00208      */
00209 
00210     if(ffstring_last_equals(&orig.data, 's')) {
00211       /* orig is now partitive_stem! */
00212       if((err = ffpriv_partitive_stem(&orig))) {
00213         ffword_delete(&orig);
00214         return err;
00215       }
00216 
00217       if(ffstring_last_equals(&orig.data, 's')) {
00218         ffword_delete(&orig);
00219 
00220         if(ffregex_match("^.*[bcdfghjklmnpqrstvwxz][aeiouyåäö]$", &word->data)) {
00221           return ffstring_append(&word->data, "en");
00222         } else if(ffregex_match("^.*[aeiouyåäö]{2}$", &word->data)) {
00223           return ffstring_append(&word->data, "den");
00224         }
00225       }
00226 
00227       ffword_delete(&orig);
00228       return ffstring_append(&word->data, "en");
00229     }
00230 
00231     /*
00232      * Words ending in t
00233      */
00234     if(ffstring_last_equals(&orig.data, 't')) {
00235       ffword_delete(&orig);
00236 
00237       if(ffregex_match("^.*(yi|öi|äi|ui|oi|ai|äy|au|yö|uo|ou|ie|ei|eu|iu|aa|ää|oo|öö|uu|yy|ee|ii)$", &word->data)) {
00238         return ffstring_append(&word->data, "den");
00239       } else {
00240         return ffstring_append(&word->data, "en");
00241       }
00242     }
00243 
00244     ffword_delete(&orig);
00245   }
00246   
00247 
00248   /*
00249    * Loan words and words not processed by above rules
00250    */
00251   if((err = ffpriv_partitive_stem(word))) {
00252     return err;
00253   } else {
00254     return ffstring_append(&word->data, "en");
00255   }
00256 
00257 }
00258 

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