//------------------------------------------------------------------- // 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()); }
//------------------------------------------------------------------ // 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); }
//------------------------------------------------------------------- // WordChainの各WordTableから翻訳結果を取り出し翻訳後文字列を返す // (ブラウザ用) public String Chain2String_for_Web(WordChain wc) { StringBuilder result; // 出力文字列 result = new StringBuilder(); string translatedText = ""; string originalText = ""; // 先頭にマーカ // 語のchainを先頭から舐め、翻訳結果をresultに順次追加。 WordTable wt = wc.Head; while (wt != null) { // タグの内容のテーブル if (wt.charCategory == CharCategory.HTMLtag) { if (translatedText.Trim() != "") { if (String.Compare(originalText, translatedText) != 0) { // 翻訳データを埋める originalText += ("<font color=blue size=-1>" + translatedText + "</font>"); } else { // NOP // 英文など無変換のものは併記しない } result.Append(originalText); // バッファクリア originalText = ""; translatedText = ""; } // htmlタグのwordをそのまま追加 result.Append(wt.word); // この書き換えは効かない... [2009/09/26 09:56:07] // string noblank = wt.word.Replace("target=\"_blank\"", ""); // result.Append( noblank ); wt = wt.next; continue; } // htmlタグの外 (訳すべきテキスト) // 原文の退避 originalText += wt.word; // 翻訳用前処理 TranslationPreproc(wt); // wtから翻訳済みテキストを取り出す string translated = wt.GetTranslatedText(); // 翻訳できなかったら元文字をそのまま返す if (translated == "") { translated = wt.word; } translatedText += translated; wt = wt.next; } return(result.ToString()); }