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 
00038 ffint32 ffpriv_nominative_singular(ffword* word)
00039 {
00040   return 0;
00041 }
00042 
00043 ffint32 ffpriv_nominative_plural(ffword* word)
00044 {
00045   ffint32 err;
00046   if ( (err = ffpriv_genitive_stem(word)) )
00047   {
00048     return err;
00049   }
00050   else
00051   {
00052     return ffstring_append(&word->data,"t");
00053   }
00054 }
00055 
00056 ffint32 ffpriv_genitive_singular(ffword* word)
00057 {
00058   ffint32 err;
00059 
00060   if ( (err = ffpriv_genitive_stem(word)) )
00061   {
00062     return err;
00063   }
00064   else
00065   {
00066     return ffstring_append(&word->data,"n");
00067   }
00068 }
00069 
00070 ffint32 ffpriv_genitive_plural(ffword* word)
00071 {
00072   ffint32 err;
00073 
00074   /*
00075    * Non-loan words
00076    */
00077   if(!word->metadata.loan) {
00078     ffword orig;   
00079 
00080     /*
00081      * We will be operating on the parameter string, but need also the
00082      * original string - so copy it
00083      */
00084     if((err = ffword_copy(word, &orig)))
00085       return err;
00086 
00087     /*
00088      * Most genitive plurals are formed from the general plural stem
00089      */    
00090     else if((err = ffpriv_plural_stem(word))) {
00091       ffword_delete(&orig);
00092       return err;
00093     }
00094 
00095     /*
00096      * Words that end in a vowel:
00097      */
00098 
00099     /**
00100      * @todo
00101      *  set rel [relic_consonant $word gen]
00102      *  if { $rel != "" } {
00103      *          return ${case}den
00104      *  }
00105      */ 
00106     /*
00107      * Words that end in two vowels
00108      */
00109     else if(ffregex_match("^.*[bcdfghjklmnpqrstvwxz][aeiouyåäö]{2}$", &orig.data)) {
00110       if((err = ffword_delete(&orig)))
00111         return err;
00112       else
00113         return ffstring_append(&word->data, "den");
00114     }
00115     
00116     /**
00117      * @todo Check this regex
00118      */
00119     /*
00120      * Three or more syllable words ending in [vm][aä]
00121      */
00122     else if(ffregex_match("^.*[aeiouyåäö][bcdfghjklmnpqrstvwxz]{1,2}[aeiouyåäö]{1,2}[vm][aä]$", &orig.data)) {
00123       if((err = ffword_delete(&orig)))
00124         return err;
00125       else if((err = ffstring_dfe(&word->data, 1)))
00126         return err;
00127       else
00128         return ffstring_append(&word->data, "ien");
00129     }
00130     
00131     /*
00132      * Three or more syllable words ending in [aä]
00133      */
00134     else if(ffregex_match("^.*[aeiouyåäö][bcdfghjklmnpqrstvwxz]{1,3}[aeiouyåäö][bcdfghjklmnpqrstvwxz]{1,2}[aä]$", &orig.data)
00135        && (!ffstring_compare_tail(&word->data, 2, "ji"))) {
00136       ffword_delete(&orig);
00137       return ffstring_append(&word->data, "den");
00138     }
00139     
00140     /**
00141      * @todo Consider writing ffstring_tail_equals_many
00142      */
00143     /*
00144      * Words ending in [aeouyäö]
00145      */
00146     else if(ffregex_match("^.*[aeouyäö]$", &orig.data)) {
00147       if((err = ffword_delete(&orig)))
00148         return err;
00149       
00150       else if(ffpriv_is_vowel(word->data.str[word->data.len - 2])) {
00151         if((err = ffstring_dfe(&word->data, 1)))
00152           return err;
00153         else
00154           return ffstring_append(&word->data, "jen");
00155       }
00156       
00157       else
00158         return ffstring_append(&word->data, "en");
00159     }
00160     
00161     /*
00162      * Words ending in i
00163      */
00164     else if(ffstring_last_equals(&word->data, 'i')) {
00165       if((err = ffword_delete(&orig)))
00166         return err;
00167       else
00168         return ffstring_append(&word->data, "en");
00169     }
00170     
00171     /*
00172      * Words ending in [lnr]
00173      */
00174     else if(ffregex_match("^.*[lnr]$", &orig.data)) {
00175       if((err = ffword_delete(&orig)))
00176         return err;
00177       else
00178         return ffstring_append(&word->data, "en");
00179     }
00180     
00181     /*
00182      * Words ending in a consonant:
00183      */    
00184     
00185     /*
00186      * Words ending in s
00187      */
00188     else if(ffstring_last_equals(&orig.data, 's')) {
00189       /*
00190        * Note that we're operating on orig here - it's no longer the original word,
00191        * rather its partitive stem. I'm just too lazy to create a new variable for
00192        * it... :D
00193        */
00194       if((err = ffpriv_partitive_stem(&orig))) {
00195         ffword_delete(&orig);
00196         return err;
00197       }
00198       
00199       else if(ffstring_last_equals(&orig.data, 's')) {
00200         if(ffregex_match("^.*[bcdfghjklmnpqrstvwxz][aeiouyåäö]$", &word->data)) {
00201           if((err = ffword_delete(&orig)))
00202             return err;
00203           else
00204             return ffstring_append(&word->data, "en");
00205         }
00206         else if(ffregex_match("^.*[aeiouyåäö]{2}$", &word->data)) {
00207           if((err = ffword_delete(&orig)))
00208             return err;
00209           else
00210             return ffstring_append(&word->data, "den");
00211         }
00212       }
00213 
00214       if((err = ffword_delete(&orig)))
00215         return err;
00216       else
00217         return ffstring_append(&word->data, "en");
00218     }
00219     
00220     /*
00221      * Words ending in t
00222      */
00223     else if(ffstring_last_equals(&orig.data, 't')) {
00224       if((err = ffword_delete(&orig)))
00225         return err;
00226       else 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))
00227         return ffstring_append(&word->data, "den");
00228       else
00229         return ffstring_append(&word->data, "en");
00230     }
00231     
00232     /**
00233      * @todo Add "n" or "en" if nothing else fits?
00234      */
00235     /*
00236      * No rule found - fallback?
00237      */
00238     else {
00239       ffword_delete(&orig);
00240       return -3;
00241     }      
00242   }
00243   
00244   /*
00245    * Loan words
00246    */
00247   else {
00248     if((err = ffpriv_partitive_stem(word)))
00249       return err;
00250     else
00251       return ffstring_append(&word->data, "en");
00252   }
00253 }
00254 

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