diff options
author | Suren A. Chilingaryan <csa@dside.dyndns.org> | 2005-08-05 03:06:50 +0000 |
---|---|---|
committer | Suren A. Chilingaryan <csa@dside.dyndns.org> | 2005-08-05 03:06:50 +0000 |
commit | 94ca629ceec7b0dc9f6f724b2e15923d3ec1d5b3 (patch) | |
tree | 317019f306f7195c07d3c0d943c829ed11ba8cca /src/rccspell.c | |
parent | 50aa5cd62ef4a66da41d68f4a50ddfca97863c38 (diff) | |
download | librcc-94ca629ceec7b0dc9f6f724b2e15923d3ec1d5b3.tar.gz librcc-94ca629ceec7b0dc9f6f724b2e15923d3ec1d5b3.tar.bz2 librcc-94ca629ceec7b0dc9f6f724b2e15923d3ec1d5b3.tar.xz librcc-94ca629ceec7b0dc9f6f724b2e15923d3ec1d5b3.zip |
Language AutoDetection Improvements
- Fix: Loading/Saving range options.
- Fix: Language AutoDetection. Using locale language instead of selected one.
- Support for range options in GTK UI.
- Option to control recoding timeout is provided.
- LibRCC.h is updated (Translate, Spell, IConv).
- Documentation is updated.
- Add 'rcc-config' alias to 'rcc-gtk2-config' in spec.
- Implemented concept of parrent languages
+ The concept is used in language autodetection. The string in considered
language is permited to have words from all it's parrent languages.
+ English is assumed to be parrent for all other languages by default.
+ Russian is parrent language for Ukrainian and Belorussian.
- No translation to english if translation between related (one of the
languages is parrent for another one) languages is failed.
Diffstat (limited to 'src/rccspell.c')
-rw-r--r-- | src/rccspell.c | 53 |
1 files changed, 48 insertions, 5 deletions
diff --git a/src/rccspell.c b/src/rccspell.c index c54e267..da5e4d1 100644 --- a/src/rccspell.c +++ b/src/rccspell.c @@ -1,6 +1,7 @@ #include <stdio.h> #include <stdlib.h> +#include "internal.h" #include "rccspell.h" rcc_speller rccSpellerCreate(const char *lang) { @@ -28,6 +29,7 @@ rcc_speller rccSpellerCreate(const char *lang) { } rccspeller->speller = speller; + rccspeller->parrents[0] = NULL; return rccspeller; #else return NULL; @@ -47,17 +49,58 @@ int rccSpellerGetError(rcc_speller rccspeller) { return 0; } -int rccSpellerSized(rcc_speller speller, const char *word, size_t len) { +int rccSpellerAddParrent(rcc_speller speller, rcc_speller parrent) { + unsigned int i; + if ((!speller)||(!parrent)) return -1; + + for (i=0;speller->parrents[i];i++); + if (i >= RCC_MAX_LANGUAGE_PARRENTS) return -1; + speller->parrents[i++] = parrent; + speller->parrents[i] = NULL; + + return 0; +} + +rcc_speller_result rccSpellerSized(rcc_speller speller, const char *word, size_t len, int recursion) { #ifdef HAVE_ASPELL + rcc_speller_result result, saved_result = (rcc_speller_result)0; + unsigned int i; int res; + + if (rccSpellerGetError(speller)) return (rcc_speller_result)RCC_SPELLER_INCORRECT; + + if (recursion) { + for (i=0; speller->parrents[i]; i++) { + result = rccSpellerSized(speller->parrents[i], word, len, 0); + if ((result == RCC_SPELLER_CORRECT)||(result == RCC_SPELLER_PARRENT)) return RCC_SPELLER_PARRENT; + if ((result == RCC_SPELLER_ALMOST_CORRECT)||(result == RCC_SPELLER_ALMOST_PARRENT)) saved_result = RCC_SPELLER_ALMOST_PARRENT; + } + } - if (rccSpellerGetError(speller)) return 0; + if (saved_result) return saved_result; + res = aspell_speller_check(speller->speller, word, len?len:-1); - return res<0?0:res; + return res<=0?RCC_SPELLER_INCORRECT:RCC_SPELLER_CORRECT; #endif /* HAVE_ASPELL */ return 0; } -int rccSpeller(rcc_speller speller, const char *word) { - return rccSpellerSized(speller, word, 0); +rcc_speller_result rccSpeller(rcc_speller speller, const char *word) { + return rccSpellerSized(speller, word, 0, 1); +} + +int rccSpellerResultIsOwn(rcc_speller_result res) { + if ((res == RCC_SPELLER_ALMOST_CORRECT)||(res == RCC_SPELLER_CORRECT)) return 1; + return 0; +} + +int rccSpellerResultIsPrecise(rcc_speller_result res) { + if ((res == RCC_SPELLER_PARRENT)||(res == RCC_SPELLER_CORRECT)) return 1; + return 0; +} + +int rccSpellerResultIsCorrect(rcc_speller_result res) { + if ((res == RCC_SPELLER_ALMOST_CORRECT)||(res == RCC_SPELLER_CORRECT)) return 1; + if ((res == RCC_SPELLER_ALMOST_PARRENT)||(res == RCC_SPELLER_PARRENT)) return 1; + return 0; } |