Exemple #1
0
        //-------------------------------------------------------
        //  分割なし完全一致の語
        static public WordTable Scan(WordChain wChain, WordTable wTable)
        {
            if (wTable.IsTranslated())
            {
                return(wTable);  // 変換済みなら何もしない
            }


            // 翻訳しなくていい文字は抜ける
            if (!wTable.IsWord() ||     // 空白や制御文字
                wTable.IsDigit() ||
                wTable.IsOther())       // 記号
            {
                return(wTable);
            }


            // 助詞なら抜ける
            if (wTable.posCategory == PosCategory.PP)
            {
                return(wTable);
            }


            // 独立した1文字の語は辞書より先に検索   (単独の이など)
            if (wTable.word.Length == 1)
            {
                CheckOneWord(wTable);
                if (wTable.transWord != "")
                {
                    return(wTable);    // match
                }
            }


            // 全体で完全一致で検索
            SearchResult sResult = KJ_dict.SearchFull(wTable.word);

            if (sResult != null)
            {
                wTable.SetResult(sResult);
                return(wTable);    // 完全一致で見つかった
            }


            // 4文字語の調査 (部分分割後は使わない)
            WordChain wc = Check4Chars(wTable);

            if (wc != null)
            {
                wChain.Swap(wTable, wc);
                return(wc.Tail);
            }



            return(wTable);
        }
Exemple #2
0
        //-------------------------------------------------------------------
        // WordChainの各WordTableから翻訳結果を取り出し翻訳後文字列を返す
        private String Chain2String(WordChain wc)
        {
            StringBuilder result;           // 出力文字列

            result = new StringBuilder();


            // debuginfo is True
            if (this.debugInfo)
            {
                result.Append("original ⇒ result " +
                              "(char)(pos)(GetWordCost)(divided)\n");
            }

            // 語のchainを先頭から舐め、翻訳結果をresultに順次追加。
            WordTable wt = wc.Head;

            while (wt != null)
            {
                // debuginfo is True
                if (this.debugInfo)
                {
                    if (wt.IsWord())
                    {
                        result.Append(wt.word + " ⇒ ");
                    }
                }

                // 翻訳用前処理
                TranslationPreproc(wt);

                // wtから翻訳済みテキストを取り出す
                string translated = wt.GetTranslatedText();
                // 翻訳できなかったら元文字をそのまま返す
                if (translated == "")
                {
                    translated = wt.word;
                }

                result.Append(translated);

                // debuginfo is True
                if (this.debugInfo)
                {
                    result.Append("\n");
                    MakeDebugInfo(result, wt);
                }

                // 次のWordTableへ
                wt = wt.next;
            }

            return(result.ToString());
        }
Exemple #3
0
        //----------------------------------------------------------------
        // 語分割ありの熟語チェック
        //     공부하지는 못할 것이라는==> 공부 + 하지는 못할 것이라는
        //     ~~~~~~~~~~                         ~~~~~~~~~~~~~~~~~~~~
        //      startwt                       ここのWordTableはdivided=Trail
        //
        static public WordTable  Search2(WordChain wc, WordTable startwt)
        {
            String str = startwt.word;

            if (!startwt.IsWord())
            {
                return(null);     // 空白などで始まる場合は、は処理しない
            }

            int target_len = 1;
            int str_len    = str.Length;

            // 前から1文字ずつ落としつつ,熟語検索。
            while (true)
            {
                if (target_len >= str_len)
                {
                    break;
                }

                // 文字列を分割する
                // str --> str2 + str3
                String str2 = str.Substring(0, target_len);
                String str3 = str.Remove(0, target_len);

                WordTable wt3 = new WordTable(str3);
                wt3.next = startwt.next;
                wt3.prev = startwt.prev;
                WordTable idiomTable = Idiom.Search(wc, wt3);

                if (idiomTable != null)
                {
                    // 熟語確定
                    WordTable wt2 = new WordTable(str2);
                    wc.InsertBefore(idiomTable, wt2);

                    WordChain wc2 = KJ_Analyzer.WordPartProc(wt2);
                    if (wc2 != null)
                    {
                        wc.Swap(wt2, wc2);
                    }
                    idiomTable.divided = Divided.Trail;
                    return(idiomTable);
                }

                target_len++;
            }

            return(null);
        }
Exemple #4
0
        //  前の有効な語を返す。(空白skip)
        public WordTable PrevWord()
        {
            WordTable wt = this.prev;

            while (true)
            {
                if (wt == null)
                {
                    break;
                }

                if (wt.IsWord())
                {
                    return(wt);
                }
                wt = wt.prev;
            }
            return(null);
        }
Exemple #5
0
        //---------------------------------------------
        //  次の有効な語を返す。(空白skip)
        public WordTable NextWord()
        {
            WordTable wt = this.next;

            while (true)
            {
                if (wt == null)
                {
                    break;
                }

                if (wt.IsWord())
                {
                    return(wt);
                }
                wt = wt.next;
            }
            return(null);
        }