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

ffpriv_general_local_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_general_local_cases.c Implements functions for inflecting
00027  * words in general local cases. They are declared in ffpriv_general_local_cases.c.
00028  */
00029 
00030 #include "ffpriv_general_local_cases.h"
00031 #include "ffpriv_genitive_stem.h"
00032 #include "ffpriv_partitive_stem.h"
00033 #include "ffpriv_essive_stem.h"
00034 #include "ffpriv_plural_stem.h"
00035 #include "ffregex.h"
00036 #include "ffutil.h"
00037 #include "ffpriv_single_letter.h"
00038 
00039 ffint32 ffpriv_partitive_singular(ffword* word) {
00040   ffint32 err;
00041 
00042   if (word->data.len < 2) {
00043     return ffpriv_single_letter(word, FFCASE_PARTITIVE, FFCOUNT_SINGULAR);
00044   }
00045 
00046   if ((err = ffpriv_partitive_stem(word))) {
00047     return err;
00048   }
00049 
00050   /* TODO: Version 2+n, update to multiple return vales */
00051 
00052   if (ffstring_tail_equals_ci(&word->data, 2, "ea") || ffstring_tail_equals_ci(&word->data, 2, "eä")) {
00053     return ffstring_append(&word->data, ffpriv_vowel_harmony(&word->data, "a", "ä"));
00054   }
00055 
00056   if (ffpriv_is_consonant(ffstring_last(&word->data)) || ffregex_match_ci("^.*[aeiouyåäöÅÄÖ][aeiouyåäöÅÄÖ]$", &word->data)) {
00057     return ffstring_append(&word->data, ffpriv_vowel_harmony(&word->data, "ta", "tä"));
00058   } else {
00059     return ffstring_append(&word->data, ffpriv_vowel_harmony(&word->data, "a", "ä"));
00060   }
00061 }
00062 
00063 ffint32 ffpriv_partitive_plural(ffword* word) {
00064   ffint32 err;
00065   ffword stem;
00066 
00067   if (word->data.len < 2) {
00068     return ffpriv_single_letter(word, FFCASE_PARTITIVE, FFCOUNT_PLURAL);
00069   }
00070 
00071   if ((err = ffword_copy(word, &stem))) {
00072     return err;
00073   }
00074 
00075   stem.metadata.cg = 1;
00076 
00077   if ((err = ffpriv_plural_stem(&stem))) {
00078     ffword_delete(&stem);
00079     return err;
00080   }
00081 
00082   /*
00083     * If set in plural_stem function
00084     */
00085   if(stem.metadata.loan) {
00086     ffword_swap_delete(&stem,word);
00087     return ffstring_rfe(&word->data, 2, ffpriv_vowel_harmony(&word->data, "eja", "ejä"));
00088   }
00089 
00090   /* TODO RELIC CONSONANT aND LOAN || */
00091   if (ffregex_match_ci("^.*[aeiouyåäöÅÄÖ][aeiouyåäöÅÄÖ]$", &stem.data) && (
00092         ffregex_match_ci("^.*[aeiouyåäöÅÄÖ][^aeiouyåäöÅÄÖ]+[aeiouyåäöÅÄÖ][^aeiouyåäöÅÄÖ][aeiouyåäöÅÄÖ]$", &word->data) ||
00093         ffregex_match_ci("^.*[aeiouyåäöÅÄÖ][aeiouyåäöÅÄÖ]$", &word->data) ||
00094         ffpriv_is_consonant(ffstring_last(&word->data)))) {
00095     ffword_swap_delete(&stem,word);
00096     return ffstring_append(&word->data, ffpriv_vowel_harmony(&word->data, "ta", "tä"));
00097   } else {
00098     if (ffpriv_is_vowel( stem.data.str[stem.data.len - 2] )) {
00099       ffword_swap_delete(&stem,word);
00100       return ffstring_rfe(&word->data, 1, ffpriv_vowel_harmony(&word->data, "ja", "jä"));
00101     } else {
00102       ffword_swap_delete(&stem,word);
00103       return ffstring_append(&word->data, ffpriv_vowel_harmony(&word->data, "a", "ä"));
00104     }
00105   }
00106 }
00107 
00108 ffint32 ffpriv_essive_singular(ffword* word) {
00109   ffint32 err;
00110 
00111   if (word->data.len < 2) {
00112     return ffpriv_single_letter(word, FFCASE_ESSIVE, FFCOUNT_SINGULAR);
00113   }
00114 
00115   if ((err = ffpriv_essive_stem(word))) {
00116     return err;
00117   }
00118 
00119   return ffstring_append(&word->data, ffpriv_vowel_harmony(&word->data, "na", "nä"));
00120 }
00121 
00122 ffint32 ffpriv_essive_plural(ffword* word) {
00123   ffint32 err;
00124   word->metadata.cg = 1;
00125 
00126   if (word->data.len < 2) {
00127     return ffpriv_single_letter(word, FFCASE_ESSIVE, FFCOUNT_PLURAL);
00128   }
00129 
00130   if ((err = ffpriv_plural_stem(word))) {
00131     return err;
00132   }
00133 
00134   return ffstring_append(&word->data, ffpriv_vowel_harmony(&word->data, "na", "nä"));;
00135 }
00136 
00137 ffint32 ffpriv_translative_singular(ffword* word) {
00138   ffint32 err;
00139 
00140   if (word->data.len < 2) {
00141     return ffpriv_single_letter(word, FFCASE_TRANSLATIVE, FFCOUNT_SINGULAR);
00142   }
00143 
00144   if ((err = ffpriv_genitive_stem(word))) {
00145     return err;
00146   }
00147 
00148   return ffstring_append(&word->data,"ksi");
00149 }
00150 
00151 ffint32 ffpriv_translative_plural(ffword* word) {
00152   ffint32 err;
00153 
00154   if (word->data.len < 2) {
00155     return ffpriv_single_letter(word, FFCASE_TRANSLATIVE, FFCOUNT_PLURAL);
00156   }
00157 
00158   if ((err = ffpriv_plural_stem(word))) {
00159     return err;
00160   }
00161 
00162   return ffstring_append(&word->data,"ksi");
00163 }

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