示例#1
0
        //--------------------------------------------------------------------
        // 完全一致の辞書検索 (再起にすると時間がかかりすぎるので再起なし)
        //
        static public WordChain  DividedWordSearch(string str)
        {
            WordTable wt;
            WordChain wc;

            #if DEBUG_LOG
            KJ_Analyzer.WriteDebugLog("DividedWordSearch:" + str);
            #endif

            SearchResult sResult = KJ_dict.SearchFull(str);

            if (sResult == null)
            {
                // strが辞書にない
                // wc = WordPartProc(wt);
                return(null);
            }

            wt = new WordTable(str);
            wc = new WordChain();

            // 検索できた
            wt.SetResult(sResult); // wt3に検索結果を入れる
            //wt.IsDevided=true;  // 分割語であるマーク

            wc.Add(wt);

            return(wc);
        }
示例#2
0
        //----------------------------------------------------------------------
        private SearchResult RegexSearch(string searchword)
        {
            // 正規表現の形式誤りをチェックする
            try{
                Regex regex = new Regex(searchword);
            }catch {
                SearchResult regexerr = new SearchResult();
                regexerr.return_code = -20;
                return(regexerr);
            }

            // サポート外の正規表現
            if (searchword.IndexOf("(") >= 0 ||
                searchword.IndexOf(")") >= 0 ||
                searchword.IndexOf("^") >= 0 ||
                searchword.IndexOf("$") >= 0)
            {
                SearchResult notfound = new SearchResult();
                notfound.return_code = -21;
                return(notfound);
            }

            // 正規表現検索
            SearchType searchType = SearchType.regex;

            return(KJ_dict.RegexSearch(searchType, searchword));
        }
示例#3
0
        //--------------------------------------------------------------------
        // 翻訳処理
        public void form_search()
        {
            if (translatorThread != null)
            {
                //  検索中を示す背景色とタイトルを戻す
                this.BackColor = System.Drawing.SystemColors.Control;
#if !EDICT
                this.Text = "KJ_dictform";
#else
                this.Text = "KJ_Edict";
#endif

                translatorThread.Abort();
                // filterを戻す
                KJ_dict.SetFilter(this.filter);
            }

            // 現在のfilterをbackup
            this.filter = KJ_dict.GetFilter();

            // 処理用のスレッドを作成
            translatorThread = new Thread(new ThreadStart(this.form_search_thread));
            translatorThread.Start();

            // filterを戻す
            KJ_dict.SetFilter(this.filter);
        }
示例#4
0
        //-------------------------------------------------------------------------

        // Formの閉じるボタン(右上の[X])が押された場合。
        private void KJ_hangulbuttonform_FormClosing(object sender,
                                                     FormClosingEventArgs e)
        {
            // 通常検索に戻す
            KJ_dict.DictOpen("KJ_dict.yml");

            this.kj_form.inputArea.Enabled = true; // 入力可能に戻す
        }
示例#5
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);
        }
示例#6
0
        private void exit_Click(object sender, System.EventArgs e)
        {
            // 通常検索に戻す
            KJ_dict.DictOpen("KJ_dict.yml");

            this.kj_form.inputArea.Enabled = true; // 入力可能に戻す

            this.Close();
        }
示例#7
0
        // (*2) xxxxする、xxxxさせる  etc
        //
        //======================================================================
        //
        //  private methods
        //
        //-------------------------------------------------------------

        // 品詞条件付きサーチ
        static private string SearchDictwithPos(string inputword, string pos)
        {
            SearchResult sResult = KJ_dict.SearchFull(inputword);

            if (sResult == null)
            {
                return("");
            }

            return(sResult.MakeTranslatedText(pos));
        }
示例#8
0
        //---------------------------------------------------------------------
        // static コンストラクタ
        //
        static KJ_dict()
        {
            #if DEBUG_DICTLOG
            KJ_dict.StartDebugLog();
            KJ_dict.WriteDebugLog("KJ_dict static constructor");
            #endif

            KJ_dict.HashAvailable        = false;           // デフォルトはHash未使用
            KJ_dict.dictHash             = new Hashtable(); // hash初期化
            KJ_dict.dictCheckForwardHash = new Hashtable(); // hash初期化
            KJ_dict.dictCheckFullHash    = new Hashtable(); // hash初期化
        }
示例#9
0
 // 辞書ファイルOpen
 //     Arrayファイルを個別に指定する場合
 static public void  DictOpen(string yaml_master, string arrayfile)
 {
     yaml_master     = "dict\\" + yaml_master;
     arrayfile       = "dict\\" + arrayfile;
     dict_instance_w = new KJ_DictData(yaml_master, (arrayfile + ".w.ary"));
     dict_instance_c = new KJ_DictData(yaml_master, (arrayfile + ".c.ary"));
     #if DEBUG_DICTLOG
     KJ_dict.WriteDebugLog("## DictOpen ##");
     KJ_dict.WriteDebugLog("yaml_master=" + yaml_master +
                           ", arrayfile=" + arrayfile);
     #endif
 }
示例#10
0
        private bool isBrowser = false;  // KJ_browserからの起動か?


        //-------------------------------------------------------------------
        // コンストラクタ
        public StringTrans()
        {
            this.pBar = null;

            // 一度ひいた辞書内容を格納するHashを使用する
            KJ_dict.HashAvailable = true;

            // Open dictionary
            KJ_dict.DictOpen("KJ_dict.yml", "KJ_dict.yml.small");
            // 翻訳では字母分解とかローマ字で検索しないので
            // それらを省いた小さいarrayを使う
        }
示例#11
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);
        }
示例#12
0
        //---------------------------------------------------------------------
        // 条件にマッチする辞書の登録語の最初のグループを調べる
        private long bsearch_top(SearchType searchtype, String search_word)
        {
            if (search_word.Length == 0)
            {
                return(-1);   // 該当語なし
            }

            // とりあえずマッチする1個を調べる
            long index = bsearch_match_one(searchtype, search_word);

            if (index == -1)
            {
#if DEBUG_DICTLOG
                KJ_dict.WriteDebugLog("■Cannot found [" + search_word + "]");
#endif
                return(index);   // 該当語なし
            }

            // indexから前方にマッチする間さかのぼる
            int cnt = 0;  // カウンタ
            while (true)
            {
                if (cnt > 100)
                {
                    // 100以上は さかのぼらない
                    //   最大100個しか返さないので無駄な検索はしない
                    break;
                }
                cnt++;

                // indexは一致している。その1つ前を調べる。
                long check = index - 1;
                if (check < 0)
                {
                    break;  // indexは0が最小。
                }
                String word = KJ_SuffixArray.GetWord(this.dict_fs,
                                                     this.array_reader, check);
                if (this.dictword.Compare(searchtype, search_word, word))
                {
                    // 1つ前も一致したならさらにさかのぼる
                    index = check;
                }
                else
                {
                    break;  // 一致しないなら終了
                }
            }

            return(index);
        }
示例#13
0
        //--------------------------------------------------------------------
        // その他正規表現検索
        static public SearchResult RegexSearch(SearchType type, string searchword)
        {
            SearchResult result;


            char[] any1 = new char[] { '.', '*', '?', '+', '[', '{' };
            char[] any2 = new char[] { '.', '*', '?', '+', ']', '}' };

            int leftPos  = searchword.IndexOfAny(any1);
            int rightPos = searchword.LastIndexOfAny(any2);
            int strLen   = searchword.Length;

            // あいう[か-く]まみ
            // 0 1 2 34 56 78 9
            //  leftPos:3    rightPos:7  strLen:9
            //    head : あいう
            //    tail : まみ
            //  if(leftPos+1==rightPos){
            //      return null;
            //  }

            string head = searchword.Substring(0, leftPos);
            string tail = searchword.Remove(0, rightPos + 1);

            KJ_dict.filterRegexword = searchword;

            // filterのデリゲート生成
            FilterDelegate dictFilter = new FilterDelegate(KJ_dict.RegexFilter);

            KJ_dict.SetFilter(dictFilter);

            // 長い方を優先に、前方一致または後方一致をかけ、
            // その結果からfilterを使い絞込みを行う。
            if (head.Length >= tail.Length)
            {
                result = KJ_dict.DictSearch(SearchType.forward, head);
            }
            else
            {
                result = KJ_dict.DictSearch(SearchType.backward, tail);
            }


            return(result);
        }
示例#14
0
        //------------------------------------------------------------------
        // 4文字語の調査 (部分分割後は使わない)
        static private WordChain Check4Chars(WordTable wTable)
        {
            SearchResult sResult;

            if (KJ_dict.inputIsHangul)
            {
                // 4文字以外は抜ける。
                if (wTable.word.Length != 4)
                {
                    return(null);
                }

                if (wTable.word.EndsWith("하게"))
                {
                    string head = wTable.word.Remove(2, 2);  // 4文字なので固定
                    sResult = KJ_dict.SearchFull(head);
                    if (sResult != null)
                    {
                        WordTable tempwt = new WordTable(head);
                        tempwt.SetResult(sResult);
                        string trans = tempwt.GetTranslatedText();

                        wTable.transWord   = trans + "に";
                        wTable.Cost        = 10;
                        wTable.posCategory = PosCategory.PP;

                        WordChain wc = new  WordChain(wTable);

                        // これだけならwtでもいいが、汎用化のためwcで返す
                        return(wc);
                    }
                }
            }

            return(null);
        }
示例#15
0
        //------------------------------------------------------------------------
        // Panel上のコンテキストメニュー
        private void hangul_button_Click(object sender, System.EventArgs e)
        {
            // モードレス
            if (hangul_button_instance == null ||
                hangul_button_instance.IsDisposed)
            {
                hangul_button_instance = new Hangul_Button_Form(this);

                // 要素検索に変更
                KJ_dict.DictOpen("KJ_dict.yml", "KJ_dict.yml.krparts");

                // 表示するIMEに現在のKJ_formを設定
                hangul_button_instance.kj_form = this;

                hangul_button_instance.Show();
            }
            else
            {
                if (hangul_button_instance != null)
                {
                    hangul_button_instance.Focus();
                }
            }
        }
示例#16
0
// for RichTextBoxEx
//        private void AddText(string text)
//        {
//            if (this.richTextBox2.InvokeRequired)
//            {
//                AddTextCallback d = new AddTextCallback(AddText);
//                this.Invoke(d, new object[] { text });
//            }
//            else
//            {
//                this.richTextBox2.SelectedText = text;
//               // this.richTextBox2.Text += text;
//            }
//        }
//        private void AddLink(string text)
//        {
//            if (this.richTextBox2.InvokeRequired)
//            {
//                AddlinkCallback d = new AddlinkCallback(AddLink);
//                this.Invoke(d, new object[] { text });
//            }
//            else
//            {
//                this.richTextBox2.InsertLink(text);
//            }
//        }

        //--------------------------------------------------------------------
        // 検索用スレッド
        //   (正規表現検索に入ると時間がかかる場合があるため別スレッドにする)
        public void form_search_thread()
        {
            Cursor preCursor = Cursor.Current;

            //  検索中を示すためタイトルを変える
            this.Text = this.searchingLabel;

            String searchword = this.inputArea.Text;


            searchword = searchword.Trim();
            if (searchword == "")
            {
                richTextBox2.Text = "";

                //  検索中を示すタイトルを戻す
#if !EDICT
                this.Text = "KJ_dictform";
#else
                this.Text = "KJ_Edict";
#endif
                // 検索語がない
                return;
            }

#if EDICT
            // 大文字→小文字変換する。
            //   There had to be times... のように
            //   文頭の大文字始まりの単語を引けるように。
            searchword = searchword.ToLower();
#endif

            // 検索の種別
            SearchType searchType = SearchType.forward;   //default

            if (this.radioButton1.Checked == true)
            {
                searchType = SearchType.full;       // 完全一致
            }
            if (this.radioButton2.Checked == true)
            {
                searchType = SearchType.forward;    // 前方一致
            }
            if (this.radioButton3.Checked == true)
            {
                searchType = SearchType.backward;   // 後方一致
            }
            if (this.radioButton4.Checked == true)
            {
                searchType = SearchType.part;       // 部分一致
            }


            SearchResult result;

            if (searchword.IndexOf("*") < 0 &&
                searchword.IndexOf("+") < 0 &&
                searchword.IndexOf(".") < 0 &&
                searchword.IndexOf("^") < 0 &&
                searchword.IndexOf("$") < 0 &&
                searchword.IndexOf("(") < 0 &&
                searchword.IndexOf("[") < 0 &&
                searchword.IndexOf("{") < 0 &&
                searchword.IndexOf("?") < 0)
            {
                // 通常検索
                result = KJ_dict.DictSearch(searchType, searchword);
            }
            else
            {
                // 正規表現検索
                result = RegexSearch(searchword);
            }

            // make result text
            //     MakeResultText(searchword, searchType, result); // for RichTextBoxEx
            this.SetText(MakeResultText(searchword, searchType, result));

            //  検索中を示す背景色とタイトルを戻す
            this.BackColor = System.Drawing.SystemColors.Control;
#if !EDICT
            this.Text = "KJ_dictform";
#else
            this.Text = "KJ_Edict";
#endif
        }
示例#17
0
        //---------------------------------------------------------------------
        // とりあえずマッチする1個を調べる     (バイナリサーチ)
        //   マッチする一群の先頭とは限らない
        //
        // もし見つかったらSuffix Arrayのindex pointを返す
        // -1  : 見つからなかった
        //
        public long bsearch_match_one(SearchType searchtype, string search_word)
        {
            long low;
            long high;

            high = array_index_max;
            low  = 0;

            long index;

            #if DEBUG_DICTLOG
            KJ_dict.WriteDebugLog("index,low,high");
            #endif

            //  最初の検索index設定
            index = (high - low) / 2 + low;     //  5/2-->2 (.5切捨て)
            while (true)
            {
                String word = KJ_SuffixArray.GetWord(this.dict_fs,
                                                     this.array_reader, index);

                #if DEBUG_DICTLOG
                KJ_dict.WriteDebugLog(index + "," + low + "," + high);
                KJ_dict.WriteDebugLog("  word=" + word + "(" +
                                      index + ")");
                String wordTemp;
                wordTemp = KJ_SuffixArray.GetWord(this.dict_fs,
                                                  this.array_reader, low);
                KJ_dict.WriteDebugLog("  low =" + wordTemp + "(" +
                                      low + ")");
                wordTemp = KJ_SuffixArray.GetWord(this.dict_fs,
                                                  this.array_reader, high);
                KJ_dict.WriteDebugLog("  high=" + wordTemp + "(" +
                                      high + ")");
                #endif

                if (this.dictword.Compare(searchtype, search_word, word))
                {
                    // 見つかったので抜ける
                    #if DEBUG_DICTLOG
                    KJ_dict.WriteDebugLog("■Found [" + search_word +
                                          "] (index=" + index +
                                          " word=" + word + ")");
                    #endif
                    break;
                }

                if (low == index)
                {
                    if (high == (low + 1))
                    {
                        // もしlowとhighが1しか違わないなら
                        // lowはチェック済みなのでhighをチェックすればいい
                        index = high; //  次の検索index再設定
                        continue;
                    }
                    else
                    {
                        return(-1);   // マッチせず
                    }
                }
                if (high == index)
                {
                    return(-1);   // マッチせず
                }

                string word_no_space        = word.Replace(" ", "");                // 2005.08.19
                string search_word_no_space = search_word.Replace(" ", "");         // 2005.08.19
                if (String.CompareOrdinal(word_no_space, search_word_no_space) < 0) // 2005.08.19
                //         if(String.CompareOrdinal(word, search_word) < 0 ) // 2005.08.19
                {
                    low = index;
                    // もしlowとhighが1しか違わないなら
                    // lowはチェック済みなのでhighをチェックすればいい
                    if (high == (low + 1))
                    {
                        index = high; //  次の検索index再設定
                        continue;
                    }
                }
                else
                {
                    high = index;
                }
                index = (high - low) / 2 + low;     //  次の検索index再設定
            }

            return(index);
        }
示例#18
0
        //---------------------------------------------------------------------
        //    辞書引きのメインのサーチメソッド。
        public SearchResult Search(SearchType searchtype, String search_word)
        {
            SearchResult result = new  SearchResult();

            #if DEBUG_DICTLOG
            KJ_dict.WriteDebugLog
                ("------------------------------------------------------------");
            KJ_dict.WriteDebugLog("Search Start");
            #endif

            // 条件にマッチするarrayの要素の先頭番号を調べる
            long match_top = bsearch_top(searchtype, search_word);

            #if DEBUG_DICTLOG
            KJ_dict.WriteDebugLog("Search End");
            #endif

            if (match_top == -1)
            {
                result.return_code = -1;
                result.documents   = new ArrayList();
                return(result);     // 検索ができなかった
            }

            // マッチした先頭から順に取り出し,resultにつなぐ
            result.return_code = 0;
            result.documents   = new ArrayList();

            long index = match_top;
            int  cnt   = 0;
            while (true)
            {
                // suffix arrayのindex番目の語を取り出す
                String word =
                    KJ_SuffixArray.GetWord(this.dict_fs, this.array_reader, index);

                // 取り出した語は検索条件にマッチするか?
                if (this.dictword.Compare(searchtype, search_word, word))
                {
                    // マッチするならその語を含むドキュメント全体を取り出す
                    long dict_pointer =
                        KJ_SuffixArray.GetSeekPointer(this.array_reader, index);
                    DocumentData docdata =
                        KJ_yaml.GetBlock(this.dict_fs, dict_pointer);

                    // 既出でないならresultに追加
                    if (!result.IsExist(docdata))
                    {
                        // 絞込みのフィルタ
                        if (this.dictFilter(docdata))
                        {
                            result.documents.Add(docdata);    // 戻り値として追加
                        }
                        else
                        {
                            // フィルタにマッチしないなら返さない
                            cnt--;   // adhocだが、先に1減じておく
                        }
                    }
                    else
                    {
                        // 既出ならcntしない
                        cnt--;   // adhocだが、先に1減じておく
                    }
                }
                else
                {
                    break; //   一致しなければ終了
                }
                index++;   // suffix arrayの次へ
                if (index > array_index_max)
                {
                    break;
                }

                // 検索語の数をカウント
                cnt++;

                if (cnt > 100)
                {
                    result.return_code = 1; // 100個を越えたら中断
                    break;
                }
            }

            // 返すべき値がなければ戻り値を -1に
            if (cnt == 0)
            {
                result.return_code = -1;
            }

            // 検索結果を返す
            return(result);
        }
示例#19
0
        //--------------------------------------------------------------------
        // 語の変換   (語の分解あり)
        //   語分解で翻訳済み末尾がずれることがあるのでWordTableを返す
        //           ABCDEF という語に対し、
        //              ABCDE + F
        //              ABCD  + EF
        //              ABC   + DEF
        //               :       :
        //   と調べていき、最小コストの訳語がとれる分割を採用する
        //
        static public WordChain  WordPartProc(WordTable wt)
        {
            SearchResult sResult;
            String       str = wt.word;


            if (wt == null)
            {
                return(null);
            }
            if (wt.word != null && wt.word.Length == 1)    // 1文字検索はしない
            {
                return(null);
            }

            if (wt.IsTranslated() || wt.IsDigit())
            {
                return(null); // 翻訳済みまたは 数字なら 何もしない
            }

            #if DEBUG_LOG
            KJ_Analyzer.WriteDebugLog("WordPartProc:" + wt.word);
            #endif


            // 再起に備え,まず完全一致で検索
            sResult = KJ_dict.SearchFull(str);
            if (sResult != null)
            {
                wt.SetResult(sResult); // 全体でmatch
                WordChain wc = new WordChain(wt);
                return(wc);
            }

            // 部分語の2文字は分割しない
            if (wt.word != null &&
                wt.word.Length == 2 &&
                wt.divided != Divided.Non)
            {
                return(null);
            }

            // 3文字の「ハングルまたは漢字」なら特別チェック
            if (wt.word != null && wt.word.Length == 3 &&
                wt.divided != Divided.Non &&  // 部分語の3文字語は除外
                (CodeCheck.IsHangul(wt.word) ||
                 CodeCheck.IsKanji(wt.word))
                )
            {
                WordChain wc3 = Check3Chars(wt);
                if (wc3 != null)
                {
                    return(wc3);
                }
            }

//            int target_len=2;   // 2005.09.03 やっぱり1文字まで切らないとだめだ
            int target_len = 1;
            int str_len    = str.Length;

            int       minimumCost      = 9999;
            WordChain minimumCostChain = null;

            // 前から1文字ずつ落としつつ,検索。

            while (true)
            {
                int start = str_len - target_len;
//                if( start <= 1 ){  // 2005.09.03
                if (start <= 0)
                {
                    break;
                }
                // 文字列を分割する
                // str --> str2 + str3
                //       String str2 = str.Remove   (start,  target_len );
                //       String str3 = str.Substring(start,  target_len );
                // 前から分割に変えた(2005.08)
                String str2 = str.Remove(target_len, start);
                String str3 = str.Substring(target_len, start);  //あとできれいに

                // 前と後ろを、それぞれ検索
                WordChain wc2 = DividedWordSearch(str2);
                WordChain wc3 = DividedWordSearch(str3);

                #if DEBUG_LOG
                KJ_Analyzer.WriteDebugLog("str2/str3:" + str2 + "/" + str3);
                #endif

                WordTable wt2, wt3;
                if (wc2 == null)
                {
                    wt2 = new WordTable(str2);
                    wc2 = new WordChain(wt2);
                }
                if (wc3 == null)
                {
                    wt3 = new WordTable(str3);
                    wc3 = new WordChain(wt3);
                }

                // 分割情報設定
                if (wt.divided == Divided.Non)
                {
                    wc2.Head.divided = Divided.Lead;
                    wc3.Head.divided = Divided.Trail;
                }
                if (wt.divided == Divided.Lead)
                {
                    wc2.Head.divided = Divided.Lead;
                    wc3.Head.divided = Divided.Middle;
                }
                if (wt.divided == Divided.Middle)
                {
                    wc2.Head.divided = Divided.Middle;
                    wc3.Head.divided = Divided.Middle;
                }
                if (wt.divided == Divided.Trail)
                {
                    wc2.Head.divided = Divided.Middle;
                    wc3.Head.divided = Divided.Trail;
                }

                // wc2とwc3をつなぐ
                wc2.Add(wc3);

                //  wc2---wc3 のコストを計算
                int divChainCost = wc2.GetChainCost();
                if (minimumCost >= divChainCost)
                {
                    minimumCostChain = wc2;
                    minimumCost      = divChainCost;    //最小コストの更新
                }

                #if DEBUG_LOG
                KJ_Analyzer.WriteDebugLog("wc2:" + wc2.Head.word + "," + wc2.Head.Cost);
                KJ_Analyzer.WriteDebugLog("wc3:" + wc3.Head.word + "," + wc3.Head.Cost);
                KJ_Analyzer.WriteDebugLog("divChainCost:" + divChainCost);
                #endif


                target_len++;
            } // end of while


            // Chain中のwordが全て翻訳できていない
            if (minimumCostChain == null ||
                (minimumCostChain != null && !minimumCostChain.IsTranslated()))
            {
                return(null);
            }

            // 翻訳できていない部分chainを再起実行
            WordTable subT = minimumCostChain.Head;
            while (subT != null)
            {
                if (!subT.IsTranslated())
                {
                    WordChain subWc = WordPartProc(subT);
                    if (subWc != null)
                    {
                        WordTable wNext = subT.next;
                        minimumCostChain.Swap(subT, subWc);
                        subT = wNext;
                        continue;
                    }
                }
                subT = subT.next;
            }

            return(minimumCostChain);
        }
示例#20
0
        //-------------------------------------------------------
        // 語のchainを先頭から舐め、助詞(Postpositional Particle)を分解する。
        static private WordTable ScanPPKr(WordChain wChain, WordTable wTable)
        {
            bool inputIsHangul = KJ_dict.inputIsHangul;

            // 語を舐め、助詞を分解する。

            if (wTable.charCategory != CharCategory.Hangul &&
                wTable.charCategory != CharCategory.LetterMix)
            {
                // ハングルでないなら、または英字+ハングルでないなら何もしない。
                return(wTable);
            }


            // 完全一致の助詞なら情報をセットし、終了
            string pp_trans = CheckHangulPP_Full(wTable);

            if (pp_trans != "")
            {
                wTable.transWord   = pp_trans;
                wTable.posCategory = PosCategory.PP;
                if (wTable.word.Length > 2)
                {
                    wTable.Cost = 0;
                }
                else if (wTable.word.Length == 2)
                {
                    wTable.Cost = 3;
                }
                else
                {
                    wTable.Cost = 5;
                }

                return(wTable);
            }

            // wordTableが辞書に完全一致で存在するか調べる。
            bool isExist = KJ_dict.CheckFull(wTable.word);

            if (isExist)
            {
                // 完全一致した語は判定せず、なにもしない。
                return(wTable);
            }


            // 助詞の分解を試みる
            WordChain resultChain = DivideHangulPP(wTable);

            if (resultChain == null)
            {
                // 助詞はついてなかった。なにもしない。
                return(wTable);
            }

            // resultChainは 語+助詞のチェーン。WordTと入れ替える
            wChain.Swap(wTable, resultChain);

            // 助詞で始まる熟語でないかチェック
            WordTable idiomwt = Idiom.Search(wChain, resultChain.Tail);

            // resultChainの先頭は未処理。
            // いったんcurrentをresultChainの先頭に戻す
            //     위원회를 --->    위원회          +   를
            //      wTable        resultChain.Head     [を]:翻訳済み
            wTable = resultChain.Head;


            return(wTable);
        }
示例#21
0
        // コンストラクタ
        public KJ_form()
        {
            msg = new KJ_Message();


            // 設定情報
            Setting = new KJ_form_Setting();

            // もし存在するならば設定をファイルから読み込む

            if (System.IO.File.Exists(Setting.SettingFileName) == true)
            {
                // 設定ファイルあり

                //XmlSerializerオブジェクトの作成
                XmlSerializer serializer2 =
                    new XmlSerializer(typeof(KJ_form_Setting));
                //ファイルを開く
                FileStream fs2 = new FileStream(Setting.SettingFileName,
                                                FileMode.Open,
                                                FileAccess.Read);
                //XMLファイルから読み込み、逆シリアル化する
                Setting = (KJ_form_Setting)serializer2.Deserialize(fs2);

                // もし設定ファイルにカルチャ情報があれば,KJ_Messageに設定する
                //  (ふるい設定ファイルにはカルチャ情報はない)
                if (Setting.CultureName != null)
                {
                    KJ_Message.SetCultureName(Setting.CultureName);
                }
                else
                {
                    // 無いならOSのデフォルトを設定
                    Setting.CultureName = KJ_Message.GetCultureName();
                }

                //閉じる
                fs2.Close();
            }
            else
            {
                // 設定ファイルがない時のdefault
                Setting.withPronunciation = false;
                Setting.PronunciationType = 1;
                Setting.TargetLang        = 1;
                Setting.CultureName       = KJ_Message.GetCultureName();
                Setting.debugInfo         = false;
                Setting.except9999        = false;
                Setting.except8888        = true;
                Setting.ClipboardView     = false;
#if  !EDICT
                Setting.CompactForm = false;
#else
                Setting.CompactForm = true;
#endif
            }


            // フォントを設定する
            FontSetting();


            // FormのInitialize
            InitializeComponent();


            //コンパクトモード切替
            if (this.Setting.CompactForm)
            {
                this.ChangeCompactForm();
            }
            else
            {
                // Fromサイズを覚えていたらSettingから戻す
                if (Setting.FormSize.Width != 0)
                {
                    this.ClientSize = Setting.FormSize;
                }
            }

            // フィルタのデリゲート生成
            this.filter = new FilterDelegate(this.defaultFilter);

            // 韓国語環境テストが簡単にできるように関数化
            this.cultureName = KJ_Message.GetCultureName();
            //  "ja-JP"  or ...

            //  Open dictionary
      #if  EDICT
            //     KJ_dict.DictOpen("edict.yml");
            if (this.Setting.TargetLang == 1)
            {
                KJ_dict.DictOpen("edict.yml");
            }
            if (this.Setting.TargetLang == 2)
            {
                KJ_dict.DictOpen("edict.yml", "edict.yml.en");
            }
            if (this.Setting.TargetLang == 3)
            {
                KJ_dict.DictOpen("edict.yml", "edict.yml.jp");
            }
      #else
            if (this.Setting.TargetLang == 1)
            {
                KJ_dict.DictOpen("KJ_dict.yml");
            }
            if (this.Setting.TargetLang == 2)
            {
                KJ_dict.DictOpen("KJ_dict.yml", "KJ_dict.yml.kr");
            }
            if (this.Setting.TargetLang == 3)
            {
                KJ_dict.DictOpen("KJ_dict.yml", "KJ_dict.yml.jp");
            }
      #endif

            KJ_dict.SetFilter(this.filter);


            // for Clipboard
            NextHandle = SetClipboardViewer(this.Handle);
        } // end of KJ_form
示例#22
0
        //--------------------------------------------------------------
        // startwtで始まる熟語を最長一致でチェックする
        //
        // (before)
        //  -----wt1-----wt2-----wt3-----wt4-----wt5-----wt6-----
        //               ↑              ↑
        //              startwt         matched
        //
        // (after)
        //  -----wt1-----idiomwt-----wt5-----wt6-----
        //
        //  チェーン中の熟語を成すテーブルは1つにまとめる。
        //    (正確には熟語のテーブルを挿入し、個々の語のテーブルは削除)
        //
        static public WordTable  Search(WordChain wc, WordTable startwt)
        {
            //熟語は語単位より優先
            //   if(startwt.IsTranslated()){
            //       return  null; // 翻訳済みの語は触らない
            //   }

            bool isExist;                // 辞書中にチェック対象の語(熟語)が存在するか?

            WordTable    idiomwt = null; // 熟語テーブル
            SearchResult sResult;
            string       word = startwt.word;

            // startwtが翻訳済みで助詞なら何もしない
            // 暫定的 2005.08.26
            //    if(startwt.IsTranslated() && startwt.pos == PosCategory.PP ){
            //        return(null);   // not found
            //  }

            // 前方一致で該当なしなら
            // この語で始まる熟語は辞書にない
            isExist = KJ_dict.CheckForward(word);
            if (!isExist)
            {
                return(null);   // not found
            }

            // 前方一致でmatchしたので先読みして熟語チェック
            String    word2     = "";
            string    next      = "";
            WordTable nextTable = startwt.next;
            WordTable matched   = startwt;

            // 次の語以降を足しながらチェック
            while (nextTable != null)
            {
                if (nextTable == null || nextTable.word == "")
                {
                    break;  // 次の語なしなら抜ける
                }
                next = nextTable.word;
                char ch = next[0];
                if (Char.IsSeparator(ch))
                {
                    next = " ";
                }

                if (next == " ")
                {
                    word      = word + next;
                    nextTable = nextTable.next; // 次の語へ
                    continue;                   // 空白付加だけでは再検索しない
                }

                word2 = word + next;
                //次の語を足して前方一致チェック
                isExist = KJ_dict.CheckForward(word2);
                if (!isExist)
                {
                    // nextを足したら,一致しない。→ これ以上先を見る必要なし


                    break;
                }

                // 一致した部分まででで完全一致検索
                sResult = KJ_dict.SearchFull(word2);
                if (sResult != null)
                {
                    // string trimword = word2;
                    // trimword = trimword.Replace(" ", ""); // 空白削除
                    if (IsValidIdiom(sResult))  // 長さ4以上でないと採用しない
                    // 熟語が見つかった
                    {
                        idiomwt = new WordTable(word2);
                        idiomwt.charCategory = startwt.charCategory;
                        // 先頭文字種で (混ざっている可能性あるが)
                        idiomwt.posCategory = PosCategory.Idiom;
                        idiomwt.SetResult(sResult);
                        matched = nextTable; // 完全一致した最後のテーブル
                    }
                }

                // さらに次の語へ
                word      = word2;          // nextを足したものを元とする。
                nextTable = nextTable.next; // 次の語へ
            } // while loop


            if (startwt.word == word)
            {
                // 熟語でなく単なる入力語の完全一致の時は返さない
                return(null);
            }

            if (idiomwt != null)
            {
                // 熟語が見つかっている

                wc.Insert(matched, idiomwt);

                // startwtからmatchedまでは消していい。
                WordTable delwt = startwt;
                while (true)
                {
                    wc.Delete(delwt);
                    if (delwt == matched)
                    {
                        break;
                    }
                    delwt = delwt.next;
                }

                // 熟語のテーブルを返す
                return(idiomwt);
            }

            // 熟語なし
            return(null);
        }
示例#23
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を返す。
        }