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());
                    }
                }
            }
        }
Beispiel #2
0
        public void Populate(List <Word> words)
        {
            Contract.Assert(wordsByName.Count == 0);
            foreach (Word word in words)
            {
                WordInfo wordInfo = WordInfo.Create(this, word);
                wordsByName.Add(word.Name, wordInfo);

                tagIndex.Add(word.Name, wordInfo.Tags);
                translationIndex.Add(word.Name, wordInfo.Translations);
            }

            UpdateTranslations(translationIndex.GetAttributes());

            Modified = false;

            UpdateStats();

            OnContentsChanged();
        }
Beispiel #3
0
        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);
            }
        }
Beispiel #4
0
        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);
            }
        }
Beispiel #5
0
        public static WordInfo Create(WordList wordList, Word word)
        {
            WordInfo res = new WordInfo();

            res.WordList = wordList;
            res.Word = word;

            res.Update();

            return res;
        }