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

ffpriv_consonant_gradation.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_consonant_gradation.c Implements the consonant gradation function
00027  * defined in ffpriv_consonant_gradation.h.
00028  */
00029 
00030 #include "ffstring.h"
00031 #include "ffregex.h"
00032 #include "ffpriv_consonant_gradation.h"
00033 
00034 
00035 ffint32 ffpriv_consonant_gradation(ffstring* word, ffuint32 direction, ffuint32 type) {
00036   ffint32 err;
00037   ffstring t;
00038 
00039   if (direction == 1 && type == 1) {
00040     if (ffregex_match_ci("^.*(kk|pp|tt)[aeiouyåäöÅÄÖ]$", word)) {
00041       err = ffstring_tail(word, 2, &t);
00042       if (err) {
00043         return err;
00044       }
00045       err = ffstring_rfe_ff(word, 3, &t);
00046       ffstring_delete(&t);
00047       return err;
00048     }
00049 
00050     if (ffregex_match_ci("^.*[nlr]t[aeiouyåäöÅÄÖ]$", word)) {
00051       return -!ffregex_replace_ci("(.)t(.)$", "${1}${1}${2}", word);
00052     }
00053 
00054     if (ffregex_match_ci("^.*[aeiouyåäöÅÄÖ]t[aeiouyåäöÅÄÖ]$", word)) {
00055       return -!ffregex_replace_ci("t(.)$", "d${1}", word);
00056     }
00057 
00058     if (ffregex_match_ci("^.*mp[aeiouyåäöÅÄÖ]$", word)) {
00059       return -!ffregex_replace_ci("p(.)$", "m${1}", word);
00060     }
00061 
00062     if (ffregex_match_ci("^.*[lr]p[aeiouyåäöÅÄÖ]$", word)) {
00063       return -!ffregex_replace_ci("p(.)$", "v${1}", word);
00064     }
00065 
00066     if (ffregex_match_ci("^.*[aeiouyåäöÅÄÖ]p[aeiouyåäöÅÄÖ]$", word)) {
00067       return -!ffregex_replace_ci("p(.)$", "v${1}", word);
00068     }
00069 
00070     if (ffregex_match_ci("^.*[lr]k[aeiouyåäöÅÄÖ]$", word)) {
00071       return -!ffregex_replace_ci("k(.)$", "${1}", word);
00072     }
00073 
00074     if (ffregex_match_ci("^.*nk[aeiouyåäöÅÄÖ]$", word)) {
00075       return -!ffregex_replace_ci("k(.)$", "g${1}", word);
00076     }
00077 
00078     if (ffregex_match_ci("^.*ht[aeiouyåäöÅÄÖ]$", word)) {
00079       return -!ffregex_replace_ci("t(.)$", "d${1}", word);
00080     }
00081 
00082     if (ffregex_match_ci("^.[uy]k[uy]$", word)) {
00083       return -!ffregex_replace_ci("k(.)$", "v${1}", word);
00084     }
00085 
00086     if (ffregex_match_ci("^([aeiouyåäöÅÄÖ]|[^aeiouyåäöÅÄÖ][aeiouyåäöÅÄÖ]+)k[aeiouyåäöÅÄÖ]$", word)) {
00087       return -!ffregex_replace_ci("k(.)$", "${1}", word);
00088     }
00089   } else if (direction == 2 && type == 1) {
00090     /* Append crap to the word so that replace wont fuck up our shit */
00091     if (ffregex_match_ci("^.*[io]e$", word)
00092         || ffregex_match_ci("(^[^aeiouyåäöÅÄÖ]u|^.*(iu))e$", word)
00093         || ffregex_match_ci("^.[aäÄ]e$", word)) {
00094       ffstring_append(word, "!");
00095       return -!ffregex_replace_ci("(e)!$", "k${1}", word);
00096     }
00097 
00098     if (ffstring_tail_equals_ci(word, 3, "lle")) {
00099       return ffstring_rfe(word, 2, "te");
00100     }
00101 
00102     /* [kpt]e */
00103     if (ffregex_match_ci("[^str]te$", word)) {
00104       return ffstring_rfe(word, 1, "te");
00105     }
00106 
00107     if (ffregex_match_ci("[^skt]ke$", word)) {
00108       return ffstring_rfe(word, 1, "ke");
00109     }
00110 
00111     if (ffregex_match_ci("[^spt]pe$", word)) {
00112       return ffstring_rfe(word, 1, "pe");
00113     }
00114 
00115   }
00116 
00117   return 0;
00118 }
00119 

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