private FuriganaSolutionSet Process(VocabEntry v) { FuriganaSolutionSet solutionSet = new FuriganaSolutionSet(v); int priority = Solvers.First().Priority; foreach (FuriganaSolver solver in Solvers) { if (solver.Priority < priority) { if (solutionSet.Any()) { // Priority goes down and we already have solutions. // Stop solving. break; } // No solutions yet. Continue with the next level of priority. priority = solver.Priority; } // Add all solutions if they are correct and unique. solutionSet.SafeAdd(solver.Solve(ResourceSet, v)); } return(solutionSet); }
public FuriganaSolutionSet Execute(VocabEntry v) { if (v.KanjiReading == null || v.KanaReading == null || string.IsNullOrWhiteSpace(v.KanjiReading)) { // Cannot solve when we do not have a kanji or kana reading. return(new FuriganaSolutionSet(v)); } FuriganaSolutionSet result = Process(v); if (!result.Any() && v.KanjiReading.StartsWith("御")) { // When a word starts with 御 (honorific, often used), try to override the // result by replacing it with an お or a ご. It will sometimes bring a // result where the kanji form wouldn't. result = Process(new VocabEntry(v.KanaReading, "お" + v.KanjiReading.Substring(1))); if (!result.Any()) { result = Process(new VocabEntry(v.KanaReading, "ご" + v.KanjiReading.Substring(1))); } result.Vocab = v; } return(result); }
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()); } }