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

ffpriv_plural_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_plural_stem.c Implements the plural stem function declared
00027  * in ffpriv_plural_stem.h.
00028  */ 
00029 
00030 #include "ffpriv_plural_stem.h"
00031 #include "ffpriv_genitive_stem.h"
00032 #include "ffpriv_essive_stem.h"
00033 #include "ffutil.h"
00034 #include "ffstring.h"
00035 #include "ffword.h"
00036 #include "ffregex.h"
00037 #include "ffpriv_ie_vowel_change.h"
00038 
00039 ffint32 ffpriv_plural_stem(ffword* word) {
00040 /*  ffint32 err; // UNUSED */
00041   ffword gen;
00042   ffword ess;
00043   ffstring ori;
00044 
00045   ffstring_copy(&word->data, &gen.data);
00046   
00047   
00048   gen.metadata = word->metadata;
00049   
00050   ffpriv_genitive_stem(&gen);
00051         
00052   /**
00053    * @todo Relic consonant
00054    */
00055   
00056   if ( ffpriv_is_vowel(ffstring_last(&word->data)) ) {
00057     if ( ffstring_last_equals_ci(&word->data, 'i') ) {
00058       ffstring_copy(&word->data, &ori);
00059       if (ffpriv_ie_genitive(word) > 0) {
00060         if ( ffstring_tail_equals_ci(&ori, 2, "si") ) {
00061           ffstring_delete(&gen.data);
00062           ffstring_delete(&word->data);
00063           word->data = ori;
00064           return 0;
00065         }
00066         
00067         ffstring_delete(&gen.data);
00068         ffstring_delete(&ori);
00069         ffstring_rfe(&word->data, 1 , "i");
00070         return 0;
00071         
00072         
00073       }
00074       /**
00075        * @todo täi, hai?
00076        */
00077       
00078     
00079       ffstring_delete(&ori);
00080       ffstring_delete(&word->data);
00081       ffstring_rfe(&gen.data, 1 , "ei");
00082       word->data = gen.data;
00083       
00084       return 0;
00085       
00086     }
00087     
00088     if ( ffregex_match_ci("^.(ie|uo|yö)$", &word->data) ) {
00089       ffregex_replace_ci("(.).(.)", "${1}${2}i", &word->data);
00090       ffstring_delete(&gen.data);
00091       return 0;
00092     }
00093     
00094     if ( ffregex_match_ci("^.(aa|ää|ee|ii|oo|öö|uu|yy)$", &word->data) ) {
00095       ffstring_delete(&word->data);
00096       ffstring_rfe(&gen.data, 1 , "i");
00097       word->data = gen.data;
00098       return 0;
00099     }
00100     
00101     if ( ffregex_match_ci("^.[aoeuyäö]i$", &word->data) ) {
00102       ffstring_delete(&gen.data);
00103       return 0;
00104     }
00105     
00106     if ( ffstring_tail_equals_ci(&word->data, 2, "aja") || ffstring_tail_equals_ci(&word->data, 2, "äjä") ) {
00107       ffstring_delete(&word->data);
00108       ffstring_rfe(&gen.data, 1 , "i");
00109       word->data = gen.data;
00110       return 0;
00111     }
00112     
00113   
00114   
00115     if ( ffstring_last_equals_ci(&word->data, 'ä') ) {
00116       if ( ffregex_match_ci("^.[aeiouyåäöÅÄÖ][^aeiouyåäöÅÄÖ]+[aeiouyåäöÅÄÖ]+[^aeiouyåäöÅÄÖ]ä$", &word->data) ) {
00117         ffstring_delete(&word->data);
00118         ffstring_rfe(&gen.data, 1 , "öi");
00119         word->data = gen.data;
00120         return 0;
00121       }
00122       
00123       ffstring_delete(&word->data);
00124       ffstring_rfe(&gen.data, 1 , "i");
00125       word->data = gen.data;
00126       return 0;
00127       
00128     }
00129     
00130     if ( ffstring_last_equals_ci(&word->data, 'a') ) {
00131       if ( ffregex_match_ci("^[^aeiouyåäöÅÄÖ][ou][aeiouyåäöÅÄÖ]*[^aeiouyåäöÅÄÖ]+a$", &word->data) ) {
00132         ffstring_delete(&word->data);
00133         ffstring_rfe(&gen.data, 1 , "i");
00134         word->data = gen.data;
00135         return 0;
00136       }
00137       
00138       ffstring_delete(&word->data);
00139       ffstring_rfe(&gen.data, 1 , "oi");
00140       word->data = gen.data;
00141       return 0;
00142       
00143       
00144     }
00145     
00146     ffstring_delete(&word->data);
00147     ffstring_append(&gen.data, "i");
00148     word->data = gen.data;
00149     return 0;
00150     
00151   } else {
00152     /* Consonant */
00153     if ( word->metadata.cg ) {
00154       
00155       ffstring_copy(&word->data, &ess.data);
00156       ess.metadata = word->metadata;
00157       ffpriv_essive_stem(&ess);
00158       
00159       if ( ffstring_tail_equals(&ess.data, 3, "nte") ) {
00160         ffstring_delete(&gen.data);
00161         ffstring_delete(&word->data);
00162         ffstring_rfe(&ess.data, 2, "si");
00163         word->data = ess.data;
00164         return 0;
00165       }
00166       
00167       if ( ffstring_tail_equals(&ess.data, 2, "te") ) {
00168         ffstring_delete(&gen.data);
00169         ffstring_delete(&word->data);
00170         ffstring_rfe(&ess.data, 2, "ksi");
00171         word->data = ess.data;
00172         return 0;
00173       }
00174       
00175       ffstring_delete(&ess.data);
00176       
00177     } else {
00178       
00179       if ( ffstring_tail_equals(&gen.data, 2, "de") ) {
00180         ffstring_delete(&word->data);
00181         ffstring_rfe(&gen.data, 2, "ksi");
00182         word->data = gen.data;
00183         return 0;
00184       }
00185       
00186       if ( ffstring_tail_equals(&gen.data, 3, "nne") ) {
00187         ffstring_delete(&word->data);
00188         ffstring_rfe(&gen.data, 2, "si");
00189         word->data = gen.data;
00190         return 0;
00191       }
00192     
00193       ffstring_delete(&word->data);
00194       ffstring_rfe(&gen.data, 1, "i");
00195       word->data = gen.data;
00196       return 0;
00197     }
00198     
00199   }
00200   
00201   /* loan */
00202   ffstring_rfe(&gen.data, 1, "ei");
00203   return ffword_swap_delete(&gen,word);
00204 
00205 }

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