示例#1
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);
        }
示例#2
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を返す。
        }
示例#3
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を返す
        }