private int doWnGrep(Wnlib.PartOfSpeech pos) { if (radWildcard.Checked | radRegularExpression.Checked) { return(WildCardRegex(pos)); } else if (radSoundsLike.Checked) { return(soundsLike(pos)); } else { return(AnagramScrabble(pos)); } //ListBox1.Sorted = True }
private void Button2Click(System.Object sender, System.EventArgs e) { // handles noun, verb, adj, adverb click for context menu Button b = (Button)sender; Wnlib.SearchSet ss = null; //= bobj2 string btext = b.Text; if (btext == "Adjective") { btext = "Adj"; } switch (btext) { case "Noun": ss = (Wnlib.SearchSet)bobj2; break; case "Verb": ss = (Wnlib.SearchSet)bobj3; break; case "Adj": ss = (Wnlib.SearchSet)bobj4; break; case "Adverb": ss = (Wnlib.SearchSet)bobj5; break; } Wnlib.PartOfSpeech pos = Wnlib.PartOfSpeech.of(btext.ToLower()); int i = 0; opts = new ArrayList(); ContextMenu cm = new ContextMenu(); ArrayList tmplst = new ArrayList(); for (i = 0; i <= Wnlib.Opt.Count - 1; i++) { Wnlib.Opt opt = Wnlib.Opt.at(i); //Try ' TODO: fix problem with adjective menu if (ss[opt.sch.ptp.ident] & object.ReferenceEquals(opt.pos, pos)) { if (tmplst.IndexOf(opt.label) == -1 & opt.label != "Grep") { MenuItem mi = new MenuItem(); // (opt.label, AddressOf searchMenu_Click) mi.Text = opt.label; mi.Click += searchMenu_Click; opts.Add(opt); cm.MenuItems.Add(mi); tmplst.Add(opt.label); } } //Catch //End Try } cm.Show(b.Parent, new System.Drawing.Point(b.Left, b.Bottom)); //Point(b.Left, b.Bottom)) }
/// <summary> /// Handles the sense buttons to build and display the appropriate dropdown menu for /// searches on word relationships. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnWordType_Click(System.Object sender, System.EventArgs e) { Button b = (Button)sender; Wnlib.SearchSet ss = null; string btext = b.Text; if (btext == "Adjective") { btext = "Adj"; } switch (btext) { case "Noun": ss = (Wnlib.SearchSet)bobj2; break; case "Verb": ss = (Wnlib.SearchSet)bobj3; break; case "Adj": ss = (Wnlib.SearchSet)bobj4; break; case "Adverb": ss = (Wnlib.SearchSet)bobj5; break; } Wnlib.PartOfSpeech pos = Wnlib.PartOfSpeech.of(btext.ToLower()); int i = 0; opts = new ArrayList(); ContextMenu cm = new ContextMenu(); ArrayList tmplst = new ArrayList(); for (i = 0; i <= Wnlib.Opt.Count - 1; i++) { Wnlib.Opt opt = Wnlib.Opt.at(i); //opt.at(i); if (ss[opt.sch.ptp.ident] & object.ReferenceEquals(opt.pos, pos)) { if (tmplst.IndexOf(opt.label) == -1 & opt.label != "Grep") { MenuItem mi = new MenuItem(); mi.Text = opt.label; mi.Click += searchMenu_Click; opts.Add(opt); cm.MenuItems.Add(mi); tmplst.Add(opt.label); } } } cm.Show(b.Parent, new Point(b.Left, b.Bottom)); }
public override ArrayList wngrep(string wordPassed, Wnlib.PartOfSpeech pos) { ArrayList r = new ArrayList(); StreamReader inputFile = Wnlib.WNDB.index(pos); inputFile.BaseStream.Seek(0L, SeekOrigin.Begin); inputFile.DiscardBufferedData(); string word = wordPassed.Replace(" ", "_"); string line; char c = (char)200; // regex / scrabble char c2 = (char)201; // soundslike bool regexflag = false; bool soundslikeflag = false; int soundslikestrength = 0; // if the string ends with chr 200 the search is a regular expression if (word.EndsWith(c.ToString())) { regexflag = true; word = word.Replace(c.ToString(), ""); } if (word.EndsWith(c2.ToString())) { soundslikeflag = true; word = word.Replace(c2.ToString(), ""); //soundslikestrength = Convert.ToInt16(Regex.Replace(word, "[[^a-zA-Z]", "")); soundslikestrength = Convert.ToInt16(Regex.Replace(word, "[[^a-zA-Z]", "")); word = word.Replace(Regex.Replace(word, "[[^a-zA-Z]", ""), ""); } if (!regexflag && !soundslikeflag) // non-regex search { while ((line = inputFile.ReadLine()) != null) { int lineLen = line.IndexOf(' '); line = line.Substring(0, lineLen); // TODO: change the .IndexOf to allow wildcards // if (line.IndexOf(word)>=0) try { //if (ebswift.ebString.vbLike(line, word)) if (LikeOperator.LikeString(line, word, Microsoft.VisualBasic.CompareMethod.Text)) { r.Add(line.Replace("_", " ")); } } catch { } } } else if (regexflag) { // regex search Regex rg = new Regex("a", RegexOptions.IgnoreCase); try { rg = new Regex(word, RegexOptions.IgnoreCase); } catch { MessageBox.Show("Malformed regular expression."); r.Add("error"); return(r); } while ((line = inputFile.ReadLine()) != null) { int lineLen = line.IndexOf(' '); line = line.Substring(0, lineLen); // TODO: change the .IndexOf to allow wildcards // if (line.IndexOf(word)>=0) try { Match m; m = rg.Match(line); if (m.Success) { r.Add(line.Replace("_", " ")); } } catch { } } } else if (soundslikeflag) // sounds like search { mphonecompare.computeKeys(word); while ((line = inputFile.ReadLine()) != null) { int lineLen = line.IndexOf(' '); line = line.Substring(0, lineLen); try { if (soundsLike(line)) //, word)) //, soundslikestrength)) { r.Add(line.Replace("_", " ")); } } catch { } } } return(r); }
private int soundsLike(Wnlib.PartOfSpeech pos) { int i = 0; int j = 0; int x = 0; int deccount = 0; string tmpstr = ""; // asc 201 specifies a soundslike // adding the trackbar value produces the strength of "sounds like" match // between 1 and 3 //tmpstr = TextBox1.Text & TrackBar1.Value & Chr(201) tmpstr = TextBox1.Text + "3" + Strings.Chr(201); deccount += 1; Wnlib.Search se = null; ArrayList list = new ArrayList(); // if searchscrabble is checked then search the official list if (chkSearchScrabble.Checked) { list = EnableDT_Classes.EnableDT_Search.wngrep(tmpstr, radScrabble.Checked); } else { se = new Wnlib.Search(tmpstr, false, pos, new Wnlib.SearchType(false, "WNGREP"), 0, new wildgrep()); list = se.strings; } ArrayList tmplist = new ArrayList(); // delete duplicates // ignore errors here = the list may be empty try { DataRow dr = default(DataRow); for (j = 0; j <= list.Count - 1; j++) { if (tmplist.Count >= 1) { if (tmplist.IndexOf(list[j]) == -1) { tmplist.Add(list[j]); // ********** // ListBox1.Items.Add(list[i]) dr = dataSet1.Tables[0].NewRow(); dr["Word"] = list[j]; if (chkSearchScrabble.Checked) { dr["Score"] = ScrabbleScore(list[j].ToString()); } dataSet1.Tables[0].Rows.Add(dr); // ********** } } else { tmplist.Add(list[j]); // ListBox1.Items.Add(list[i]) dr = dataSet1.Tables[0].NewRow(); dr["Word"] = list[j]; if (chkSearchScrabble.Checked) { dr["Score"] = ScrabbleScore(list[j].ToString()); } dataSet1.Tables[0].Rows.Add(dr); } } list = tmplist; dataGrid1.DataSource = dataSet1.Tables[0]; } catch { } i = list.Count; return(i); }
private int AnagramScrabble(Wnlib.PartOfSpeech pos) { int i = 0; int j = 0; int x = 0; int deccount = 0; string tmpstr = ""; DataRow dr = default(DataRow); // TODO: for both anagram search and scrabble search, remove duplicates from the list // before processing a word, otherwise the character test is done twice needlessly // not a scrabble search, just find the anagram if (!radScrabble.Checked) { // repeat the string into character match blocks for the length of itself // eg. kilmo would be [kilmo][kilmo][kilmo][kilmo][kilmo] for (j = 1; j <= TextBox1.Text.Length; j++) { tmpstr += "[" + TextBox1.Text + "]"; } // Dim se As Wnlib.Search = New Wnlib.Search(TextBox1.Text, False, pos, New Wnlib.SearchType(False, "WNGREP"), 0) Wnlib.Search se = null; ArrayList list = new ArrayList(); // if searchscrabble is checked then search the official list if (chkSearchScrabble.Checked) { list = EnableDT_Classes.EnableDT_Search.wngrep(tmpstr, radScrabble.Checked); } else { se = new Wnlib.Search(tmpstr, false, pos, new Wnlib.SearchType(false, "WNGREP"), 0, new wildgrep()); list = se.strings; } ArrayList tmplist = new ArrayList(); //delete(duplicates) // ignore errors here = the list may be empty try { for (j = 0; j <= list.Count - 1; j++) { if (tmplist.Count >= 1) { if (tmplist.IndexOf(list[j]) == -1) { tmplist.Add(list[j]); // ****** if (CheckAnagram(list[j].ToString().ToString(), TextBox1.Text)) { // ListBox1.Items.Add(list[i]) dr = dataSet1.Tables[0].NewRow(); dr["Word"] = list[j]; if (chkSearchScrabble.Checked) { dr["Score"] = ScrabbleScore(list[j].ToString()); } dataSet1.Tables[0].Rows.Add(dr); } // ****** } } else { tmplist.Add(list[j]); // ****** if (CheckAnagram(list[j].ToString().ToString(), TextBox1.Text)) { // ListBox1.Items.Add(list[i]) dr = dataSet1.Tables[0].NewRow(); dr["Word"] = list[j]; if (chkSearchScrabble.Checked) { dr["Score"] = ScrabbleScore(list[j].ToString()); } dataSet1.Tables[0].Rows.Add(dr); } } } list = tmplist; } catch { } //For j = 0 To list.Count - 1 // If CheckAnagram(list[i].ToString(), TextBox1.Text) Then // ListBox1.Items.Add(list[i]) // End If //Next j i = list.Count; // scrabble search } else { deccount = 0; tmpstr = ""; // asc 200 specifies a regex tmpstr = "^[" + TextBox1.Text + "]+$" + Strings.Chr(200); //For x = 1 To TextBox1.Text.Length // repeat the string into character match blocks for the length of itself // eg. kilmo would be [kilmo][kilmo][kilmo][kilmo][kilmo] //For j = 1 To (TextBox1.Text.Length - deccount) // tmpstr += "[" & TextBox1.Text & "]" //Next deccount += 1; Wnlib.Search se = null; ArrayList list = new ArrayList(); // if searchscrabble is checked then search the official list if (chkSearchScrabble.Checked) { list = EnableDT_Classes.EnableDT_Search.wngrep(tmpstr, radScrabble.Checked); } else { se = new Wnlib.Search(tmpstr, false, pos, new Wnlib.SearchType(false, "WNGREP"), 0, new wildgrep()); list = se.strings; } ArrayList tmplist = new ArrayList(); // delete duplicates // ignore errors here = the list may be empty try { for (j = 0; j <= list.Count - 1; j++) { if (tmplist.Count >= 1) { if (tmplist.IndexOf(list[j]) == -1) { tmplist.Add(list[j]); // ********** if (CheckAnagram(list[j].ToString().ToString(), TextBox1.Text)) { //ListBox1.Items.Add(list[i]) dr = dataSet1.Tables[0].NewRow(); dr["Word"] = list[j]; if (chkSearchScrabble.Checked) { dr["Score"] = ScrabbleScore(list[j].ToString()); } dataSet1.Tables[0].Rows.Add(dr); } // ********** } } else { tmplist.Add(list[j]); // ********** if (CheckAnagram(list[j].ToString(), TextBox1.Text)) { // ListBox1.Items.Add(list[i]) dr = dataSet1.Tables[0].NewRow(); dr["Word"] = list[j]; if (chkSearchScrabble.Checked) { dr["Score"] = ScrabbleScore(list[j].ToString()); } dataSet1.Tables[0].Rows.Add(dr); } } } list = tmplist; } catch { } i = list.Count; tmpstr = ""; //Next //DataGrid1.TableStyles(0).GridColumnStyles(0).Width = 200 //DataGrid1.TableStyles(0).GridColumnStyles(1).Width = 100 } dataGrid1.DataSource = dataSet1.Tables[0]; return(i); }
private int WildCardRegex(Wnlib.PartOfSpeech pos) { int i = 0; int j = 0; int x = 0; int deccount = 0; string tmpstr = ""; // TODO: for both anagram search and scrabble search, remove duplicates from the list // before processing a word, otherwise the character test is done twice needlessly // not a scrabble search, just find the anagram if (!radRegularExpression.Checked) { tmpstr = TextBox1.Text; } else { tmpstr = TextBox1.Text + Strings.Chr(200); } Wnlib.Search se = null; ArrayList list = new ArrayList(); // if searchscrabble is checked then search the official list if (chkSearchScrabble.Checked) { list = EnableDT_Classes.EnableDT_Search.wngrep(tmpstr, radScrabble.Checked); } else { se = new Wnlib.Search(tmpstr, false, pos, new Wnlib.SearchType(false, "WNGREP"), 0, new wildgrep()); list = se.strings; } ArrayList tmplist = new ArrayList(); if (list.IndexOf("error") != -1) { return(-1); } //delete(duplicates) // ignore errors here = the list may be empty try { DataRow dr = default(DataRow); for (j = 0; j <= list.Count - 1; j++) { if (tmplist.Count >= 1) { if (tmplist.IndexOf(list[j]) == -1) { tmplist.Add(list[j]); // ****** //ListBox1.Items.Add(list[i]) dr = dataSet1.Tables[0].NewRow(); dr["Word"] = list[j]; if (chkSearchScrabble.Checked) { dr["Score"] = ScrabbleScore(list[j].ToString()); } dataSet1.Tables[0].Rows.Add(dr); // ****** } } else { tmplist.Add(list[j]); // ****** // ListBox1.Items.Add(list[i]) dr = dataSet1.Tables[0].NewRow(); dr["Word"] = list[i]; if (chkSearchScrabble.Checked) { dr["Score"] = ScrabbleScore(list[i].ToString()); } dataSet1.Tables[0].Rows.Add(dr); // ****** } } list = tmplist; dataGrid1.DataSource = dataSet1.Tables[0]; } catch { } //For j = 0 To list.Count - 1 // If CheckAnagram(list[i].ToString(), TextBox1.Text) Then // ListBox1.Items.Add(list[i]) // End If //Next j i = list.Count; return(i); }