Exemple #1
0
    public static T?SelectInteractive <T>(string str, Dictionary <string, T> dictionary, string context) where T : class
    {
        T?result = dictionary.TryGetC(str);

        if (result != null)
        {
            return(result);
        }

        StringDistance sd = new StringDistance();

        var list = dictionary.Keys.Select(s => new { s, lcs = sd.LongestCommonSubsequence(str, s) }).OrderByDescending(s => s.lcs !).Select(a => a.s !).ToList();

        var cs = new ConsoleSwitch <int, string>("{0} has been renamed in {1}".FormatWith(str, context));

        cs.Load(list);

        string?selected = cs.Choose();

        if (selected == null)
        {
            return(null);
        }

        return(dictionary.GetOrThrow(selected));
    }
 public void LongestCommonSubsequence()
 {
     Assert.Equal(4, d.LongestCommonSubsequence("hallo", "halo"));
     Assert.Equal(7, d.LongestCommonSubsequence("SupeMan", "SuperMan"));
     Assert.Equal(0, d.LongestCommonSubsequence("aoa", ""));
 }
 public void LongestCommonSubsequence()
 {
     Assert.True(4 == _stringDistance.LongestCommonSubsequence("hallo", "halo"));
     Assert.True(7 == _stringDistance.LongestCommonSubsequence("SupeMan", "SuperMan"));
     Assert.True(0 == _stringDistance.LongestCommonSubsequence("aoa", string.Empty));
 }