void AnnotateMappingAndConvertToXhtml(ContentsMapping chapterMapping) { var xhtmlParagraphs = new List <XElement>(); foreach (var plainTextLine in chapterMapping.PlainTextContent) { foreach (var sentence in _sentenceBreaker.BreakToSentences(plainTextLine)) { IList <string> lines; using (var reader = _mecabBackend.ParseText(sentence)) { lines = _reader.ReadResponse(reader); } var words = new List <WordInfo>(); foreach (var line in lines) { var word = _parser.ParseWord(line); word.Translation = _dicReader.Lookup(word.RootForm); words.Add(word); } xhtmlParagraphs.Add(_xhtmlMaker.MakeParagraph(words.Select(w => _xhtmlMaker.MakeWord(w)))); xhtmlParagraphs.Add(_xhtmlMaker.MakeContextHelpParagraph(words.DistinctBy(w => w.Text))); words.Clear(); } } chapterMapping.XhtmlContent = _xhtmlMaker.MakeRootNode(xhtmlParagraphs); }
public void MakeContextHelpParagraphShouldHasTextWithTranslationOnly() { AssertEqualNodes( "<p class=\"jp-contexthelp\" xmlns=\"http://www.w3.org/1999/xhtml\">見世物 [ミセモノ] - Unreal<br />見世物 [ミセモノ] - Unreal<br /></p>", _maker.MakeContextHelpParagraph(new List <WordInfo> { _kanjiWithReading, _kanjiWithReading, _kanjiWithoutReading })); }