/// <summary> /// Attempts to retrieve the top <paramref name="numRequested"/> similar JobDataEntries from the database that are a part of the specified complaint group /// </summary> /// <param name="entryIn">Entry that represents the query made</param> /// <param name="manipulator">Object to access the database with</param> /// <param name="companyId">The id of the company to make the request of. Determines which tables to retrieve the data from</param> /// <param name="complaintGroupId">Database id of the complaint group to match JobDataEntries by</param> /// <param name="numRequested">Number of requested JobDataEntries to output</param> /// <param name="offset">Number to offset the list of returned JobDataEntries by. /// So with an offset of 5 and 10 JobDataEntires requested, the top 5-15 JobDataEntries would instead be returned</param> /// <returns>Json string containing the requested similar JobDataEntries</returns> public string ProcessQueryForSimilarQueries(RepairJobEntry entryIn, MySqlDataManipulator manipulator, int companyId, int complaintGroupId, int numRequested, int offset = 0) { List <string> tokens = SentenceTokenizer.TokenizeSentence(entryIn.Complaint); List <List <string> > taggedTokens = KeywordTagger.Tag(tokens); List <string> keywords = KeywordPredictor.PredictKeywords(taggedTokens); KeywordExample example = new KeywordExample(); foreach (string keyword in keywords) { example.AddKeyword(keyword); } KeywordClusterer.Load(manipulator, companyId); List <int> groups = KeywordClusterer.PredictTopNSimilarGroups(example, 3); entryIn.ComplaintGroups = "[" + string.Join(',', groups) + "]"; List <RepairJobEntry> potentials = manipulator.GetDataEntriesByComplaintGroup(companyId, complaintGroupId); List <EntrySimilarity> ret = ProblemPredictor.GetQueryResults(entryIn, potentials, numRequested, offset); JsonListStringConstructor retConstructor = new JsonListStringConstructor(); ret.ForEach(obj => retConstructor.AddElement(ConvertEntrySimilarity(obj))); return(retConstructor.ToString()); JsonDictionaryStringConstructor ConvertEntrySimilarity(EntrySimilarity e) { JsonDictionaryStringConstructor r = new JsonDictionaryStringConstructor(); r.SetMapping("Make", e.Entry.Make); r.SetMapping("Model", e.Entry.Model); r.SetMapping("Complaint", e.Entry.Complaint); r.SetMapping("Problem", e.Entry.Problem); if (e.Entry.Year == -1) { r.SetMapping("Year", "Unknown"); } else { r.SetMapping("Year", e.Entry.Year); } r.SetMapping("Id", e.Entry.Id); r.SetMapping("Difference", e.Difference); return(r); } }