public string logBugData(bugData input) { bugs.Add(input); input.BugId = bugs.Count.ToString(); try { db = File.Open("E:\\Data\\data" + bugs.Count + ".bin", FileMode.Create); sf.Serialize(db, input); db.Close(); count = new StreamWriter("E:\\Data\\count.txt", false); count.Write(bugs.Count); count.Flush(); count.Close(); } catch (Exception e) { System.Console.WriteLine(e.Message); } return bugs.Count.ToString(); //x.Serialize(System.Console.Out, bugs); //db.WriteLine("<Data>"); //db.WriteLine("<softwareName>"+input.SoftwareName+"</softwareName>"); //db.WriteLine("<vendor>" + input.Vendor + "</vendor>"); //db.WriteLine("<version>" + input.Version + "</version>"); //db.WriteLine("<softwareInfo>" + input.SoftwareInfo + "</softwareInfo>"); //db.WriteLine("<filename>" + input.Filename + "</filename>"); //db.WriteLine("<stackTrace>" + input.StackTrace + "</stackTrace>"); //db.WriteLine("<errorMessage>" + input.ErrorMessage + "</errorMessage>"); //db.WriteLine("<outputText>" + input.OutputText + "</outputText>"); //db.WriteLine("<moreOptions>" + input.MoreOptions + "</moreOptions>"); //db.WriteLine("<bugId>" + input.BugId + "</bugId>"); //db.WriteLine("<userId>" + input.UserId + "</userId>"); //db.WriteLine("<guid>" + input.Guid + "</guid>"); //db.WriteLine("<nameSpace>" + input.NameSpace + "</nameSpace>"); //db.WriteLine("<token>" + input.Token + "</token>"); //db.WriteLine("<operatingSystem>" + input.OperatingSystem + "</operatingSystem>"); //db.WriteLine("<tags>"); //bool flag = false; //foreach (string tag in input.Tags) //{ // if (flag == false) // { // db.WriteLine(tag); // flag = true; // } // else // { // db.WriteLine(","+tag); // } //} //db.WriteLine("</tags>"); //db.WriteLine("</Data>"); }
public responseInfo(bugData input) { userId = input.UserId; bugId = input.BugId; error = input.ErrorMessage; }
public responseInfo GetAnswer(bugData input) { if (input == null) { //throw new ArgumentNullException("Request Object not initialized !!"); return null; } log = new logger(); apiFunctions func = new apiFunctions(); if (input.BugId == "") { input.BugId = log.logBugData(input); log.log("Log called"); responseInfo var = new responseInfo(input); //SEARCH: search local DB string searchterm = input.ErrorMessage; string [] searchTermA = null; Regex r = new Regex(@"\s+"); //remove all whitespace searchterm = r.Replace(searchterm, " ");// to a single space searchTermA = searchterm.Split(' ');// then split for (int i = 0; i < searchTermA.Length; i++) { searchTermA[i] = searchTermA[i].Trim(' ', '?','\"', ',', '\'', ';', ':', '.', '(', ')').ToLower(); } // Array of arrays of results that match ONE of the search criteria Hashtable[] searchResultsArrayArray = new Hashtable[searchTermA.Length]; // finalResultsArray is populated with pages that *match* ALL the search criteria Hashtable finalResultsArray = new Hashtable(); bool botherToFindMatches = true; int indexOfShortestResultSet = -1, lengthOfShortestResultSet = -1; for (int i = 0; i < searchTermA.Length; i++) { searchResultsArrayArray[i] = my_catalog.Search (searchTermA[i].ToString()); if (null == searchResultsArrayArray[i]) { //botherToFindMatches = false; } else { int resultsInThisSet = searchResultsArrayArray[i].Count; if ( (lengthOfShortestResultSet == -1) || (lengthOfShortestResultSet > resultsInThisSet) ) { indexOfShortestResultSet = i; lengthOfShortestResultSet = resultsInThisSet; } } } // Find the common files from the array of arrays of documents // matching ONE of the criteria if (botherToFindMatches) { int c = indexOfShortestResultSet; // loop through the *shortest* resultset Hashtable searchResultsArray = searchResultsArrayArray[c]; if (null != searchResultsArray) foreach (object foundInFile in searchResultsArray) { // for each file in the *shortest* result set DictionaryEntry fo = (DictionaryEntry)foundInFile; // find matching files in the other resultsets int matchcount=0, totalcount=0, weight=0; for (int cx = 0; cx < searchResultsArrayArray.Length; cx++) { totalcount+=(cx+1); // keep track, so we can compare at the end (if term is in ALL resultsets) if (cx == c) { // current resultset matchcount += (cx+1); // implicitly matches in the current resultset weight += (int)fo.Value; // sum the weighting } else { Hashtable searchResultsArrayx = searchResultsArrayArray[cx]; if (null != searchResultsArrayx) foreach (object foundInFilex in searchResultsArrayx) { // for each file in the result set DictionaryEntry fox = (DictionaryEntry)foundInFilex; if (fo.Key.ToString() == fox.Key.ToString()) { // see if it matches matchcount += (cx+1); // and if it matches, track the matchcount weight += (int)fox.Value; // and weighting; then break out of loop, since break; // no need to keep looking through this resultset } } // foreach } // if } // for if ( (matchcount>0) && (matchcount == totalcount) ) { // was matched in each Array // we build the finalResults here, to pass to the formatting code below // - we could do the formatting here, but it would mix up the 'result generation' // and display code too much fo.Value = weight; // set the 'weight' in the combined results to the sum of individual document matches if ( !finalResultsArray.Contains (fo.Key) ) finalResultsArray.Add ( fo.Key, fo.Value); } // if } // foreach } // if // Format the results if (finalResultsArray.Count > 0) { SortedList output = new SortedList(finalResultsArray.Count); DictionaryEntry fo; string result = ""; string bugId = ""; foreach (object foundInFile in finalResultsArray) { fo = (DictionaryEntry)foundInFile; bugId = (String)fo.Key; int rank = (int)fo.Value; result = bugId; //extract info from bugId int sortrank = (rank * -1); if (output.Contains(sortrank)) { output[sortrank] = ((string)output[sortrank]) + ":" + result; } else { output.Add(sortrank, result); } result = ""; } //saves 10 result instances and applies the similarity metrics on these int resCount = 0; string[] bId = new string[100]; foreach (object rows in output.Keys) { bId[resCount] = (string)output[rows]; if (bId[resCount].Contains(':')) { string[] temp = bId[resCount].Split(':'); foreach (string s in temp) { bId[resCount] = s; resCount++; if (resCount >= MAX_RESULTS) break; } } else { resCount++; } if (resCount >= MAX_RESULTS) break; } suggestAnswer[] suggestions = new suggestAnswer[resCount]; for (int f = 0; f < resCount; f++) { suggestions[f] = this.extractRowSQL(bId[f]); } //rank results responseInfo response = SolutionRank.sortDBResults(input,suggestions); return response; } else { //No result in local DB so search developer network of stakoverflow //call the stackapi to get the response func.similar(input.ErrorMessage, input.Tags); func.rootObject.bugId = input.BugId; //sort the answers based on the question similarity func.rootObject = SolutionRank.sortOnlineAnswers(func.rootObject, input.ErrorMessage); log.logAnswer(func.rootObject); //no of solutions proposed int count = 0; //take the solution with haighest rank ie 0th element Question question = func.rootObject.questions[0]; log.log("Question: " + func.cleanText(question.body)); var.Question = func.cleanText(question.body); var.Solution = new string[question.answer_count]; var.Vote = new int[question.answer_count]; try { foreach (Answer answer in question.answers) { var.Solution[count] = func.cleanText(answer.body); var.Vote[count] = answer.score; log.log("Answer :" + var.Solution[count]); count++; } } catch (Exception e) { System.Console.WriteLine(e.Message); } var.BugId = input.BugId; return var; } } else { StackApi.RootObject solution = log.retrievStored(input.BugId); responseInfo var = new responseInfo(); if (input.MoreOptions < solution.questions.Length) { StackApi.Question question = solution.questions[input.MoreOptions]; log.log("Question in mem: " + func.cleanText(question.body)); var.Question = func.cleanText(question.body); var.Solution = new string[question.answer_count]; var.Vote = new int[question.answer_count]; int count = 0; try { foreach (Answer answer in question.answers) { var.Solution[count] = func.cleanText(answer.body); var.Vote[count] = 0; log.log("Answer in mem:" + var.Solution[count]); count++; } } catch (Exception e) { System.Console.WriteLine(e.Message); } var.BugId = input.BugId; return var; } else { return null; } } }