///////////////////////////////////////////buttons part 2 private void choose_btn_Click(object sender, EventArgs e) { Ranker.cleanList(); openFileDialog1.FileName = ""; openFileDialog1.ShowDialog(); List <string> qry = new List <string>(); if (openFileDialog1.FileName != "") { try { qry = Files.qureys(openFileDialog1.FileName); } catch (Exception) { MessageBox.Show("wrong file"); } } List <string> qid = new List <string>(); List <string> q = new List <string>(); for (int i = 0; i < qry.Count; i = i + 2) { qid.Add(qry[i]); q.Add(qry[i + 1]); } Searcher.parseQuerys(qid, q, 50); }
public static void parseQuery(string qryid, string qry, int num, bool show) { Parse p = new Parse(); List <string> words = new List <string>(); p.parse(words, new List <bool>(), qry); //groupby HashSet <string> hash = new HashSet <string>(); for (int i = 0; i < words.Count; i++)//optional groupby { hash.Add(words[i]); } List <string> docs = Ranker.getdocs(num, hash.ToArray()); for (int i = 0; i < docs.Count; i++) { Console.WriteLine(docs[i]); } Ranker.addTolist(qryid, docs); if (show) { Searcher.show(docs); } }
/// <summary> /// Searches for the specified query, returns a ranked List of Documents matching any word in the query. /// </summary> /// <param name="query">The query.</param> /// <returns></returns> public static List <Document> Search(String query) { //Separate words, remove punctiations,make lowercase List <String> words = Semanter.Splitwords(query, ":").ToList(); //Obtains possible types searched by this query HashSet <String> typesPossible = TypeChecker(words); //Stem words and remove stopwords //slower method words = words.Except(invt.Stopwords).ToList(); List <String> splitwords = new List <String>(); string stem; foreach (string word in words) { stem = invt.Samantha.StemWord(word); if (!(invt.Stopwords.Contains(stem))) { splitwords.Add(stem); } } if (splitwords.Count == 0) { return(new List <Document>()); } //search for documents Dictionary <Document, Dictionary <string, List <int> > > Results = DocsFound(splitwords, typesPossible); if (Results.Keys.Count < 2) { return(Results.Keys.ToList()); } return(Ranker.RankQuery(splitwords, Results, invt.DocumentCount)); }
public static void calculate_w(string postlist) { //split term and post doc string[] post = postlist.Split('='); if (!Indexer.idf.ContainsKey(post[0])) { return; } //split by docs string[] docs = post[1].Split('#'); docs[0] = docs[0].Substring(docs[0].IndexOf(">") + 1); //split by args char[] del = { ':', ',' }; double weight = 0; string term = post[0]; double idf = Ranker.calculate_idf(term); if (idf == -1) { return; } foreach (string i in docs) { if (i.Equals("")) { //end of postlist return; } string[] doci = i.Split(del); if (!Parse.DocDic.ContainsKey(doci[0])) { continue; } double tf = (int.Parse(doci[1]) + int.Parse(doci[2])); tf = Ranker.calculate_itf(post[0], doci[0], tf); if (tf == -1) { return; } weight = Math.Pow(idf * tf, 2); //add the Wi to the relevant doc string[] doctemp = Parse.DocDic[doci[0]].Split(','); //if already exist add the weight if (doctemp.Length == 4) { weight = weight + double.Parse(doctemp[3]); string ans = doctemp[0] + "," + doctemp[1] + "," + doctemp[2] + "," + weight; Parse.DocDic[doci[0]] = ans; } //first W-term of the doc else { string ans = Parse.DocDic[doci[0]] + "," + weight; Parse.DocDic[doci[0]] = ans; } } }
private void save_qry_Click(object sender, EventArgs e) { browser.ShowDialog(); try { Ranker.writeList(@"C:\Users\aviv9_000\Desktop\all"); } catch (Exception) {} Ranker.cleanList(); }
private void reset_btn_Click(object sender, EventArgs e) { //if index doesnt exixt -> alert Ranker.cleanList(); qry_txt.Text = ""; openFileDialog1.FileName = ""; Doc_Search_chk.Checked = false; expantion_chk.Checked = false; }
private void run_query_btn_Click(object sender, EventArgs e) { Ranker.cleanList(); //if index doesnt exixt -> alert if (qry_txt.Text == "") { return; } if (Doc_Search_chk.Checked) { if (Parse.DocDic.ContainsKey(qry_txt.Text)) { string s = Parse.DocDic[qry_txt.Text].Split(',')[0]; //name of file string s2 = browseCurpus.Text; //corpus location string docpath = s2 + "/corpus/" + s + "/" + s; //read the file , find the doc, parse 5 sentences from the doc; } return; } Parse p = new Parse(); List <string> ans = new List <string>(); int back = 50; if (expantion_chk.Checked && !qry_txt.Text.Contains(" ")) { ans = Files.viki(qry_txt.Text);//need 50 docs instead of 70 } if (ans.Count != 0) { back = 70; } Indexer.path = pathPost.Text; string final = qry_txt.Text; for (int i = 0; i < ans.Count; i++) { final += " " + ans[i]; } ans.Clear(); Random rnd = new Random(); Searcher.parseQuery("" + rnd.Next(100000, 999999), final, back, true); }