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 
00037 /**
00038  * Forms the partitive stem of the given word
00039  * @param word The word to inflect
00040  * @return 0 on success, negative on error
00041  */
00042 ffint32 ffpriv_partitive_stem(ffword* word)
00043 {
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    * @todo relic consonant
00057    */
00058 
00059   /*
00060    * Non-loan words
00061    */
00062   if(!word->metadata.loan) {
00063 
00064     /*
00065      * INITIALIZATIONS
00066      */
00067     if((err = ffword_copy(word, &gen)))
00068       return err;
00069 
00070     /**
00071      * @todo Error constant
00072      */
00073     /*
00074      * Should be zero
00075      */
00076     if(gen.metadata.cg != 0)
00077       return -10;
00078 
00079     /*
00080      * Get the genitive stem for reference
00081      */
00082     if((err = ffpriv_genitive_stem(&gen)))
00083       return err;
00084 
00085     /*
00086      * CODE BEGINS
00087      */
00088 
00089     /*
00090      * Words whose genitive stem ends in two vowels, kse or he
00091      */
00092     if(ffregex_match_ci("^.*([aeiouyåäöÅÄÖ][aeiouyåäöÅÄÖ]|kse|he)$", &gen.data))
00093       return ffword_delete(&gen);
00094 
00095     /*
00096      * Words whose genitive stem ends in de or nne
00097      */
00098     else if(ffstring_tail_equals_ci(&gen.data, 2, "de") || ffstring_tail_equals_ci(&gen.data, 3, "nne")) {
00099       ffword_delete(&gen);
00100       return ffstring_rfe(&word->data, 1, "t"); /* BUGFIX 2005-05-13 */
00101     }
00102 
00103     /*
00104      * Words that end in nen
00105      */
00106     else if(ffstring_tail_equals_ci(&word->data, 3, "nen")) {
00107       if((err = ffword_delete(&gen)))
00108         return err;
00109       else
00110         return ffstring_rfe(&word->data, 3, "s");
00111     }
00112     
00113     /*
00114      * Words that end in n, [ae]l, [aä]r or [aäuy]t
00115      */
00116     else if(ffregex_match_ci("^.*(n|[ae]l|[aäÄ]r|[aäÄuy]t)$", &word->data))
00117       return ffword_delete(&gen);
00118 
00119     /*
00120      * Fall back
00121      */  
00122     else
00123       ffword_delete(&gen);
00124 
00125                 return 0;
00126 
00127   }
00128 
00129   /*
00130    * FALLBACK
00131    */
00132 
00133   if(ffstring_last_equals(&word->data, 'i'))
00134     return 0;
00135   else
00136     return ffstring_append(&word->data, "i");
00137 }

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