/// <summary> /// Loads the special expressions dictionary. /// </summary> private void LoadSpecialExpressions() { _specialExpressions = new Dictionary <string, SpecialExpression>(); foreach (string line in File.ReadAllLines(PathHelper.SpecialReadingsPath)) { if (string.IsNullOrWhiteSpace(line) || line.First() == ';') { continue; } string[] split = line.Split(SeparatorHelper.FileFieldSeparator); string kanjiReading = split[0]; string kanaReading = split[1]; VocabEntry v = new VocabEntry(kanjiReading, kanaReading); // Read the solution if it is explicitly written. Compute it otherwise. FuriganaSolution solution = split.Count() == 3 ? FuriganaSolution.Parse(split[2], v) : new FuriganaSolution(v, new FuriganaPart(kanaReading, 0, kanjiReading.Length - 1)); // Add the special reading or special expression. SpecialReading specialReading = new SpecialReading(kanaReading, solution); if (_specialExpressions.ContainsKey(kanjiReading)) { _specialExpressions[kanjiReading].Readings.Add(specialReading); } else { _specialExpressions.Add(kanjiReading, new SpecialExpression(kanjiReading, specialReading)); } } }
/// <summary> /// Loads the furigana override list. /// </summary> private void LoadOverrideList() { _overrideList = new Dictionary <string, FuriganaSolution>(); foreach (string line in File.ReadAllLines(PathHelper.OverrideFuriganaPath)) { if (string.IsNullOrWhiteSpace(line) || line.First() == ';') { continue; } string[] split = line.Split(SeparatorHelper.FileFieldSeparator); _overrideList.Add(new VocabEntry(split[0], split[1]).ToString(), FuriganaSolution.Parse(split[2], null)); } }
public void Test_Furigana(string kanjiReading, string kanaReading, string expectedFurigana) { VocabEntry v = new VocabEntry(kanjiReading, kanaReading); FuriganaBusiness business = new FuriganaBusiness(DictionaryFile.Jmdict); FuriganaSolutionSet result = business.Execute(v); if (result.GetSingleSolution() == null) { Assert.Fail(); } else { Assert.AreEqual(FuriganaSolution.Parse(expectedFurigana, v), result.GetSingleSolution()); } }