예제 #1
0
 /// <summary>
 /// Create a new GreWordSynonym object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="word">Initial value of the Word property.</param>
 /// <param name="serial">Initial value of the Serial property.</param>
 /// <param name="partsOfSpeech">Initial value of the PartsOfSpeech property.</param>
 public static GreWordSynonym CreateGreWordSynonym(global::System.Int64 id, global::System.String word, global::System.String serial, global::System.String partsOfSpeech)
 {
     GreWordSynonym greWordSynonym = new GreWordSynonym();
     greWordSynonym.Id = id;
     greWordSynonym.Word = word;
     greWordSynonym.Serial = serial;
     greWordSynonym.PartsOfSpeech = partsOfSpeech;
     return greWordSynonym;
 }
예제 #2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the GreWordSynonyms EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToGreWordSynonyms(GreWordSynonym greWordSynonym)
 {
     base.AddObject("GreWordSynonyms", greWordSynonym);
 }
예제 #3
0
        private void ParseWordnetSynonyms(string word)
        {
            FireLogMessage("WordnetSynonyms Parsing: " + word);

            var html = (from w in _entities.SynonymsNetHtmls where w.Word == word select w).FirstOrDefault();
            var greWord = GetGreWord(word);

            try
            {

                Regex regexObj = new Regex(@"<br><b>([0-9]+)\.&nbsp;<span style=""color:#000055;font-size:10px"">\((.+?)\)</span></b>&nbsp;<b>(.+?)</b>\s*<br><span style=""color:#666666;""><i>(.+?)</i></span>\s*<br>(<b>Synonyms:&nbsp;</b>(.+?)<br>)?(<b>Antonyms:&nbsp;</b>(.+?)\s*<br>)?", RegexOptions.Singleline | RegexOptions.IgnoreCase);

                MatchCollection mc = regexObj.Matches(html.Html);
                foreach (Match match in mc)
                {
                    string similar = match.Groups[3].Value;
                    var defs = (from w in _entities.GreWordSynonyms
                                where w.GreWord.Word == word && w.SimilarWords == similar
                                select w).FirstOrDefault();
                    if (defs == null)
                    {
                        defs = new GreWordSynonym()
                        {
                            GreWord = greWord,
                            Serial = match.Groups[1].Value,
                            PartsOfSpeech = match.Groups[2].Value,
                            SimilarWords = match.Groups[3].Value,
                            Definitions = match.Groups[4].Value,
                            Synonyms = match.Groups[6].Value,
                            Antonyms = match.Groups[8].Value
                        };

                        defs.Definitions = Regex.Replace(Regex.Replace(defs.Definitions, "<a.+?>(.+?)</a>", "$1"), "<span.+?>(.+?)</span>", "$1");
                        defs.Synonyms = Regex.Replace(Regex.Replace(defs.Synonyms, "<a.+?>(.+?)</a>", "$1"), "<span.+?>(.+?)</span>", "$1").Replace("\t", "").Replace("\r", "").Replace("\n", "");
                        defs.Antonyms = Regex.Replace(Regex.Replace(defs.Antonyms, "<a.+?>(.+?)</a>", "$1"), "<span.+?>(.+?)</span>", "$1");

                        _entities.AddToGreWordSynonyms(defs);
                        _entities.SaveChanges();
                    }
                    else
                    {
                        defs.Serial = match.Groups[1].Value;
                        defs.PartsOfSpeech = match.Groups[2].Value;
                        defs.SimilarWords = match.Groups[3].Value;
                        defs.Definitions = match.Groups[4].Value;
                        defs.Synonyms = match.Groups[6].Value;
                        defs.Antonyms = match.Groups[8].Value;

                        defs.Definitions = Regex.Replace(Regex.Replace(defs.Definitions, "<a.+?>(.+?)</a>", "$1"), "<span.+?>(.+?)</span>", "$1");
                        defs.Synonyms = Regex.Replace(Regex.Replace(defs.Synonyms, "<a.+?>(.+?)</a>", "$1"), "<span.+?>(.+?)</span>", "$1");
                        defs.Antonyms = Regex.Replace(Regex.Replace(defs.Antonyms, "<a.+?>(.+?)</a>", "$1"), "<span.+?>(.+?)</span>", "$1");
                        _entities.SaveChanges();
                    }
                }
            }
            catch (ArgumentException ex)
            {
                // Syntax error in the regular expression
            }
        }