Back to project page MYKey_SoftKeyboard.
The source code is released under:
Apache License
If you think the Android project MYKey_SoftKeyboard listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package korean_automata; /*from www . ja v a2 s .c om*/ import java.util.ArrayList; import com.android.mykey.*; import key_process.*; import korean_automata.*; public class KoreanAutomata { public static final int ST_EMPTY = 0; // ?? EMPTY??? public static final int ST_FIRST = 1; // ?? public static final int ST_VOWEL = 2; // ?? public static final int ST_AREA = 3; // ??? public static final int ST_FIRST_VOWEL = 4; // ??+?? public static final int ST_FIRST_AREA = 5; // ??+??? public static final int ST_FIRST_VOWEL_AND_FIRST = 6; // [??+??] + [??] ??? public static final int ST_SINGLE_FINAL = 7; // ?????? public static final int PROC1 = 8; // <??+??> + [??+???] ??? public static final int PROC2 = 9; // <??+??> + [??+??] ??? public static final int VERIFYCOMB = 10; // ??? ?? ???? ?? ??? public static final int ST_MULTI_FINAL = 11; // ???? public static final int ST_SINGLE_FINAL_AND_FIRST = 12; // [??????]+[??] ??? public static final int PROC3 = 13; // <??????> + [??+???] ??? public static final int PROC4 = 14; // <??????> + [??+??] ??? public static final int ST_ERROR = 15; // ??? ?? ??? public static final int FIRST_CONSONANT = 0; // ?? public static final int VOWEL = 1; // ?? public static final int FINAL_CONSONANT = 2; // ?? public static final int AREA = 3; // ??? public static final int UNKNOWN = 4; private static final int NUM_STATE = 16; private static final int NUM_INPUT = 4; private int currentState; private int previousState; private boolean isFinalInput; private Buffer buffer; private CombinationState resultState; private int phonemeInt[]; private ArrayList<CombinationState> stateArr; private int stTrTable[][]; private boolean isEnter; public void startCombine(boolean isRenew) { ArrayList<Integer> tmpBuffer = buffer.getPhoBuffer(); if(isRenew){ currentState = previousState; } do{ if(isEnter){ int phoneme = tmpBuffer.get(tmpBuffer.size()-1); int category = verifyPhonemeCategory(phoneme); previousState = currentState; currentState = stTrTable[currentState][category]; } resultState = stateArr.get(currentState); phonemeInt = resultState.combine(buffer.getPhoBuffer(), this); }while(resultState.isRepeat()); buffer.appendLetter(phonemeInt); } public int getPreviousState(){ return previousState; } public void setEnter(boolean isEnter){ this.isEnter = isEnter; }; public void setKoreanAutomataState(int currentState, int previousState) { this.currentState = currentState; this.previousState = previousState; } public boolean getIsFinalInput() { return isFinalInput; } public void setIsFinalInput(boolean isFinalInput) { this.isFinalInput = isFinalInput; } private void createCombinationTable() { for(int i = 0; i < stTrTable.length; i++){ for(int j = 0; j <stTrTable[i].length; j++){ stTrTable[i][j] = ST_ERROR; } } //[EMPTY]??? ???? stTrTable[ST_EMPTY][FIRST_CONSONANT] = ST_FIRST; //EMPTY -??-> ?? stTrTable[ST_EMPTY][VOWEL] = ST_VOWEL; //EMPTY -??-> ?? stTrTable[ST_EMPTY][FINAL_CONSONANT] = ST_FIRST; //EMPTY -??-> ?? stTrTable[ST_EMPTY][AREA] = ST_AREA; //EMPTY -???-> ??? //[??]??? ???? stTrTable[ST_FIRST][VOWEL] = ST_FIRST_VOWEL; //?? -??-> ??+?? stTrTable[ST_FIRST][AREA] = ST_FIRST_AREA; //?? -???-> ??+??? //[??+??]??? ???? stTrTable[ST_FIRST_VOWEL][FIRST_CONSONANT] = ST_FIRST_VOWEL_AND_FIRST; // ??+?? -??-> [??+??]+[??] stTrTable[ST_FIRST_VOWEL][FINAL_CONSONANT] = ST_SINGLE_FINAL; // ??+?? -??-> ?????? //[??+??]+[??]??? ???? stTrTable[ST_FIRST_VOWEL_AND_FIRST][VOWEL] = PROC2; // [??+??]+[??] -??-> <??+??> + [??+??] (PROC2) stTrTable[ST_FIRST_VOWEL_AND_FIRST][AREA] = PROC1; // [??+??]+[??] -???-> <??+??> + [??+???] (PROC1) //????????? ???? stTrTable[ST_SINGLE_FINAL][FIRST_CONSONANT] = VERIFYCOMB; // ?????? -??-> ????? stTrTable[ST_SINGLE_FINAL][VOWEL] = PROC2; // ?????? -??-> <??+??> + [??+??] (PROC2) stTrTable[ST_SINGLE_FINAL][FINAL_CONSONANT] = VERIFYCOMB; // ?????? -??-> ????? (ST_VERIFY_COMB) stTrTable[ST_SINGLE_FINAL][AREA] = PROC1; // ?????? -???-> <??+??> + [??+???] (PROC1) //??????? ???? stTrTable[ST_MULTI_FINAL][VOWEL] = PROC4; // ???? -??-> <??????> + [??+??] (PROC4) stTrTable[ST_MULTI_FINAL][AREA] = PROC3; // ???? -???-> <??????> + [??+???] (PROC3) //[??????]+[??]??? ???? stTrTable[ST_SINGLE_FINAL_AND_FIRST][VOWEL] = PROC4; // [??????]+[??] -??-> <??????> + [??+??] (PROC4) stTrTable[ST_SINGLE_FINAL_AND_FIRST][AREA] = PROC3; // [??????]+[??] -??-> <??????> + [??+???] (PROC3) } // ??? ?? private void createState() { stateArr.add(new StEmpty()); // ????? 0 stateArr.add(new StFirst()); // ?? 1 stateArr.add(new StVowel()); // ?? 2 stateArr.add(new StArea()); // ??? 3 stateArr.add(new StFirstVowel()); // ??+?? 4 stateArr.add(new StFirstArea()); // ??+??? 5 stateArr.add(new StFirstVowelAndFirst()); // [??+??] + [??] ??? 6 stateArr.add(new StSingleFinal()); // ?????? 7 stateArr.add(new Proc1()); // <??+??> + [??+???] 8 stateArr.add(new Proc2()); // <??+??> + [??+??] 9 stateArr.add(new VerifyComb()); // ?? ???? ?? ??? 10 stateArr.add(new StMultiFinal()); // ???? 11 stateArr.add(new StSingleFinalAndFirst()); // [??????] + [??] ??? 12 stateArr.add(new Proc3()); // <??????> + [??+???] 13 stateArr.add(new Proc4()); //<??????> + [??+??] 14 stateArr.add(new StError()); // ??? ?? ??? 15 } private int verifyPhonemeCategory(int phoneme) { int tmp = phoneme / 100; if (tmp == 40) return FIRST_CONSONANT; else if (tmp == 41) return VOWEL; else if(tmp == 82 || tmp == 87) return AREA; else if(tmp == 42) return FINAL_CONSONANT; else return UNKNOWN; } public void initPhonemeInt() { for (int i = 0; i < phonemeInt.length; i++) phonemeInt[i] = 0; } public Buffer getBuffer() { return buffer; } public void initKoreaAutomataState() { isEnter = true; currentState = ST_EMPTY; previousState = currentState; } public KoreanAutomata(Buffer buffer) { this.buffer = buffer; isEnter = true; phonemeInt = new int[3]; currentState = ST_EMPTY; previousState = currentState; isFinalInput = false; stateArr = new ArrayList<CombinationState>(); createState(); stTrTable = new int[NUM_STATE][NUM_INPUT]; createCombinationTable(); } }