Exemplo n.º 1
0
 /// <summary>
 /// Create a new FeaturedMnemonic object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="word">Initial value of the Word property.</param>
 /// <param name="mnemonic">Initial value of the Mnemonic property.</param>
 public static FeaturedMnemonic CreateFeaturedMnemonic(global::System.Int64 id, global::System.String word, global::System.String mnemonic)
 {
     FeaturedMnemonic featuredMnemonic = new FeaturedMnemonic();
     featuredMnemonic.Id = id;
     featuredMnemonic.Word = word;
     featuredMnemonic.Mnemonic = mnemonic;
     return featuredMnemonic;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the FeaturedMnemonics EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToFeaturedMnemonics(FeaturedMnemonic featuredMnemonic)
 {
     base.AddObject("FeaturedMnemonics", featuredMnemonic);
 }
Exemplo n.º 3
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();
                }
            }
        }