UserSimulation.ErrorGenerator.Typoize C# (CSharp) Méthode

Typoize() public méthode

public Typoize ( Microsoft.FSharp.Core.FSharpOption input, string>.Dictionary typos, int guar ) : string
input Microsoft.FSharp.Core.FSharpOption
typos string>.Dictionary
guar int
Résultat string
        public string Typoize(OptChar[] input,
            Dictionary<Tuple<OptChar, string>, int> typos,
            int guar)
        {
            var output = "";

            // for each character in the string, sample from the typo dict
            for (int i = 0; i < input.Length; i++)
            {
                KeyValuePair<Tuple<OptChar, String>, int>[] dist;
                // handle case where the input character is an empty char
                // and condition on the possible typos for this optchar
                if (OptChar.get_IsNone(input[i]))
                {
                    // the input character is the empty char, so condition on empty chars
                    var dist_1 = typos.Where(kvp => kvp.Key.Item1 == null);
                    // if the current character is a guaranteed typo, ensure that
                    // an empty character does not appear in the output
                    dist = (i == guar ? dist_1.Where(kvp => !kvp.Key.Item2.Equals("")) : dist_1).ToArray();
                }
                else
                {
                    // condition on the possible typos for this particular OptChar
                    var dist_1 = typos.Where(kvp => input[i].Equals(kvp.Key.Item1));
                    // get the string corresponding to the current OptChar
                    var str_i = OptChar.get_IsNone(input[i]) ? "" : input[i].Value.ToString();

                    // if the current character is a guaranteed typo, ensure that
                    // the conditioned OptChar does not appear in the output
                    dist = (i == guar ? dist_1.Where(kvp => !kvp.Key.Item2.Equals(str_i)) : dist_1).ToArray();
                }

                var total = dist.Select(kvp => kvp.Value).Sum();
                var prs = dist.Select(kvp => (double)kvp.Value / total).ToArray();
                if (prs.Length == 0)
                {
                    output += OptCharToString(input[i]);
                }
                else
                {
                    // sample
                    var j = MultinomialSample(prs);
                    // j corresponds to what typo string?
                    output += dist[j].Key.Item2;
                }
            }

            return output;
        }