Skip to content

Commit b25330e

Browse files
authored
Add variety to Az.Predictor result list (#13420)
* add variety to predictions list * add variety to predictions list
1 parent fbd0b9b commit b25330e

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

tools/Az.Tools.Predictor/Az.Tools.Predictor/Predictor.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ public IDictionary<string, string> Query(Ast input, int suggestionCount, Cancell
102102
var resultBuilder = new StringBuilder();
103103
var usedParams = new HashSet<int>();
104104
var sourceBuilder = new StringBuilder();
105+
var presentCommands = new System.Collections.Generic.Dictionary<string, int>(); // Added
106+
int maxAllowedCommandDupl = 1;
105107

106108
for (var i = 0; i < _predictions.Count && results.Count < suggestionCount; ++i)
107109
{
@@ -140,7 +142,17 @@ public IDictionary<string, string> Query(Ast input, int suggestionCount, Cancell
140142
}
141143
}
142144

143-
results.Add(prediction.ToString(), sourceBuilder.ToString());
145+
146+
if (!presentCommands.ContainsKey(_predictions[i].Command))
147+
{
148+
results.Add(prediction.ToString(), sourceBuilder.ToString());
149+
presentCommands.Add(_predictions[i].Command, 1);
150+
}
151+
else if (presentCommands[_predictions[i].Command] < maxAllowedCommandDupl)
152+
{
153+
results.Add(prediction.ToString(), sourceBuilder.ToString());
154+
presentCommands[_predictions[i].Command] += 1;
155+
}
144156

145157
if (results.Count == suggestionCount)
146158
{
@@ -152,7 +164,7 @@ public IDictionary<string, string> Query(Ast input, int suggestionCount, Cancell
152164
}
153165
}
154166
catch
155-
{
167+
{
156168
}
157169

158170
return results;

0 commit comments

Comments
 (0)