public UserKNNReport Search(string SearchTerm) { UserKNNReport Output = new UserKNNReport(search(SearchTerm).ConvertAll(c => (UserKNNResult)c), flipOrdering(order), lastPropertyQueried); if (Output.QRList.Count > 0) { Output.sortByPropertyValue(lastPropertyQueried); } return(Output); }
private void nNDataGridView_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) { string Property = nNDataGridView.Columns[e.ColumnIndex].HeaderText; if (thisFormResultType == typeof(UserQueryResult)) { UserKNNReport ReportPointer = (UserKNNReport)thisQueryReport; ReportPointer.SortByProperty(Property); thisBindingSource.DataSource = ReportPointer.QRList; } else if (thisFormResultType == typeof(GroupingQueryResult)) { GroupingKNNReport ReportPointer = (GroupingKNNReport)thisQueryReport; ReportPointer.SortByProperty(Property); thisBindingSource.DataSource = ReportPointer.QRList; } else { } }
private void nearestNeighboursButton_Click(object sender, EventArgs e) { nNDataGridView.AutoGenerateColumns = true; bool KSpecified = true; int K; List <iKNNResult> AllResults = new List <iKNNResult>(); ConcurrentBag <iKNNResult> ResultBag = new ConcurrentBag <iKNNResult>(); try { K = Convert.ToInt32(kTextBox.Text); } catch { KSpecified = false; kTextBox.Text = "All"; Application.DoEvents(); K = -1; } if (thisFormResultType == typeof(UserQueryResult)) { UserQueryResult UQR = (UserQueryResult)thisFormResult; List <UserKNNResult> UKRList = new List <UserKNNResult>(); Parallel.ForEach <UserQueryResult>(parentReference.UserQueryResults, CurrentUQR => { if (CurrentUQR.AccountName != UQR.AccountName) { UserKNNResult UKR = new UserKNNResult(CurrentUQR); double CurrentDistance = HelperFunctions.GetEuclideanDistance(UQR.ReturnAccessVector(), CurrentUQR.ReturnAccessVector()); UKR.AssignKNNDistanceFromX(CurrentDistance); ResultBag.Add(UKR); } }); UKRList = ResultBag.Cast <UserKNNResult>().ToList <UserKNNResult>(); AllResults = UKRList.OrderBy(o => o.Distance).ToList().Cast <iKNNResult>().ToList(); thisQueryReport = new UserKNNReport(AllResults.Cast <UserKNNResult>().ToList(), Ordering.Ascending); } else if (thisFormResultType == typeof(GroupingQueryResult)) { GroupingQueryResult GQR = (GroupingQueryResult)thisFormResult; List <GroupingKNNResult> GKRList = new List <GroupingKNNResult>(); Parallel.ForEach <GroupingQueryResult>(parentReference.GroupingQueryResults, CurrentGQR => { if (CurrentGQR.GroupingName != GQR.GroupingName) { GroupingKNNResult GKR = new GroupingKNNResult(CurrentGQR); double CurrentDistance; if (parentReference.ClusterByRelativeCount) { CurrentDistance = HelperFunctions.GetEuclideanDistance(GQR.ReturnAccessVector(), CurrentGQR.ReturnAccessVector()); } else { CurrentDistance = HelperFunctions.GetEuclideanDistance(GQR.ReturnTF_IDFVector(), CurrentGQR.ReturnTF_IDFVector()); } GKR.AssignKNNDistanceFromX(CurrentDistance); ResultBag.Add(GKR); } }); GKRList = ResultBag.Cast <GroupingKNNResult>().ToList(); AllResults = GKRList.OrderBy(o => o.Distance).ToList().Cast <iKNNResult>().ToList(); thisQueryReport = new GroupingKNNReport(AllResults.Cast <GroupingKNNResult>().ToList(), Ordering.Ascending); } else { } if (KSpecified && K <= AllResults.Count) { List <iKNNResult> Outlist = new List <iKNNResult>(); for (int i = 0; i < K; i++) { Outlist.Add(AllResults[i]); } //AllKNNResults = Outlist; if (thisFormResultType == typeof(UserQueryResult)) { thisQueryReport = new UserKNNReport(Outlist.Cast <UserKNNResult>().ToList(), Ordering.Ascending); } else if (thisFormResultType == typeof(GroupingQueryResult)) { thisQueryReport = new GroupingKNNReport(Outlist.Cast <GroupingKNNResult>().ToList(), Ordering.Ascending); } else { } } else { AllKNNResults = AllResults; } if (thisFormResultType == typeof(UserQueryResult)) { UserKNNReport ReportPointer = (UserKNNReport)thisQueryReport; thisBindingSource.DataSource = ReportPointer.QRList; //thisBindingSource.DataSource = (UserKNNReport)thisQueryReport..Cast<UserKNNResult>().ToList(); nNDataGridView.DataSource = thisBindingSource; } else if (thisFormResultType == typeof(GroupingQueryResult)) { GroupingKNNReport ReportPointer = (GroupingKNNReport)thisQueryReport; thisBindingSource.DataSource = ReportPointer.QRList; nNDataGridView.DataSource = thisBindingSource; } else { } }