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

finflect.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 finflect.c Implementations for the public API functions defined in finflect.h.
00027  */
00028 
00029 #include <stdlib.h>
00030 #include <string.h>
00031 #include <strings.h>
00032 
00033 #include "finflect.h"
00034 #include "ffpriv_basic_cases.h"
00035 #include "ffpriv_general_local_cases.h"
00036 #include "ffpriv_exterior_local_cases.h"
00037 #include "ffpriv_interior_local_cases.h"
00038 #include "ffpriv_means_cases.h"
00039 
00040 ffchar* ff_inflect(const ffchar* word, ffcase thecase, ffint32 count) {
00041   switch(thecase) {
00042   case FFCASE_NOMINATIVE:
00043     if(count == 1)
00044       return ff_nominative_singular(word);
00045     else
00046       return ff_nominative_plural(word);
00047     break;
00048   case FFCASE_GENITIVE:
00049     if(count == 1)
00050       return ff_genitive_singular(word);
00051     else
00052       return ff_genitive_plural(word);
00053     break;
00054   case FFCASE_PARTITIVE:
00055     if(count == 1)
00056       return ff_partitive_singular(word);
00057     else
00058       return ff_partitive_plural(word);
00059     break;
00060   case FFCASE_ESSIVE:
00061     if(count == 1)
00062       return ff_essive_singular(word);
00063     else
00064       return ff_essive_plural(word);
00065     break;
00066   case FFCASE_TRANSLATIVE:
00067     if(count == 1)
00068       return ff_translative_singular(word);
00069     else
00070       return ff_translative_plural(word);
00071     break;
00072   case FFCASE_INESSIVE:
00073     if(count == 1)
00074       return ff_inessive_singular(word);
00075     else
00076       return ff_inessive_plural(word);
00077     break;
00078   case FFCASE_ELATIVE:
00079     if(count == 1)
00080       return ff_elative_singular(word);
00081     else
00082       return ff_elative_plural(word);
00083     break;
00084   case FFCASE_ILLATIVE:
00085     if(count == 1)
00086       return ff_illative_singular(word);
00087     else
00088       return ff_illative_plural(word);
00089     break;
00090   case FFCASE_ADESSIVE:
00091     if(count == 1)
00092       return ff_adessive_singular(word);
00093     else
00094       return ff_adessive_plural(word);
00095     break;
00096   case FFCASE_ABLATIVE:
00097     if(count == 1)
00098       return ff_ablative_singular(word);
00099     else
00100       return ff_ablative_plural(word);
00101     break;
00102   case FFCASE_ALLATIVE:
00103     if(count == 1)
00104       return ff_allative_singular(word);
00105     else
00106       return ff_allative_plural(word);
00107     break;
00108   case FFCASE_ABESSIVE:
00109     if(count == 1)
00110       return ff_abessive_singular(word);
00111     else
00112       return ff_abessive_plural(word);
00113     break;
00114   case FFCASE_INSTRUCTIVE:
00115     if(count == 1)
00116       return ff_instructive_singular(word);
00117     else
00118       return ff_instructive_plural(word);
00119     break;
00120   case FFCASE_COMITATIVE:
00121     if(count == 1)
00122       /** @todo curse user? */
00123       return (ffchar*)(strdup("-"));
00124     else
00125       return ff_comitative_plural(word);
00126     break;
00127   default:
00128     return NULL;
00129     break;
00130   }
00131 }
00132 
00133 ffchar* ff_nominative_singular(const ffchar* word) {
00134   return (ffchar*)strdup(word);
00135 }
00136 
00137 ffchar* ff_nominative_plural(const ffchar* word) {
00138   ffword theword;
00139 
00140   if (ffword_create(word, &theword)) {
00141     return NULL;
00142   }
00143 
00144   if (ffpriv_nominative_plural(&theword)) {
00145     ffword_delete(&theword);
00146     return NULL;
00147   }
00148 
00149   ffword_finalize(&theword);
00150   return theword.data.str;
00151 }
00152 
00153 ffchar* ff_genitive_singular(const ffchar* word) {
00154   ffword theword;
00155 
00156   if (ffword_create(word, &theword)) {
00157     return NULL;
00158   }
00159 
00160   if (ffpriv_genitive_singular(&theword)) {
00161     ffword_delete(&theword);
00162     return NULL;
00163   }
00164 
00165   ffword_finalize(&theword);
00166   return theword.data.str;
00167 }
00168 
00169 ffchar* ff_genitive_plural(const ffchar* word) {
00170   ffword theword;
00171 
00172   if (ffword_create(word, &theword)) {
00173     return NULL;
00174   }
00175 
00176   if (ffpriv_genitive_plural(&theword)) {
00177     ffword_delete(&theword);
00178     return NULL;
00179   }
00180 
00181   ffword_finalize(&theword);
00182   return theword.data.str;
00183 }
00184 
00185 ffchar* ff_essive_singular(const ffchar* word) {
00186   ffword theword;
00187 
00188   if (ffword_create(word, &theword)) {
00189     return NULL;
00190   }
00191 
00192   if (ffpriv_essive_singular(&theword)) {
00193     ffword_delete(&theword);
00194     return NULL;
00195   }
00196 
00197   ffword_finalize(&theword);
00198   return theword.data.str;
00199 }
00200 
00201 ffchar* ff_essive_plural(const ffchar* word) {
00202   ffword theword;
00203 
00204   if (ffword_create(word, &theword)) {
00205     return NULL;
00206   }
00207 
00208   if (ffpriv_essive_plural(&theword)) {
00209     ffword_delete(&theword);
00210     return NULL;
00211   }
00212 
00213   ffword_finalize(&theword);
00214   return theword.data.str;
00215 }
00216 
00217 ffchar* ff_partitive_singular(const ffchar* word) {
00218   ffword theword;
00219 
00220   if (ffword_create(word, &theword)) {
00221     return NULL;
00222   }
00223 
00224   if (ffpriv_partitive_singular(&theword)) {
00225     ffword_delete(&theword);
00226     return NULL;
00227   }
00228 
00229   ffword_finalize(&theword);
00230   return theword.data.str;
00231 }
00232 
00233 ffchar* ff_partitive_plural(const ffchar* word) {
00234   ffword theword;
00235 
00236   if (ffword_create(word, &theword)) {
00237     return NULL;
00238   }
00239 
00240   if (ffpriv_partitive_plural(&theword)) {
00241     ffword_delete(&theword);
00242     return NULL;
00243   }
00244 
00245   ffword_finalize(&theword);
00246   return theword.data.str;
00247 }
00248 
00249 ffchar* ff_translative_singular(const ffchar* word) {
00250   ffword theword;
00251 
00252   if (ffword_create(word, &theword)) {
00253     return NULL;
00254   }
00255 
00256   if (ffpriv_translative_singular(&theword)) {
00257     ffword_delete(&theword);
00258     return NULL;
00259   }
00260 
00261   ffword_finalize(&theword);
00262   return theword.data.str;
00263 }
00264 
00265 ffchar* ff_translative_plural(const ffchar* word) {
00266   ffword theword;
00267 
00268   if (ffword_create(word, &theword)) {
00269     return NULL;
00270   }
00271 
00272   if (ffpriv_translative_plural(&theword)) {
00273     ffword_delete(&theword);
00274     return NULL;
00275   }
00276 
00277   ffword_finalize(&theword);
00278   return theword.data.str;
00279 }
00280 
00281 ffchar* ff_inessive_singular(const ffchar* word) {
00282   ffword theword;
00283 
00284   if (ffword_create(word, &theword)) {
00285     return NULL;
00286   }
00287 
00288   if (ffpriv_inessive_singular(&theword)) {
00289     ffword_delete(&theword);
00290     return NULL;
00291   }
00292 
00293   ffword_finalize(&theword);
00294   return theword.data.str;
00295 }
00296 
00297 ffchar* ff_inessive_plural(const ffchar* word) {
00298   ffword theword;
00299 
00300   if (ffword_create(word, &theword)) {
00301     return NULL;
00302   }
00303 
00304   if (ffpriv_inessive_plural(&theword)) {
00305     ffword_delete(&theword);
00306     return NULL;
00307   }
00308 
00309   ffword_finalize(&theword);
00310   return theword.data.str;
00311 }
00312 
00313 ffchar* ff_elative_singular(const ffchar* word) {
00314   ffword theword;
00315 
00316   if (ffword_create(word, &theword)) {
00317     return NULL;
00318   }
00319 
00320   if (ffpriv_elative_singular(&theword)) {
00321     ffword_delete(&theword);
00322     return NULL;
00323   }
00324 
00325   ffword_finalize(&theword);
00326   return theword.data.str;
00327 }
00328 
00329 ffchar* ff_elative_plural(const ffchar* word) {
00330   ffword theword;
00331 
00332   if (ffword_create(word, &theword)) {
00333     return NULL;
00334   }
00335 
00336   if (ffpriv_elative_plural(&theword)) {
00337     ffword_delete(&theword);
00338     return NULL;
00339   }
00340 
00341   ffword_finalize(&theword);
00342   return theword.data.str;
00343 }
00344 
00345 ffchar* ff_illative_singular(const ffchar* word) {
00346   ffword theword;
00347 
00348   if (ffword_create(word, &theword)) {
00349     return NULL;
00350   }
00351 
00352   if (ffpriv_illative_singular(&theword)) {
00353     ffword_delete(&theword);
00354     return NULL;
00355   }
00356 
00357   ffword_finalize(&theword);
00358   return theword.data.str;
00359 }
00360 
00361 ffchar* ff_illative_plural(const ffchar* word) {
00362   ffword theword;
00363 
00364   if (ffword_create(word, &theword)) {
00365     return NULL;
00366   }
00367 
00368   if (ffpriv_illative_plural(&theword)) {
00369     ffword_delete(&theword);
00370     return NULL;
00371   }
00372 
00373   ffword_finalize(&theword);
00374   return theword.data.str;
00375 }
00376 
00377 ffchar* ff_adessive_singular(const ffchar* word) {
00378   ffword theword;
00379 
00380   if (ffword_create(word, &theword)) {
00381     return NULL;
00382   }
00383 
00384   if (ffpriv_adessive_singular(&theword)) {
00385     ffword_delete(&theword);
00386     return NULL;
00387   }
00388 
00389   ffword_finalize(&theword);
00390   return theword.data.str;
00391 }
00392 
00393 ffchar* ff_adessive_plural(const ffchar* word) {
00394   ffword theword;
00395 
00396   if (ffword_create(word, &theword)) {
00397     return NULL;
00398   }
00399 
00400   if (ffpriv_adessive_plural(&theword)) {
00401     ffword_delete(&theword);
00402     return NULL;
00403   }
00404 
00405   ffword_finalize(&theword);
00406   return theword.data.str;
00407 }
00408 
00409 ffchar* ff_ablative_singular(const ffchar* word) {
00410   ffword theword;
00411 
00412   if (ffword_create(word, &theword)) {
00413     return NULL;
00414   }
00415 
00416   if (ffpriv_ablative_singular(&theword)) {
00417     ffword_delete(&theword);
00418     return NULL;
00419   }
00420 
00421   ffword_finalize(&theword);
00422   return theword.data.str;
00423 }
00424 
00425 ffchar* ff_ablative_plural(const ffchar* word) {
00426   ffword theword;
00427 
00428   if (ffword_create(word, &theword)) {
00429     return NULL;
00430   }
00431 
00432   if (ffpriv_ablative_plural(&theword)) {
00433     ffword_delete(&theword);
00434     return NULL;
00435   }
00436 
00437   ffword_finalize(&theword);
00438   return theword.data.str;
00439 }
00440 
00441 ffchar* ff_allative_singular(const ffchar* word) {
00442   ffword theword;
00443 
00444   if (ffword_create(word, &theword)) {
00445     return NULL;
00446   }
00447 
00448   if (ffpriv_allative_singular(&theword)) {
00449     ffword_delete(&theword);
00450     return NULL;
00451   }
00452 
00453   ffword_finalize(&theword);
00454   return theword.data.str;
00455 }
00456 
00457 ffchar* ff_allative_plural(const ffchar* word) {
00458   ffword theword;
00459 
00460   if (ffword_create(word, &theword)) {
00461     return NULL;
00462   }
00463 
00464   if (ffpriv_allative_plural(&theword)) {
00465     ffword_delete(&theword);
00466     return NULL;
00467   }
00468 
00469   ffword_finalize(&theword);
00470   return theword.data.str;
00471 }
00472 
00473 ffchar* ff_abessive_singular(const ffchar* word) {
00474   ffword theword;
00475 
00476   if (ffword_create(word, &theword)) {
00477     return NULL;
00478   }
00479 
00480   if (ffpriv_abessive_singular(&theword)) {
00481     ffword_delete(&theword);
00482     return NULL;
00483   }
00484 
00485   ffword_finalize(&theword);
00486   return theword.data.str;
00487 }
00488 
00489 ffchar* ff_abessive_plural(const ffchar* word) {
00490   ffword theword;
00491 
00492   if (ffword_create(word, &theword)) {
00493     return NULL;
00494   }
00495 
00496   if (ffpriv_abessive_plural(&theword)) {
00497     ffword_delete(&theword);
00498     return NULL;
00499   }
00500 
00501   ffword_finalize(&theword);
00502   return theword.data.str;
00503 }
00504 
00505 ffchar* ff_instructive_singular(const ffchar* word) {
00506   ffword theword;
00507 
00508   if (ffword_create(word, &theword)) {
00509     return NULL;
00510   }
00511 
00512   if (ffpriv_instructive_singular(&theword)) {
00513     ffword_delete(&theword);
00514     return NULL;
00515   }
00516 
00517   ffword_finalize(&theword);
00518   return theword.data.str;
00519 }
00520 
00521 ffchar* ff_instructive_plural(const ffchar* word) {
00522   ffword theword;
00523   if (ffword_create(word, &theword)) {
00524     return NULL;
00525   }
00526 
00527   if (ffpriv_instructive_plural(&theword)) {
00528     ffword_delete(&theword);
00529     return NULL;
00530   }
00531 
00532   ffword_finalize(&theword);
00533   return theword.data.str;
00534 }
00535 
00536 ffchar* ff_comitative_plural(const ffchar* word) {
00537   ffword theword;
00538 
00539   if (ffword_create(word, &theword)) {
00540     return NULL;
00541   }
00542 
00543   if (ffpriv_comitative_plural(&theword)) {
00544     ffword_delete(&theword);
00545     return NULL;
00546   }
00547 
00548   ffword_finalize(&theword);
00549   return theword.data.str;
00550 }
00551 

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