public static List <GroupRepresentationResult> QueryListToGroupRepresentationList(List <QueryResult> QRList, List <Tuple <string, string> > GroupNames) { ConcurrentBag <GroupRepresentationResult> GRBag = new ConcurrentBag <GroupRepresentationResult>(); DenseVector SummedVector = new DenseVector(QRList[0].ReturnAccessVector().Count); Parallel.ForEach(QRList, QR => { SummedVector = SummedVector + (DenseVector)QR.ReturnAccessVector(); }); Parallel.For(0, GroupNames.Count, i => { GroupRepresentationResult CurrentGR = new GroupRepresentationResult(GroupNames[i].Item1, GroupNames[i].Item2, (double)Decimal.Divide((decimal)SummedVector[i], QRList.Count)); GRBag.Add(CurrentGR); }); return((from GR in GRBag where Convert.ToDouble(GR.Percent.Substring(0, GR.Percent.Length - 1)) > 0 select GR).Distinct().OrderBy(o => o.Name).ToList()); }
public static string ReturnRecommendationString(List <QueryResult> AllInputs, List <Tuple <string, string> > AllGroupNamesAndDescriptions, double Threshold) { Vector CountVector = new DenseVector(AllInputs[0].ReturnAccessVector().Count); //bool TFIDFAttempted = false; /*if (ByTFIDF) * { * TFIDFAttempted = true; * try * { * GroupingQueryResult GQR = (GroupingQueryResult)AllInputs[0]; * Vector TestVector = GQR.ReturnTF_IDFVector(); * } * catch * { * ByTFIDF = false; * } * if (ByTFIDF) * { * Parallel.ForEach<QueryResult>(AllInputs, QR => { * GroupingQueryResult GQR = (GroupingQueryResult)QR; * CountVector = (DenseVector)(CountVector + GQR.ReturnTF_IDFVector()); * }); * CountVector = (DenseVector)(CountVector / AllInputs.Count); * Parallel.For(0, CountVector.Count, i => { * if (CountVector[i] < Threshold) * { * CountVector[i] = 0; * } * }); * * string Titlestring = $"Template Recommended By TF-IDF, with Threshold of {Threshold.ToString()}"; * return RecommendationString(CountVector, AllGroupNamesAndDescriptions, Titlestring); * } * }*/ //the following executes if TFIDF is not being used if (AllInputs[0].GetType() == typeof(RBACS.UserQueryResult)) { Parallel.ForEach <QueryResult>(AllInputs, QR => { CountVector = (DenseVector)(CountVector + QR.ReturnAccessVector()); }); } else if (AllInputs[0].GetType() == typeof(GroupingQueryResult)) { Parallel.ForEach(AllInputs, QR => { GroupingQueryResult GQR = (GroupingQueryResult)QR; CountVector = (DenseVector)(CountVector + GQR.ReturnAccessVector()); }); } else if (AllInputs[0].GetType() == typeof(UserClusteringResult)) { Parallel.ForEach(AllInputs, QR => { UserClusteringResult UCR = (UserClusteringResult)QR; CountVector = (DenseVector)(CountVector + UCR.ReturnAccessVector()); }); } else if (AllInputs[0].GetType() == typeof(GroupingClusteringResult)) { Parallel.ForEach(AllInputs, QR => { GroupingClusteringResult GCR = (GroupingClusteringResult)QR; CountVector = (DenseVector)(CountVector + GCR.ReturnAccessVector()); }); } CountVector = (DenseVector)(CountVector / AllInputs.Count); Parallel.For(0, CountVector.Count, i => { if (CountVector[i] < Threshold) { CountVector[i] = 0; } }); string TitleString; TitleString = $"Template Recommended By Relative Count with Threshold {Threshold.ToString()}"; return(RecommendationString(CountVector, AllGroupNamesAndDescriptions, TitleString)); }