/// <summary> /// 載入使用者自訂詞庫。 /// </summary> private void LoadPhraseFiles() { string phraseListFileName = Path.Combine(AppGlobals.TempPath, Constant.Files.CvtInputPhraseListFileName); if (!File.Exists(phraseListFileName)) { return; } string[] phraseFiles = File.ReadAllLines(phraseListFileName, Encoding.UTF8); string fname; ZhuyinPhraseTable phtbl = ZhuyinPhraseTable.GetInstance(); foreach (string s in phraseFiles) { fname = s.Trim().ToLower(); if (String.IsNullOrEmpty(fname)) { continue; } if (!File.Exists(fname)) // 檔案如果不存在,就不處理 { continue; } phtbl.Load(fname); } }
public void Should_CustomPhrase_Work() { // 手動加一個片語,以便觀察是否查詢字根時是否有用到片語資料。 ZhuyinPhraseTable.GetInstance().AddPhrase("什麼 ㄕㄣˊ ㄇㄚˇ"); var converter = new ZhuyinReverseConverter(new ZhuyinReverseConversionProvider()); string aChineseText = "什麼"; string[] expected = { "ㄕ ㄣˊ", "ㄇ ㄚˇ" }; string[] actual = converter.GetZhuyinWithPhraseTable(aChineseText); CollectionAssert.AreEqual(expected, actual); }
public void Should_CustomPhrase_AllowSingleWord() { // 手動加一個片語,以便觀察是否查詢字根時是否有用到片語資料。 var phraseTable = ZhuyinPhraseTable.GetInstance(); phraseTable.AddPhrase("什 ㄕㄜˊ"); phraseTable.AddPhrase("什麼 ㄕㄣˊ ㄇㄚˇ"); var converter = new ZhuyinReverseConverter(skipLoadingDictionary: true); string aChineseText = "什麼"; string[] expected = { "ㄕ ㄣˊ", "ㄇ ㄚˇ" }; string[] actual = converter.GetZhuyinWithPhraseTable(aChineseText); CollectionAssert.AreEqual(expected, actual); }