Permalink
Browse files

romaji to kana conversion works

  • Loading branch information...
1 parent b572a45 commit 36d913e01c89523e8e05255b61d6f0f1f9bc52e0 @yuewangny yuewangny committed Nov 19, 2011
Showing with 98 additions and 185 deletions.
  1. +2 −2 po/zh_CN.po
  2. +35 −14 src/convert.c
  3. +9 −6 src/eim.c
  4. +1 −1 src/eim.h
  5. +49 −157 src/tables.c
  6. +2 −5 src/tables.h
View
@@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2011-11-19 18:24+0800\n"
+"POT-Creation-Date: 2011-11-19 20:40+0800\n"
"PO-Revision-Date: 2011-08-12 01:54+0800\n"
"Last-Translator: \n"
"Language-Team: Chinese Simplified <kde-i18n-doc@kde.org>\n"
@@ -19,7 +19,7 @@ msgstr ""
# unknown
#: /home/pipitu/workspace/fcitx-anthy/build/po/tmp/fcitx-anthy.conf.in.h:1
-#: /home/pipitu/workspace/fcitx-anthy/build/po/../..//src/eim.c:175
+#: /home/pipitu/workspace/fcitx-anthy/build/po/../..//src/eim.c:182
msgid "Anthy"
msgstr "Anthy"
View
@@ -18,17 +18,33 @@
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
+#include <stdio.h>
+#include <fcitx-utils/log.h>
+
#include "tables.h"
#include "eim.h"
int checkIfCorrectionNeeded(const char *buffer)
{
char c1 = *buffer;
char c2 = *(buffer + 1);
- return c1 == 'n' && (c2 != 'a' && c2 != 'i' && c2 != 'u'
+ return strlen(buffer) > 1 && c1 == 'n' && (c2 != 'a' && c2 != 'i' && c2 != 'u'
&& c2 != 'e' && c2 != 'o' && c2 != 'n' && c2 != 'y');
}
+int checkIfDoubleConsonat(const char *buffer){
+ if(buffer[0] == buffer[1]){
+ char c = buffer[0];
+ return c == 'b' || c == 'c' || c == 'd'
+ || c == 'f' || c == 'g' || c == 'h'
+ || c == 'j' || c == 'k' || c == 'm'
+ || c == 'p' || c == 'r' || c == 's'
+ || c == 't' || c == 'v' || c == 'w'
+ || c == 'x' || c == 'y' || c == 'z';
+ }
+ return 0;
+}
+
int FcitxAnthyConvertRomajiToKana(struct _FcitxAnthy *anthy)
{
@@ -37,7 +53,7 @@ int FcitxAnthyConvertRomajiToKana(struct _FcitxAnthy *anthy)
char *romaji_buffer = anthy->input_state.romaji_buffer;
int romaji_count = anthy->input_state.romaji_count;
- printf("input_buffer:%s romaji_buffer:%s\n",input_buffer,romaji_buffer);
+ FcitxLog(INFO,"input_buffer:%s romaji_buffer:%s",input_buffer,romaji_buffer);
if (checkIfCorrectionNeeded(romaji_buffer)) {
//apply correction rule in input
@@ -49,28 +65,33 @@ int FcitxAnthyConvertRomajiToKana(struct _FcitxAnthy *anthy)
romaji_buffer[0] = romaji_buffer[1];
romaji_buffer[1] = '\0';
romaji_count = 1;
- } else {
- const char *kana_string = NULL, *extra_romaji_string = NULL;
- FcitxAnthyLookupKanaForRomaji(anthy, romaji_buffer, &kana_string, &extra_romaji_string);
+ }
+ else if(checkIfDoubleConsonat(romaji_buffer)){
+ //apply double consonating rule in input
+ strcpy(input_buffer + input_count, "");
+ input_count += strlen("");
+ input_buffer[input_count] = '\0';
+
+ //update romaji buffer
+ romaji_buffer[1] = '\0';
+ romaji_count = 1;
+ }
+ else {
+ const char *kana_string = NULL;
+ FcitxAnthyLookupKanaForRomaji(anthy, romaji_buffer, &kana_string);
if (kana_string) {
- printf("kana:%s",kana_string);
strcpy(input_buffer + input_count, kana_string);
input_count += strlen(kana_string);
- if (extra_romaji_string) {
- strcpy(romaji_buffer, extra_romaji_string);
- romaji_count = strlen(romaji_buffer);
- } else {
- romaji_buffer[0] = '\0';
- romaji_count = 0;
- }
+ romaji_buffer[0] = '\0';
+ romaji_count = 0;
} else {
// todo: lookup symbol table
}
}
anthy->input_state.input_count = input_count;
anthy->input_state.romaji_count = romaji_count;
- printf("input_buffer:%s romaji_buffer:%s\n",input_buffer,romaji_buffer);
+ FcitxLog(INFO,"input_buffer:%s romaji_buffer:%s",input_buffer,romaji_buffer);
return 0;
}
View
@@ -77,26 +77,29 @@ INPUT_RETURN_VALUE FcitxAnthyDoInput(void* arg, FcitxKeySym sym, unsigned int st
{
FcitxAnthy* anthy = (FcitxAnthy*) arg;
FcitxInputState *input = FcitxInstanceGetInputState(anthy->owner);
- Messages *msgClientPreedit = FcitxInputStateGetClientPreedit(input);
+ Messages *msgPreedit = FcitxInputStateGetPreedit(input);
- //CleanInputWindowUp(anthy->owner);
+ CleanInputWindowUp(anthy->owner);
// todo: if convert key or predict key, convert or predict
if (IsHotKeySimple(sym, state)) {
char *romaji_buffer = (anthy->input_state).romaji_buffer;
int romaji_count = (anthy->input_state).romaji_count;
+
romaji_buffer[romaji_count ++] = sym & 0xff;
romaji_buffer[romaji_count] = '\0';
+ (anthy->input_state).romaji_count = strlen(romaji_buffer);
- printf("input:%c\n",romaji_buffer[romaji_count-1]);
+ FcitxLog(INFO,"input:%c\n",romaji_buffer[romaji_count-1]);
FcitxAnthyConvertRomajiToKana(anthy);
- printf("Input Display should be:%s%s\n",anthy->input_state.input_buffer,anthy->input_state.romaji_buffer);
- AddMessageAtLast(msgClientPreedit, MSG_INPUT, "%s", anthy->input_state.input_buffer);
+ FcitxLog(INFO,"romaji_buffer:%s count:%d\n",anthy->input_state.romaji_buffer,anthy->input_state.romaji_count);
+ FcitxLog(INFO,"Input Display should be:%s%s\n",anthy->input_state.input_buffer,anthy->input_state.romaji_buffer);
+ AddMessageAtLast(msgPreedit, MSG_INPUT, "%s", anthy->input_state.input_buffer);
if(romaji_buffer[0])
- AddMessageAtLast(msgClientPreedit, MSG_INPUT, "%s", anthy->input_state.romaji_buffer);
+ AddMessageAtLast(msgPreedit, MSG_INPUT, "%s", anthy->input_state.romaji_buffer);
return IRV_DISPLAY_MESSAGE;
} else {
View
@@ -66,7 +66,7 @@ typedef enum _TypingMode {
TYPING_MODE_KANA
} TypingMode;
-#define MAX_INPUT_COUNT 100
+#define MAX_INPUT_COUNT 1000
#define MAX_ROMAJI_COUNT 3
typedef struct _FcitxAnthyInputState {
Oops, something went wrong.

0 comments on commit 36d913e

Please sign in to comment.