public GoogleParser(string HTML, string word) { try { this.word = word; string box = Regex.Match(HTML, @"<div class=""g"">((.|\n)*?)<div class=""g"">").ToString(); string speech = Regex.Match(box, @">\/(.*?)\/<").ToString().Remove(0, 2); speech = speech.Replace("/<", ""); MatchCollection types = Regex.Matches(box, @"color:#666;padding:5px 0(.*?)<"); string type = ""; List<string> typeList = new List<string>(); List<string> distTypeList = new List<string>(); for (int i = 0; i < types.Count; i++) { string t = types[i].ToString().Replace("<", "").Remove(0, 26); typeList.Add(t); } //removing duplicates distTypeList = typeList.Distinct().ToList(); for (int i = 0; i < distTypeList.Count; i++) { type += "• " + distTypeList[i] + "\n"; } MatchCollection defs = Regex.Matches(box, @"<li(.*?)>(.*?)<"); string definitions = ""; for (int i = 0; i < defs.Count; i++) { string d = RipTags(defs[i].ToString()); d = d.Replace("<", ""); definitions += (i + 1).ToString() + ". " + d + "\n"; } OUTPUT = new wordInfo(word, definitions, type, speech); html += "<u><b>" + word + ": </b></u>" + "(" + type.Replace("\n", "/") + ")" + "<br>" + definitions.Replace("\n", "<br>") + "<br>"; } catch { } }
public GoogleParser(string HTML, string word) { try { this.word = word; string box = Regex.Match(HTML, @"<div class=""g"">((.|\n)*?)<div class=""g"">").ToString(); string speech = Regex.Match(box, @">\/(.*?)\/<").ToString().Remove(0, 2); speech = speech.Replace("/<", ""); MatchCollection types = Regex.Matches(box, @"color:#666;padding:5px 0(.*?)<"); string type = ""; List <string> typeList = new List <string>(); List <string> distTypeList = new List <string>(); for (int i = 0; i < types.Count; i++) { string t = types[i].ToString().Replace("<", "").Remove(0, 26); typeList.Add(t); } //removing duplicates distTypeList = typeList.Distinct().ToList(); for (int i = 0; i < distTypeList.Count; i++) { type += "• " + distTypeList[i] + "\n"; } MatchCollection defs = Regex.Matches(box, @"<li(.*?)>(.*?)<"); string definitions = ""; for (int i = 0; i < defs.Count; i++) { string d = RipTags(defs[i].ToString()); d = d.Replace("<", ""); definitions += (i + 1).ToString() + ". " + d + "\n"; } OUTPUT = new wordInfo(word, definitions, type, speech); html += "<u><b>" + word + ": </b></u>" + "(" + type.Replace("\n", "/") + ")" + "<br>" + definitions.Replace("\n", "<br>") + "<br>"; } catch { } }
public bool addWord(string word, string meaning) { for (int x = 0; x < numWords; x++) { if (word == wlist[x].getWord() || (numWords > maxWords)) { Console.WriteLine("Duplicate!"); return(false); } } wordInfo w = new wordInfo(word, meaning); wlist[numWords] = w; numWords++; return(true); }
/*public void printOrder(wordInfo[] array) * { * int start, presentLoc; * //int presentLoc = start - 1; * for ( start = 1; start < numWords; start++) * { * presentLoc = start - 1; * wordInfo temp = wlist[start]; * //string z =""; * //int compare = string.Compare(wlist[start].getWord(), wlist[presentLoc].getWord()); * while ((presentLoc >= 0) && (wlist[presentLoc].getWord().CompareTo(temp)>0)){ * wlist[presentLoc + 1] = wlist[presentLoc]; * presentLoc--; * } * * wlist[presentLoc + 1] = temp; * * //wlist[presentLoc].getWord() > temp) * } * }*/ public void insertionSort(wordInfo[] array) { for (int start = 1; start < numWords; start++) { wordInfo temp = wlist[start]; int presentLoc = start - 1; //string z =""; int compare = string.Compare(wlist[start].getWord(), wlist[presentLoc].getWord()); while (presentLoc >= 0 && compare > 0) { wlist[presentLoc + 1] = wlist[presentLoc]; presentLoc--; } wlist[presentLoc + 1] = temp; } }
public void load(wordInfo wordInfo) { dataGrid.DataContext = wordInfo; }
public wordView(wordInfo w) { Title = (char.ToUpper(w.word[0]) + w.word.Substring(1)); #region labels Label lblWord = new Label { HorizontalOptions = LayoutOptions.CenterAndExpand, FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)), }; lblWord.Text = w.word; Label lblDefinition = new Label { HorizontalOptions = LayoutOptions.CenterAndExpand, }; lblDefinition.Text = w.definition; Label lblPartOfSpeech = new Label { HorizontalOptions = LayoutOptions.CenterAndExpand, }; lblPartOfSpeech.Text = w.partOfSpeech; Label lblPronuc = new Label { HorizontalOptions = LayoutOptions.CenterAndExpand, }; lblPronuc.Text = w.pronunciation; #endregion StackLayout synstack = new StackLayout { Padding = new Thickness(10), }; foreach (string s in w.synonyms) synstack.Children.Add(new Label { Text = s }); ScrollView synScrollview = new ScrollView { Content = synstack }; StackLayout antstack = new StackLayout { Padding = new Thickness(10), }; foreach (string s in w.antonyms) antstack.Children.Add(new Label { Text = s }); ScrollView antScrollview = new ScrollView { Content = antstack }; Content = new StackLayout { Padding = new Thickness(25), Children = { // lblWord, lblPronuc, new ScrollView { Content = lblDefinition, }, lblPartOfSpeech, new StackLayout { Orientation = StackOrientation.Horizontal, Children = { new StackLayout { VerticalOptions = LayoutOptions.StartAndExpand, HorizontalOptions = LayoutOptions.CenterAndExpand, Children = { new Label {Text = "Synonyms",FontSize = Device.GetNamedSize (NamedSize.Medium, typeof(Label)), }, synScrollview } }, new StackLayout { VerticalOptions = LayoutOptions.StartAndExpand, HorizontalOptions = LayoutOptions.CenterAndExpand, Children = { new Label {Text = "Antonyms",FontSize = Device.GetNamedSize (NamedSize.Medium, typeof(Label)), }, antScrollview } } } } } }; }