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

ffpriv_partitive_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_partitive_stem.c Implements the partitive stem function
00027  * declared in ffpriv_partitive_stem.h.
00028  */
00029 
00030 #include "ffpriv_partitive_stem.h"
00031 #include "ffpriv_genitive_stem.h"
00032 #include "ffutil.h"
00033 #include "ffstring.h"
00034 #include "ffregex.h"
00035 #include "ffpriv_ie_vowel_change.h"
00036 #include "ffconfig.h"
00037 
00038 /**
00039  * Forms the partitive stem of the given word
00040  * @param word The word to inflect
00041  * @return 0 on success, negative on error
00042  */
00043 ffint32 ffpriv_partitive_stem(ffword* word) {
00044   ffint32 err;
00045   ffword gen;
00046 
00047   /*
00048    * i-e exceptions
00049    */
00050   if((err = ffpriv_ie_partitive(word)) > 0) {
00051     return 0;
00052   } else if (err < 0) {
00053     return err;
00054   }
00055 
00056   /**
00057    * @todo relic consonant
00058    */
00059 
00060   /*
00061    * Non-loan words
00062    */
00063   if(!word->metadata.loan) {
00064     /*
00065      * INITIALIZATIONS
00066      */
00067     if((err = ffword_copy(word, &gen))) {
00068       return err;
00069     }
00070 
00071     /*
00072      * Should be zero.
00073      * Other functions might have changed the value.
00074      */
00075     gen.metadata.cg = 0;
00076 
00077     /*
00078      * Get the genitive stem for reference
00079      */
00080     if((err = ffpriv_genitive_stem(&gen))) {
00081       ffword_delete(&gen);
00082       return err;
00083     }
00084 
00085     /*
00086      * CODE BEGINS
00087      */
00088     /*
00089      * Words whose genitive stem ends in two vowels, kse or he
00090      */
00091     if(ffregex_match_ci("^.*([aeiouyåäöÅÄÖ][aeiouyåäöÅÄÖ]|kse|he)$", &gen.data)) {
00092       ffword_delete(&gen);
00093       return 0;
00094     }
00095 
00096     /*
00097      * Words whose genitive stem ends in de or nne
00098      */
00099     if(ffstring_tail_equals_ci(&gen.data, 2, "de") || ffstring_tail_equals_ci(&gen.data, 3, "nne")) {
00100       ffword_delete(&gen);
00101       return ffstring_rfe(&word->data, 1, "t"); /* BUGFIX 2005-05-13 */
00102     }
00103 
00104     /*
00105      * Words that end in nen
00106      */
00107     if(ffstring_tail_equals_ci(&word->data, 3, "nen")) {
00108       ffword_delete(&gen);
00109       return ffstring_rfe(&word->data, 3, "s");
00110     }
00111 
00112     /*
00113      * Words that end in n, [ae]l, [aä]r or [aäuy]t
00114      */
00115     if(ffregex_match_ci("^.*(n|[ae]l|[aäÄ]r|[aäÄuy]t)$", &word->data)) {
00116       ffword_delete(&gen);
00117       return 0;
00118     }
00119 
00120     if (ffpriv_is_vowel(ffstring_last(&word->data))) {
00121       ffword_delete(&gen);
00122       return 0;
00123     }
00124 
00125     /*
00126      * If word ends in consonant it's likely to be loan word
00127      */
00128 
00129   }
00130 
00131   /*
00132    * Fall trough
00133    */
00134 
00135   word->metadata.loan = 1;
00136   if(ffstring_last_equals(&word->data, 'i')) {
00137     return 0;
00138   } else {
00139     return ffstring_append(&word->data, "i");
00140   }
00141 }

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