public IEnumerable <AutoGlosserNote> Gloss(string inputText) { var words = parser.BreakIntoWords(inputText) .ToList(); var glosses = new List <AutoGlosserNote>(); for (int i = 0; i < words.Count; i++) { var word = words[i]; var greedySelection = words.Skip(i).Greedy(wordInfos => { var entireExpression = string.Concat(wordInfos.Select(w => w.RawWord)); var l = dictLookup.Lookup(entireExpression); if (l == null) { return(false); } var entireReading = kana.ToHiragana(string.Concat(wordInfos.Select(w => w.Reading))); if (l.Any(e => e.ReadingEntries.Any(r => entireReading == kana.ToHiragana(r.Reading)))) { return(true); } return(false); }).ToList(); var lookup = dictLookup.Lookup(word.DictionaryForm ?? word.RawWord)?.ToList(); if (word.RawWord.All(c => ".!??!⁉、…。.".IndexOf(c) != -1)) { // skip punctuation continue; } if (greedySelection.Count > 1) { var greedyLookup = dictLookup.Lookup(string.Concat(greedySelection.Select(w => w.RawWord))).Materialize(); glosses.Add(new AutoGlosserNote( string.Join(" ", greedySelection.Select(w => w.RawWord)), OrderSenses(FilterOutInapplicableSenses(greedyLookup, greedySelection)).Select(FormatSense))); i += greedySelection.Count - 1; // -1 because iteration will result in one extra increase continue; } else if (lookup != null) { glosses.Add(new AutoGlosserNote(word.RawWord, OrderSenses(FilterOutInapplicableSenses(lookup, word)).Select(FormatSense))); } else { glosses.Add(new AutoGlosserNote(word.RawWord, new string[0])); } } return(glosses); }
public void ToHiragana(string input, string expected) { Assert.AreEqual(expected, kana.ToHiragana(input)); }