public void Test() { ArticleParser parser = new ArticleParser(); WordArticle article = parser.Parse("a", "b"); Assert.That(article.FormGroups.Count, Is.EqualTo(1)); Assert.That(article.FormGroups[0].Forms, Is.EquivalentTo(new string[] {"a"})); Assert.That(article.FormGroups[0].TranslationGroups.Count, Is.EqualTo(1)); Assert.That(article.FormGroups[0].TranslationGroups[0].Translations, Is.EquivalentTo(new string[] {"b"})); Assert.That(article.Format(), Is.EqualTo("#a\nb\n")); }
private void AppendWord(FlowDocument document, WordInfo word) { ArticleParser parser = new ArticleParser(); WordArticle article = parser.Parse(word.Word.Name, word.Word.Description); Paragraph paragraph = FlowDocumentStyles.CreateParagraph(); document.Blocks.Add(paragraph); IEnumerable<WordFormGroup> formGroups = article.FormGroups.Where(fg => fg.TranslationGroups.SelectMany(tg => tg.Translations).Contains(Translation)); foreach (WordFormGroup formGroup in formGroups) { bool firstForm = true; foreach (string form in formGroup.Forms) { Hyperlink link = new Hyperlink(); link.Command = Commands.NavigateTo; link.CommandParameter = NavigationTarget.ToWord(word.Word.Name); paragraph.Inlines.Add(link); Run run = new Run(form); link.Inlines.Add(run); if (firstForm) { FlowDocumentStyles.FormatWord(run); firstForm = false; } else { FlowDocumentStyles.FormatWordForm(run); } paragraph.Inlines.Add(new LineBreak()); } foreach (WordTranslationGroup translationGroup in formGroup.TranslationGroups.Where(tg => tg.Translations.Contains(Translation))) { foreach (string translation in translationGroup.Translations) { Run run = new Run("\u2022 " + translation); paragraph.Inlines.Add(run); FlowDocumentStyles.FormatTranslation(run); paragraph.Inlines.Add(new LineBreak()); } foreach (string example in translationGroup.Examples) { Run run = new Run("Example: " + example); paragraph.Inlines.Add(run); FlowDocumentStyles.FormatExample(run); paragraph.Inlines.Add(new LineBreak()); } } } }
public void FilterTranslationEvents() { ArticleParser parser = new ArticleParser(); WordArticle article = parser.Parse(name, description); HashSet<string> translations = new HashSet<string>(article.GetAllTranslations()); for (int i = 0; i < Events.Count;) { WordEvent wordEvent = events[i]; if (wordEvent.Translation == null || translations.Contains(wordEvent.Translation)) { i++; } else { events.RemoveAt(i); } } }
public void FilterTranslationEvents() { ArticleParser parser = new ArticleParser(); WordArticle article = parser.Parse(name, description); HashSet <string> translations = new HashSet <string>(article.GetAllTranslations()); for (int i = 0; i < Events.Count;) { WordEvent wordEvent = events[i]; if (wordEvent.Translation == null || translations.Contains(wordEvent.Translation)) { i++; } else { events.RemoveAt(i); } } }
private static void ParseWord(WordInfo info) { ArticleParser parser = new ArticleParser(); WordArticle article = parser.Parse(info.Word.Name, info.Word.Description); List <string> forms = article.FormGroups.SelectMany(g => g.Forms).Distinct().ToList(); info.Forms.Clear(); foreach (string form in forms) { info.Forms.Add(new WordForm(info, form)); } List <string> translations = article.FormGroups.SelectMany(g => g.TranslationGroups).SelectMany(tg => tg.Translations).Distinct().ToList(); info.Translations.Clear(); foreach (string translation in translations) { info.Translations.Add(translation); } }
private static void ParseWord(WordInfo info) { ArticleParser parser = new ArticleParser(); WordArticle article = parser.Parse(info.Word.Name, info.Word.Description); List<string> forms = article.FormGroups.SelectMany(g => g.Forms).Distinct().ToList(); info.Forms.Clear(); foreach (string form in forms) { info.Forms.Add(new WordForm(info, form)); } List<string> translations = article.FormGroups.SelectMany(g => g.TranslationGroups).SelectMany(tg => tg.Translations).Distinct().ToList(); info.Translations.Clear(); foreach (string translation in translations) { info.Translations.Add(translation); } }