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   /*@@v PLUb-03 **/
00041   ffword gen;
00042   ffint32 err;
00043 
00044   /**
00045    * @todo Relic consonant
00046    */
00047   if(!word->metadata.loan) {
00048     if (ffpriv_is_vowel(ffstring_last(&word->data))) {
00049 
00050       if ((err = ffword_copy(word, &gen))) {
00051         return err;
00052       }
00053 
00054       if ((err = ffpriv_genitive_stem(&gen))) {
00055         ffword_delete(&gen);
00056         return err;
00057       }
00058 
00059       /* Relic consonant */
00060       if (gen.metadata.relic) {
00061         ffword_swap_delete(&gen,word);
00062         return ffstring_rfe(&word->data, 1 , "i");
00063       }
00064 
00065       /* Numerals: (kolme) */
00066       if (ffstring_tail_equals_ci(&word->data, 5, "kolme")) {
00067           ffword_delete(&gen);
00068           return ffstring_rfe(&word->data, 1 , "i");
00069       }
00070 
00071       if (ffstring_last_equals_ci(&word->data, 'i')) {
00072         ffword ori;
00073         ffint32 result;
00074 
00075         if ((err = ffword_copy(word, &ori))) {
00076           ffword_delete(&gen);
00077           return err;
00078         }
00079 
00080         /* BUGFIX 2005-05-18
00081         * Added cg check
00082         */
00083         if (word->metadata.cg) {
00084           result = ffpriv_ie_partitive(word);
00085         } else {
00086           result = ffpriv_ie_genitive(word);
00087         }
00088 
00089         if (result > 0) {
00090           ffword_delete(&gen);
00091 
00092           if (ffstring_tail_equals_ci(&ori.data, 2, "si")) {
00093             ffword_swap_delete(&ori,word);
00094             return 0; /*@@v PLUb--01 **/
00095           }
00096 
00097           ffword_delete(&ori);
00098           if (ffstring_last(&word->data) == 'e') {
00099             return ffstring_rfe(&word->data, 1 , "i");
00100           } else {
00101             return ffstring_append(&word->data, "i");
00102           }
00103         }
00104 
00105         if (ffregex_match_ci("^.[aoeuyäö]i$", &word->data)) {
00106           return 0; /*@@v PLUb--03 **/
00107         }
00108 
00109         ffword_delete(&ori);
00110         ffword_swap_delete(&gen,word);
00111         return ffstring_rfe(&word->data, 1 , "ei"); /*@@v PLUb--04 **/
00112       }
00113 
00114       if (ffregex_match_ci("^.(ie|uo|yö)$", &word->data)) {
00115         ffword_delete(&gen);
00116         return -!ffregex_replace_ci("(.).(.)", "${1}${2}i", &word->data); /*@@v PLUb--05 **/
00117       }
00118 
00119       /* BUGFIX 2005-05-17
00120       * Allow more than three letters (yksi tavu)
00121       * Broke: Ehtoo
00122       */
00123       if (ffregex_match_ci("^.+(aa|ää|ee|ii|oo|öö|uu|yy)$", &word->data)) {
00124         ffword_swap_delete(&gen,word);
00125         return ffstring_rfe(&word->data, 1 , "i"); /*@@v PLUb--06 **/
00126       }
00127 
00128       if (ffstring_tail_equals_ci(&word->data, 3, "aja") || ffstring_tail_equals_ci(&word->data, 3, "äjä")) {
00129         ffword_swap_delete(&gen,word);
00130         return ffstring_rfe(&word->data, 1 , "i"); /*@@v PLUb--07 **/
00131       }
00132 
00133       /* BUGFIX 2005-05-18
00134       * Changed .V to K*?V+
00135       * Broke: siivilä, ähkinä, plörinä
00136       */
00137       if (ffstring_last_equals_ci(&word->data, 'ä')) {
00138         if (ffregex_match_ci("^[^aeiouyåäöÅÄÖ]*[aeiouyåäöÅÄÖ]+[^aeiouyåäöÅÄÖ]+[aeiouyåäöÅÄÖ]+[^aeiouyåäöÅÄÖ]ä$", &word->data)) {
00139           ffword_swap_delete(&gen,word);
00140           return ffstring_rfe(&word->data, 1 , "öi"); /*@@v PLUb--08 **/
00141         }
00142 
00143         ffword_swap_delete(&gen,word);
00144         return ffstring_rfe(&word->data, 1 , "i"); /*@@v PLUb--09 **/
00145 
00146       }
00147 
00148       if (ffstring_last_equals_ci(&word->data, 'a')) {
00149         if (ffstring_tail_equals_ci(&word->data, 2, "ea") || ffregex_match_ci("^[^aeiouyåäöÅÄÖ][ou][aeiouyåäöÅÄÖ]*[^aeiouyåäöÅÄÖ]+a$", &word->data)) {
00150           ffword_swap_delete(&gen,word);
00151           return ffstring_rfe(&word->data, 1 , "i"); /*@@v PLUb--10 **/
00152         }
00153 
00154         ffword_swap_delete(&gen,word);
00155         return ffstring_rfe(&word->data, 1 , "oi"); /*@@v PLUb--11 **/
00156 
00157       }
00158 
00159       ffword_swap_delete(&gen,word);
00160       return ffstring_append(&word->data, "i"); /*@@v PLUb--12 **/
00161 
00162     } else {
00163       /* Consonant */
00164       if (word->metadata.cg ) {
00165         ffword ess;
00166   
00167         if ((err = ffword_copy(word, &ess))) {
00168           return err;
00169         }
00170   
00171         if ((err = ffpriv_essive_stem(&ess))) {
00172           ffword_delete(&ess);
00173           return err;
00174         }
00175   
00176         if (ffstring_tail_equals(&ess.data, 3, "nte")) {
00177           ffword_swap_delete(&ess,word);
00178           return ffstring_rfe(&word->data, 2, "si"); /*@@v PLUb--13 **/
00179         }
00180   
00181         if (ffstring_tail_equals(&ess.data, 2, "te")) {
00182           ffword_swap_delete(&ess,word);
00183           return ffstring_rfe(&word->data, 2, "ksi"); /*@@v PLUb--14 **/
00184         }
00185   
00186         /* BUGFIX 2005-05-17
00187          * With other words the final letter should be replaced with i
00188          * Broke: oppinut -> oppinee -> oppineeita
00189          */
00190         /* BUGFIX 2005-05-22
00191          * Let fall down
00192          */
00193         ffword_delete(&ess);
00194 
00195       } else {
00196 
00197         if ((err = ffword_copy(word, &gen))) {
00198           return err;
00199         }
00200 
00201         if ((err = ffpriv_genitive_stem(&gen))) {
00202           ffword_delete(&gen);
00203           return err;
00204         }
00205 
00206         if (ffstring_tail_equals_ci(&gen.data, 2, "de")) {
00207           ffword_swap_delete(&gen,word);
00208           return ffstring_rfe(&word->data, 2, "ksi"); /*@@v PLUb--15 **/
00209         }
00210 
00211         if (ffstring_tail_equals_ci(&gen.data, 3, "nne")) {
00212           ffword_swap_delete(&gen,word);
00213           return ffstring_rfe(&word->data, 2, "si"); /*@@v PLUb--16 **/
00214         }
00215         /* BUGFIX 2005-05-22
00216          * Let fall down
00217          */
00218         ffword_delete(&gen);
00219       }
00220     }
00221   }
00222 
00223   if ((err = ffword_copy(word, &gen))) {
00224     return err;
00225   }
00226 
00227   if ((err = ffpriv_genitive_stem(&gen))) {
00228     ffword_delete(&gen);
00229     return err;
00230   }
00231 
00232   /* loan */
00233   ffword_swap_delete(&gen,word);
00234   if (ffstring_last_equals_ci(&word->data, 'i') && !ffstring_tail_equals_ci(&word->data, 2, "ii")) {
00235     word->metadata.loan = 1;
00236     return ffstring_rfe(&word->data, 1, "ei"); /*@@v PLUb--17 **/
00237   } else {
00238     return ffstring_rfe(&word->data, 1, "i"); /*@@v PLUb--18 **/
00239   }
00240 
00241 }

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