private void ParseGooglePhrase(string word) { FireLogMessage("GooglePhrase Parsing " + word); try { string html = (_entities.GoogleDictionaryHtmls.Where(w => w.Word == word).Select(w => w.Html)).FirstOrDefault(); Regex ul = new Regex("<ul class=\"rlt-snt\">(.*?)</ul>", RegexOptions.Singleline); string list = ul.Match(html).Groups[1].Value; Regex li = new Regex("<li>.+?<a.+?>(.+?)</a></b>.+?</div>(.+?)</li>", RegexOptions.Singleline); MatchCollection mc = li.Matches(list); GreWord gw = GetGreWord(word); foreach (Match m in mc) { string en = m.Groups[1].Value; string bn = m.Groups[2].Value; bn = bn.Replace("\n", "").Replace("<b>", "").Replace("</b>", "").Replace(" ", " "); UpdateGooglePhrase(gw, en, bn); } } catch { } }
String getMnemonics(GreWord gw) { var entities = new gredbEntities(); var parser = new ParserHelper(entities); String mnemonics = ""; List <FeaturedMnemonic> mSelected = (from w in entities.FeaturedMnemonics where w.GreWord.Word == gw.Word select w).ToList(); foreach (FeaturedMnemonic ms in mSelected) { mnemonics += "##:" + ms.Mnemonic + ", "; } List <BasicMnemonic> mAll = (from w in entities.BasicMnemonics where w.GreWord.Word == gw.Word select w).ToList(); foreach (BasicMnemonic ms in mAll) { mnemonics += "#" + ms.Helpful + "," + ms.NotHelpful + ":" + ms.Mnemonic + ", "; } mnemonics = Clean(mnemonics, @"\(Tag.+?\)"); mnemonics = Clean(mnemonics); return(mnemonics); }
void UpdateGoogleBengaliWord(GreWord word, string definition) { BengaliDefinition gs = (_entities.BengaliDefinitions.Where(w => w.GreWord.Word == word.Word && w.Bengali == definition)).FirstOrDefault(); if (gs == null) { gs = new BengaliDefinition() { GreWord = word, Bengali = definition }; _entities.AddToBengaliDefinitions(gs); _entities.SaveChanges(); } }
void UpdateGoogleSynonym(GreWord word, string synonym) { GoogleSynonym gs = (_entities.GoogleSynonyms.Where(w => w.GreWord.Word == word.Word && w.Synonym == synonym)).FirstOrDefault(); if (gs == null) { gs = new GoogleSynonym() { GreWord = word, Synonym = synonym }; _entities.AddToGoogleSynonyms(gs); _entities.SaveChanges(); } }
private void InsertAffineWord(GreWord word, GreWord affine, int affinity) { int count = (from o in _entities.GreWordAffinities where o.GreWord.Word == word.Word && o.RelevantWord.Word == affine.Word select o).Count(); if (count == 0) { GreWordAffinity gwa = new GreWordAffinity() { GreWord = word, RelevantWord = affine, Affinity = affinity }; _entities.AddToGreWordAffinities(gwa); } }
void UpdateGooglePhrase(GreWord word, string en, string bn) { var gs = (_entities.GooglePhrases.Where(w => w.GreWord.Word == word.Word && w.EnglishPhrase == en)).FirstOrDefault(); if (gs == null) { gs = new GooglePhrase() { GreWord = word, EnglishPhrase = en, BengaliPhrase = bn, }; _entities.AddToGooglePhrases(gs); _entities.SaveChanges(); } }
String getGoogleSynonym(GreWord gw) { var entities = new gredbEntities(); var parser = new ParserHelper(entities); String synnonym = ""; List <GoogleSynonym> gSyn = (from w in entities.GoogleSynonyms where w.GreWord.Word == gw.Word select w).ToList(); foreach (GoogleSynonym gs in gSyn) { synnonym += gs.Synonym + ", "; } return(synnonym); }
private void ParseGoogleBengali(string word) { FireLogMessage("GoogleBengali for " + word); GreWord greWord = GetGreWord(word); GoogleDictionaryHtml gd = (_entities.GoogleDictionaryHtmls.Where(w => w.Word == word)).FirstOrDefault(); if (gd == null) { return; } string text = gd.Html; Regex regexWord = new Regex(@"<div class=""dct-em"">\s+<span class=""dct-tt"">(.+?)</span>", RegexOptions.Singleline | RegexOptions.IgnoreCase); MatchCollection meanings = regexWord.Matches(text); foreach (string def in from Match m in meanings select CleanText(m.Groups[1].Value)) { UpdateGoogleBengaliWord(greWord, def); } }
private void ParseGoogleSynonym(string word) { GreWord greWord = GetGreWord(word); GoogleDictionaryHtml gd = (_entities.GoogleDictionaryHtmls.Where(w => w.Word == word)).FirstOrDefault(); FireLogMessage("GoogleSynonym Parsing " + word); if (gd == null) { return; } string text = gd.Html; Regex regexWord = new Regex(@"<a href=""/dictionary\?hl=en&q=.+?&sl=en&tl=bn&oi=dict_lk"">(.+?)</a>"); MatchCollection meanings = regexWord.Matches(text); foreach (Match m in meanings) { string def = CleanText(m.Groups[1].Value); UpdateGoogleSynonym(greWord, def); } }
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 \? \s+<strong id='hallo\d+'>(.+?)</strong>.+?<strong id='hallo\d+'> (.+?)</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(); } } }
private void button1_Click(object sender, EventArgs e) { long listNameId = -1; var entities = new gredbEntities(); var list = entities.ListNames.Where(o => o.Name.ToLower().Equals(comboBoxList.Text.Trim().ToLower())).Select(o => o).FirstOrDefault(); if (list == null) { ListName listName = new ListName { Name = comboBoxList.Text.Trim() }; entities.AddToListNames(listName); entities.SaveChanges(); listNameId = listName.Id; } else { listNameId = list.Id; } String str = Regex.Replace(textBox1.Text, "([0-9\\.]+|<.+?>)", ""); Regex regex = new Regex("([^\\s]+)"); ListName ln = (from n in entities.ListNames where n.Id == listNameId select n).FirstOrDefault(); try { MatchCollection mc = regex.Matches(str); foreach (Match m in mc) { try { GreWord word = (from w in entities.GreWords where w.Word.ToLower() == m.Value.ToLower() select w).FirstOrDefault(); if (word == null) { word = new GreWord() { Word = m.Value.ToLower(), }; entities.AddToGreWords(word); entities.SaveChanges(); } ListedWord lw = (from w in entities.ListedWords where w.ListName.Id == ln.Id && w.GreWord.Word == word.Word select w).FirstOrDefault(); if (lw == null) { lw = new ListedWord() { GreWord = word, ListName = ln }; entities.AddToListedWords(lw); entities.SaveChanges(); } } catch (Exception exp) { MessageBox.Show(exp.Message); } } entities.Connection.Close(); } catch (Exception exp) { } }
private void buttonCollect_Click(object sender, EventArgs e) { var entities = new gredbEntities(); long listNameId = -1; if (comboBoxList.Text.Trim().Length > 0) { var list = entities.ListNames.Where(o => o.Name.ToLower().Equals(comboBoxList.Text.Trim().ToLower())).Select(o => o).FirstOrDefault(); if (list == null) { ListName listName = new ListName(); listName.Name = comboBoxList.Text.Trim().ToLower(); entities.AddToListNames(listName); entities.SaveChanges(); listNameId = listName.Id; } else { listNameId = list.Id; } } else { listNameId = Convert.ToInt64(comboBoxList.SelectedValue); } String strWord = textBoxWord.Text.Trim().ToLower(); ListName ln = (from n in entities.ListNames where n.Id == listNameId select n).FirstOrDefault(); try { GreWord word; word = (from w in entities.GreWords where w.Word.ToLower() == strWord select w).FirstOrDefault(); if (word == null) { word = new GreWord() { Word = strWord, }; entities.AddToGreWords(word); entities.SaveChanges(); } ListedWord lw = (from w in entities.ListedWords where w.ListName.Id == ln.Id && w.GreWord.Word == word.Word select w).FirstOrDefault(); if (lw == null) { lw = new ListedWord() { GreWord = word, ListName = ln }; entities.AddToListedWords(lw); entities.SaveChanges(); } } catch (Exception exp) { MessageBox.Show(exp.Message); } ParserHelper parserHelper = new ParserHelper(entities); parserHelper.OnLogMessage += (sender2, person) => this.Invoke((MethodInvoker)(() => textBoxInfo.AppendText(person + "\r\n"))); parserHelper.WordToFetch = strWord; var workerThread = new Thread(parserHelper.FetchAndParseSingleWord) { IsBackground = true }; workerThread.Start(); }