Example #1
0
        private static IEnumerable <PredictionInfo> GetRefinedCandidates(IEnumerable <CsccContextInfo> baseCandidates,
                                                                         CsccContextInfo currentContext)
        {
            // Hamming distance closeness
            var similarities = new List <PredictionInfo>();

            foreach (var baseCandidate in baseCandidates)
            {
                similarities.Add(new PredictionInfo(baseCandidate, baseCandidate.Similarity(currentContext)));
            }

            // Sort by Hamming distance
            similarities.Sort();

            // Take k = 200 most similar candidate contexts
            var refinedCandidates = similarities.Take(_maximumRefinedCandidates).ToList();

            for (var i = 0; i < refinedCandidates.Count; i++)
            {
                refinedCandidates[i].ExtendedSimilarity = refinedCandidates[i].Context.NormalizedLCS(currentContext);
                refinedCandidates[i].LocalSimilarity    = refinedCandidates[i].Context.LevenshteinSimilarity(currentContext);
                if (!refinedCandidates[i].IsSimilar())
                {
                    refinedCandidates.RemoveAt(i);
                }
            }

            refinedCandidates.Sort();

            return(refinedCandidates);
        }
Example #2
0
        public List <string> GetPredictions(CsccContextInfo currentContext, string type)
        {
            var refinedCandidates = GetRefinedCandidates(GetBaseCandidates(type), currentContext);

            var predictions = new List <string>();

            foreach (var refinedCandidate in refinedCandidates)
            {
                if (!predictions.Contains(refinedCandidate.Context.Invocation))
                {
                    predictions.Add(refinedCandidate.Context.Invocation);
                }

                if (predictions.Count == _maximumPredictions)
                {
                    break;
                }
            }

            return(predictions);
        }
Example #3
0
 public bool IsSimilar(CsccContextInfo context)
 {
     return(LocalSimilarity(context) >= LowerThreshold ||
            ExtendedSimilarity(context) >= LowerThreshold);
 }
Example #4
0
 public float Similarity(CsccContextInfo context)
 {
     return(Math.Max(LocalSimilarity(context), ExtendedSimilarity(context)));
 }