Пример #1
0
        //----------------------------------------------------------------
        // J-->K方向の助詞翻訳
        static public string  TransJapanesePP(WordTable wt)
        {
            // ここにくるという事は posCategory == PosCategory.PPは確定している。

            // 1つ前の語に対応する韓国語を取り出す(パッチム判定のため)
            string prevtrans = "";

            if (wt.prev.transWord != "")
            {
                prevtrans = wt.prev.transWord;
            }
            else
            {
                prevtrans = wt.prev.GetTranslatedText();
            }

            // J-->K方向の助詞変換
            // こちらは前の語を翻訳しないと、変換すべき語を判断できない。
            if (Hangul.withPachim(prevtrans))
            {
                return(KJ_Filter.SearchPP_Pachim(wt.word));
            }
            else
            {
                return(KJ_Filter.SearchPP_NoPachim(wt.word));
            }
        }
Пример #2
0
 //-------------------------------------------------------
 // textが日本語の助詞ならば、Category.PPを返す。
 static public PosCategory  CheckPos_Hira(string input)
 {
     if (KJ_Filter.SearchPPall(input) != "")
     {
         return(PosCategory.PP);
     }
     else
     {
         return(PosCategory.Null);
     }
 }
Пример #3
0
        //------------------------------------------------------------------
        // 3文字語の調査 (部分分割後も使う)
        static private WordChain Check3Chars(WordTable wTable)
        {
            SearchResult sResult;

            // ABC --->  AB + C
            String head   = wTable.word.Remove(2, 1);
            String suffix = wTable.word.Substring(2, 1);

            sResult = KJ_dict.SearchFull(head);
            if (sResult != null)
            {
                // lastWordListにあるか調べる
                string translatedSuffix = KJ_Filter.SearchSuffix(suffix);
                if (translatedSuffix != "")
                {
                    WordTable headWt = new WordTable(head);
                    headWt.SetResult(sResult);
                    WordChain wc = new WordChain(headWt);

                    WordTable wt = new WordTable(suffix, translatedSuffix);
                    wt.Cost = 5;
                    wc.Add(wt);
                    return(wc);
                }
            }

            // ABC --->  A + BC
            String prefix = wTable.word.Remove(1, 2);
            String tail   = wTable.word.Substring(1, 2);

            sResult = KJ_dict.SearchFull(tail);
            if (sResult != null)
            {
                // lastWordListにあるか調べる
                string translatedPrefix = KJ_Filter.SearchPrefix(prefix);
                if (translatedPrefix != "")
                {
                    WordTable wt = new WordTable(prefix, translatedPrefix);
                    wt.Cost = 5;
                    WordChain wc = new WordChain(wt);

                    WordTable tailWt = new WordTable(tail);
                    tailWt.SetResult(sResult); // 全体でmatch

                    wc.Add(tailWt);
                    return(wc);
                }
            }

            return(null);
        }
Пример #4
0
        //-------------------------------------------------------
        static private WordChain DivideCountableMain(WordTable wTable, PosCategory poscategory)
        {
            WordChain wc = null;

            StringDivider sd = new  StringDivider(wTable.word);

            // 後から1文字ずつ落としつつ,検索。
            string trans = "";

            while (sd.eof() == false)
            {
                // 文字列を分割する
                HYAM.KJ_dict.Pair pair = sd.DivideBackward();

                if (poscategory == PosCategory.Numeral)
                {
                    trans = KJ_Filter.SearchNumeral(pair.head);
                }
                else
                {
                    trans = KJ_Filter.SearchNumerative(pair.head);
                }

                if (trans != "")
                {
                    WordTable wt_num = new WordTable(pair.head, trans);
                    wt_num.posCategory = poscategory;
                    wc = new WordChain(wt_num);

                    if (pair.tail != "")
                    {
                        WordTable wt_tail = new WordTable(pair.tail);
                        wc.Add(wt_tail);
                    }

                    return(wc);
                }
            }  // end of while


            return(null);
        }
Пример #5
0
        //-------------------------------------------------------
        // wordがハングルの助詞と完全一致なら、訳語をreturn で返す。
        static private String  CheckHangulPP_Full(WordTable wordT)
        {
            string word     = wordT.word;
            string prevword = "";

            if (wordT.prev == null)
            {
                return("");
            }

            // 前の語が空白なら助詞とは判断しない。
            //     초파리에서 이 유전자를 の「이」は「が」ではない
            if (!wordT.prev.IsWord())
            {
                return("");  // 何もせず抜ける
            }

            prevword = wordT.prev.word;   // 前の語

            // 前の語がハングルならつながっているから
            // このタイプの判断が必要なのは前が英数字
            //   ex.    MP3의
            return(KJ_Filter.SearchPPall(word));
        }
Пример #6
0
        //-------------------------------------------------------
        // 語のchainを先頭から舐め、助数詞・冠数詞を解析する。
        static public WordTable Scan(WordChain wChain, WordTable wTable)
        {
            if (wTable.IsTranslated())
            {
                return(wTable);  // 変換済みなら何もしない
            }

            WordTable next = wTable.NextWord();  // 次の有効な語を返す。(空白skip)

            // 前後を数字(Digit)に挟まれる場合
            if ((wTable.prev != null && wTable.prev.IsDigit()) &&
                (next != null && next.IsDigit()))
            {
                string transword = KJ_Filter.SearchNumConnecting(wTable.word);
                if (transword != "")
                {
                    wTable.transWord   = transword;
                    wTable.posCategory = PosCategory.Numerative;
                    wTable.Cost        = 1;
                    return(wTable);
                }
            }

            // 1つ前のWordTableは数字(Digit)の場合
            // または数詞(Numeral)である場合
            if ((wTable.prev != null && wTable.prev.IsDigit()) ||      // 800억 の 억
                (wTable.PrevWord() != null &&
                 wTable.PrevWord().posCategory == PosCategory.Numeral) // 800억원 --> 800+억+원の원
//                 160억 개의 のように空白をはさむ事があるので空白skipで前の語を調べる
                )
            {
                WordChain dividedChain = DivideCountable(wTable);

                if (dividedChain != null)
                {
                    // 助数詞であった

                    // devidedChainは 助数詞+語のチェーン。wTableと入れ替える
                    //   (+語はない場合もある)
                    wChain.Swap(wTable, dividedChain);

                    // 処理済みTable変更
                    wTable = dividedChain.Head;
                }
            }
            else
            {
                // 次の語が数字である場合 (冠数詞)  NumerativePrefix
                //   ★前数字と違い、空白はさんでも許す  (약 90만  or  약90만)
                if (next != null && next.IsDigit())
                {
                    string transword = KJ_Filter.SearchPreNum(wTable.word);
//                    string transword = CheckPreNum(wTable);
                    if (transword != "")
                    {
                        wTable.transWord   = transword;
                        wTable.posCategory = PosCategory.NumerativePrefix;
                        // ちょっと違うか。あとで
                        wTable.Cost = 1;
                    }
                }
            }

            return(wTable);
        }
Пример #7
0
        //-------------------------------------------------------
        static private WordChain  DivideJapanesePP(WordTable wTable)
        {
            StringDivider sd = new  StringDivider(wTable.word);

            // 前から1文字ずつ落としつつ,検索。
            string trans = "";

            while (sd.eof() == false)
            {
                // 文字列を分割する
                HYAM.KJ_dict.Pair pair = sd.DivideForward();

                if (Hangul.withPachim(pair.head))
                {
                    trans = KJ_Filter.SearchPP_Pachim(pair.tail);
                }
                else
                {
                    trans = KJ_Filter.SearchPP_NoPachim(pair.tail);
                }

                if (trans == "")
                {
                    continue;
                }

                SearchResult result = KJ_dict.SearchFull(pair.head);

                if (result != null)
                {
                    // 助詞確定

                    // 助詞に先行しない語は除外
                    //   산은  (은が助詞なら、산は動詞[連体詞]ではない)
                    //   result = SearchResult.CheckPPConnectable(result);

                    // もし語が全部落ちたならば何もしない
                    if (result.documents.Count == 0)
                    {
                        // nop
                    }
                    else
                    {
                        // 先行語+助詞のチェーンを作る
                        WordTable wt1 = new WordTable(pair.head);
                        wt1.SetResult(result);
                        wt1.divided = Divided.Lead;

                        // wt2.transWord はまだ設定しない。
                        //   前の訳語のパッチムに影響されるため。
                        WordTable wt2 = new WordTable(pair.tail);
                        wt2.posCategory = PosCategory.PP;
                        wt2.divided     = Divided.Trail;

                        // 長い助詞ほどコストを低くする
                        // wt2.Cost      = 0;
                        if (wt2.word.Length > 2)
                        {
                            wt2.Cost = 0;
                        }
                        else if (wt2.word.Length == 2)
                        {
                            wt2.Cost = 3;
                        }
                        else
                        {
                            wt2.Cost = 5;
                        }

                        WordChain rtnChain = new WordChain(wt1, wt2);

                        return(rtnChain);
                    }
                }
            }  // end of while


            return(null);  // 分離できなかったらnullを返す。
        }
Пример #8
0
        //-------------------------------------------------------
        // 辞書チェックなしのハングル助詞チェック
        //
        //    末尾が助詞と一致するなら分離する。
        //
        static public WordChain CheckPPwithoutDictKr(WordTable wt)
        {
            if (wt.IsTranslated())
            {
                // 翻訳済みなら何もしない。
                return(null);
            }
            if (wt.charCategory != CharCategory.Hangul &&
                wt.charCategory != CharCategory.LetterMix)
            {
                // ハングルでないなら、または英字+ハングルでないなら何もしない。
                return(null);
            }

            WordTable rtnWt = wt;   // 戻りのdefault

            StringDivider sd = new  StringDivider(wt.word);

            string trans = "";

            // 前から1文字ずつ落としつつ,検索。
            while (sd.eof() == false)
            {
                // 文字列を分割する
                HYAM.KJ_dict.Pair pair = sd.DivideForward();

                if (Hangul.withPachim(pair.head))
                {
                    trans = KJ_Filter.SearchPP_Pachim(pair.tail);
                }
                else
                {
                    trans = KJ_Filter.SearchPP_NoPachim(pair.tail);
                }

                if (trans == "")
                {
                    continue;
                }

                // wtをwt1とwt2に分割
                WordTable wt1 = new WordTable(pair.head);
                wt1.divided = Divided.Lead;

                //  分離できた。 wT2は助詞と仮定。訳語も入れておく
                WordTable wt2 = new WordTable(pair.tail, trans);
                wt2.posCategory = PosCategory.PP;
                wt2.Cost        = 2;
                wt2.divided     = Divided.Trail;


                WordChain rtnChain; // 返却チェーン
                // wt1を調査
                //  (未知語なので分割してみる)
                WordChain wc1 = KJ_Analyzer.WordPartProc(wt1);

                if (wc1 == null)
                {
                    // 分割できなかった
                    rtnChain = new WordChain(wt1, wt2);
                }
                else
                {
                    wc1.Add(wt2);
                    rtnChain = wc1;
                }

                return(rtnChain);
            }

            return(null);  // 分離できなかったらnullを返す
        }