/// Writes a trec evaluation file from the search results. /// if the query is not a standard one, '000' is used as the topicID public int WriteEvalFile(string fileName, string topicID) { List <string> evalList = new List <string>(); bool appendFlag = true; // check if the file exists if (File.Exists(fileName) == true) { // prompt for append DialogResult append = MessageBox.Show("Do you want to append to the existing file?", "Confirm", MessageBoxButtons.YesNo); if (append == DialogResult.Yes) { appendFlag = true; } else { // if overwrite confirm DialogResult ruSure = MessageBox.Show("Are you sure you want to overwrite the file?", "Confirm", MessageBoxButtons.YesNo); if (ruSure == DialogResult.Yes) { appendFlag = false; } } } // this is fixed string groupName = "09648500_NathanOnly"; // structure TopicID QO DocID rank score group string tempString = ""; for (int i = 0; i < resultsCollection.Length(); i++) { IRDocument doc = resultsCollection.GetIRDocument(i); tempString = topicID + "\tQ0\t"; tempString += doc.GetDocID() + "\t"; tempString += doc.Rank + "\t"; tempString += doc.Score + "\t"; tempString += groupName + "\n"; evalList.Add(tempString); } // write file FileHandling.WriteTextFile(evalList, fileName, appendFlag); return(0); }
// this is for testing only public void AutoResults(string filename, Dictionary <string, string> queries, bool preproc) { string dontcare = ""; bool appendFlag = false; foreach (KeyValuePair <string, string> q in queries) { // execute query string topicID = q.Key; RunQuery(q.Value, preproc, out dontcare); // get results //IRCollection results = BuildResults(); int numResults = BuildResults(); // write to file string groupName = "09648500_NathanOnly"; List <string> evalList = new List <string>(); // structure TopicID QO DocID rank score group string tempString = ""; for (int i = 0; i < numResults; i++) { IRDocument doc = resultsCollection.GetIRDocument(i); tempString = topicID + "\tQ0\t"; tempString += doc.GetDocID() + "\t"; tempString += doc.Rank + "\t"; tempString += doc.Score + "\t"; tempString += groupName + "\n"; evalList.Add(tempString); } // write file FileHandling.WriteTextFile(evalList, filename, appendFlag); appendFlag = true; } string trecpath = "../../../../results/"; if (File.Exists(trecpath + Path.GetFileName(filename))) { File.Delete(trecpath + Path.GetFileName(filename)); } File.Move(filename, trecpath + Path.GetFileName(filename)); // from MSDN Process p = new Process(); p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.FileName = trecpath + "trec_eval"; p.StartInfo.Arguments = "-q " + trecpath + "cranqrel.txt " + trecpath + "autoquery_results.txt"; p.Start(); string output = p.StandardOutput.ReadToEnd(); p.WaitForExit(); Console.WriteLine(output); }