Levenshtein distance c# count error type

前端 未结 1 1391
青春惊慌失措
青春惊慌失措 2021-01-02 23:33

I found this bit of code that computes Levenshtein\'s distance between an answer and a guess:

int CheckErrors(string Answer, string Guess)
{
    int[,] d = n         


        
相关标签:
1条回答
  • 2021-01-02 23:50

    Seems like you could add counters for each of the operations:

                    if (Answer[i - 1] == Guess[j - 1])
                        d[i, j] = d[i - 1, j - 1];  //no operation
                    else
                    {
                        int del = d[i-1, j] + 1;
                        int ins = d[i, j-1] + 1;
                        int sub = d[i-1, j-1] + 1;
                        int op = Math.Min(Math.Min(del, ins), sub);
                        d[i, j] = op;
                        if (i == j)
                        {
                            if (op == del)
                                ++deletions;
                            else if (op == ins)
                                ++insertions;
                            else
                                ++substitutions;
                        }
                    }
    
    0 讨论(0)
提交回复
热议问题