Ejemplo n.º 1
0
        private void AddMnemonicsHtml(string word, string data)
        {
            var allItems = _entities.MnemonicsDictionaryHtmls.EnumerateInChunksOf(100);

            var sql = from w in allItems
                      where w.Word.Equals(word)
                      select w;

            if (sql.Count() == 0)
            {
                var mh = new MnemonicsDictionaryHtml()
                {
                    Word = word,
                    Html = data
                };
                _entities.AddToMnemonicsDictionaryHtmls(mh);
                _entities.SaveChanges();
            }
            else
            {
                sql.First().Html = data;
                _entities.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        private void ParseMnemonicDictionary(string word)
        {
            FireLogMessage("Parsing Mnemonics for: " + word);

            GreWord greWord            = GetGreWord(word);
            MnemonicsDictionaryHtml gd = (_entities.MnemonicsDictionaryHtmls.Where(w => w.Word == word)).FirstOrDefault();

            if (gd == null)
            {
                return;
            }

            string text        = gd.Html;
            Regex  regexWordUl = new Regex("<ul class='wordnet'>(.+?)</ul>", RegexOptions.Singleline);
            Regex  regexWordLi = new Regex("<li>(.+?)</li>", RegexOptions.Singleline);


            Regex regexImage = new Regex("<div class=\"floatright\">.+?<img src=\"(.+?)\".+?</div>", RegexOptions.Singleline);
            Regex regexTag   = new Regex("<div class=\"floatleft\">(.+?)</div>", RegexOptions.Singleline);

            Match meaningMatch = regexWordUl.Match(text);

            if (meaningMatch.Success)
            {
                MatchCollection meanings = regexWordLi.Matches(meaningMatch.Value);

                foreach (Match m in meanings)
                {
                    string tag = "";
                    string img = "";

                    string          def = CleanText(m.Groups[1].Value);
                    MatchCollection mci = regexImage.Matches(def);
                    foreach (Match mi in mci)
                    {
                        Match mt = regexTag.Match(def);

                        img = mi.Groups[1].Value;
                        tag = mt.Groups[1].Value.Replace("\r\n", "");

                        def = regexImage.Replace(def, "");
                        def = regexTag.Replace(def, "");
                        def = def.Replace("<div class='clear'></div>", "");
                    }

                    WordDefinition wordDefinition = new WordDefinition {
                        Definition = def, Image = img, Tag = tag, GreWord = greWord,
                    };
                    _entities.AddToWordDefinitions(wordDefinition);
                    _entities.SaveChanges();
                }
            }


            Regex regexSelectedMnemonicDiv = new Regex("<div class='mnemonics'>(.+?)</div>", RegexOptions.Singleline | RegexOptions.IgnoreCase);
            Regex regexSelectedMnemonicLi  = new Regex(@"<li><p>(.+?)</p><p>\s+added by.+?</li>", RegexOptions.Singleline | RegexOptions.IgnoreCase);
            Match selectedMnemonic         = regexSelectedMnemonicDiv.Match(text);

            if (selectedMnemonic.Success)
            {
                MatchCollection selectedMnemonics = regexSelectedMnemonicLi.Matches(selectedMnemonic.Groups[1].Value);

                foreach (Match m in selectedMnemonics)
                {
                    //listSelectedMnemonics.Items.Add(clarify(m.Groups[1].Value));
                    string           def       = CleanText(m.Groups[1].Value);
                    FeaturedMnemonic mnemonics = new FeaturedMnemonic
                    {
                        Mnemonic = def,
                        GreWord  = greWord
                    };
                    _entities.AddToFeaturedMnemonics(mnemonics);
                    _entities.SaveChanges();
                }
            }

            Regex regexAllMnemonicDiv = new Regex("<div class='mnemonic'>(.+?)</div>", RegexOptions.Singleline | RegexOptions.IgnoreCase);
            Regex regexAllMnemonicLi  = new Regex(@"<li><p>(.+?)</p><p>\s+added by.+?<p>Was this mnemonic useful \?&nbsp; &nbsp;\s+<strong id='hallo\d+'>(.+?)</strong>.+?<strong id='hallo\d+'>&nbsp;(.+?)</strong>", RegexOptions.Singleline | RegexOptions.IgnoreCase);
            Match allMnemonic         = regexAllMnemonicDiv.Match(text);

            if (allMnemonic.Success)
            {
                MatchCollection meanings = regexAllMnemonicLi.Matches(allMnemonic.Groups[1].Value);

                foreach (Match m in meanings)
                {
                    string        def       = CleanText(m.Groups[1].Value);
                    BasicMnemonic mnemonics = new BasicMnemonic()
                    {
                        Mnemonic   = def,
                        Helpful    = m.Groups[2].Value,
                        NotHelpful = m.Groups[3].Value
                    };
                    mnemonics.GreWord = greWord;
                    _entities.AddToBasicMnemonics(mnemonics);
                    _entities.SaveChanges();
                }
            }
        }