src/main/java/eu/digitisation/distance/WordCompare.java
private static EditTable align(TokenArray a1, TokenArray a2) {

        int l1 = a1.length();      // length of first 
        int l2 = a2.length();      // length of second
        int[][] A;   // distance table
        EditTable B; // edit operations

        // intialize 
        A = new int[2][l2 + 1];
        B = new EditTable(l1 + 1, l2 + 1);
        // Compute first row
        A[0][0] = 0;
        B.set(0, 0, EdOp.KEEP);
        for (int j = 1; j <= l2; ++j) {
            A[0][j] = A[0][j - 1] + 1;
            B.set(0, j, EdOp.INSERT);
        }

        // Compute other rows
        for (int i = 1; i <= l1; ++i) {
            int n1 = a1.tokenAt(l1 - i);
            A[i % 2][0] = A[(i - 1) % 2][0] + 1;
            B.set(i, 0, EdOp.DELETE);
            for (int j = 1; j <= l2; ++j) {
                int n2 = a2.tokenAt(l2 - j);

                if (n1 == n2) {
                    A[i % 2][j] = A[(i - 1) % 2][j - 1];
                    B.set(i, j, EdOp.KEEP);
                } else {
                    A[i % 2][j] = min(A[(i - 1) % 2][j] + 1,
                            A[i % 2][j - 1] + 1,
                            A[(i - 1) % 2][j - 1] + 1);
                    if (A[i % 2][j] == A[(i - 1) % 2][j] + 1) {
                        B.set(i, j, EdOp.DELETE);
                    } else if (A[i % 2][j] == A[i % 2][j - 1] + 1) {
                        B.set(i, j, EdOp.INSERT);
                    } else {
                        B.set(i, j, EdOp.SUBSTITUTE);
                    }
                }
            }
        }
        return B;
    }
/**
     * Compute the table of basic edit operations needed to transform first into
     * second
     *
     * @param first source string
     * @param second target string
     * @return the table of minimal basic edit operations needed to transform
     * first into second
     */
Compute the table of basic edit operations needed to transform first into
second

@param first source string
@param second target string
@return the table of minimal basic edit operations needed to transform
first into second
Compute the table of basic edit operations needed to transform first into second @param first source string @param second target string @return the table of minimal basic edit operations needed to transform first into second
private static EditTable align(TokenArray a1, TokenArray a2) {
        int l1 = a1.length();      
        int l2 = a2.length();      
        int[][] A;   
        EditTable B; 
        A = new int[2][l2 + 1];
        B = new EditTable(l1 + 1, l2 + 1);
        A[0][0] = 0;
        B.set(0, 0, EdOp.KEEP);
        for (int j = 1; j <= l2; ++j) {
            A[0][j] = A[0][j - 1] + 1;
            B.set(0, j, EdOp.INSERT);
        }
        for (int i = 1; i <= l1; ++i) {
            int n1 = a1.tokenAt(l1 - i);
            A[i % 2][0] = A[(i - 1) % 2][0] + 1;
            B.set(i, 0, EdOp.DELETE);
            for (int j = 1; j <= l2; ++j) {
                int n2 = a2.tokenAt(l2 - j);
                if (n1 == n2) {
                    A[i % 2][j] = A[(i - 1) % 2][j - 1];
                    B.set(i, j, EdOp.KEEP);
                } else {
                    A[i % 2][j] = min(A[(i - 1) % 2][j] + 1,
                            A[i % 2][j - 1] + 1,
                            A[(i - 1) % 2][j - 1] + 1);
                    if (A[i % 2][j] == A[(i - 1) % 2][j] + 1) {
                        B.set(i, j, EdOp.DELETE);
                    } else if (A[i % 2][j] == A[i % 2][j - 1] + 1) {
                        B.set(i, j, EdOp.INSERT);
                    } else {
                        B.set(i, j, EdOp.SUBSTITUTE);
                    }
                }
            }
        }
        return B;
    }
private static EditTable align ( TokenArray a1 , TokenArray a2 ) { int l1 = a1 . length ( ) ; int l2 = a2 . length ( ) ; int [ ] [ ] A ; EditTable B ; A = new int [ 2 ] [ l2 + 1 ] ; B = new EditTable ( l1 + 1 , l2 + 1 ) ; A [ 0 ] [ 0 ] = 0 ; B . set ( 0 , 0 , EdOp . KEEP ) ; for ( int j = 1 ; j <= l2 ; ++ j ) { A [ 0 ] [ j ] = A [ 0 ] [ j - 1 ] + 1 ; B . set ( 0 , j , EdOp . INSERT ) ; } for ( int i = 1 ; i <= l1 ; ++ i ) { int n1 = a1 . tokenAt ( l1 - i ) ; A [ i % 2 ] [ 0 ] = A [ ( i - 1 ) % 2 ] [ 0 ] + 1 ; B . set ( i , 0 , EdOp . DELETE ) ; for ( int j = 1 ; j <= l2 ; ++ j ) { int n2 = a2 . tokenAt ( l2 - j ) ; if ( n1 == n2 ) { A [ i % 2 ] [ j ] = A [ ( i - 1 ) % 2 ] [ j - 1 ] ; B . set ( i , j , EdOp . KEEP ) ; } else { A [ i % 2 ] [ j ] = min ( A [ ( i - 1 ) % 2 ] [ j ] + 1 , A [ i % 2 ] [ j - 1 ] + 1 , A [ ( i - 1 ) % 2 ] [ j - 1 ] + 1 ) ; if ( A [ i % 2 ] [ j ] == A [ ( i - 1 ) % 2 ] [ j ] + 1 ) { B . set ( i , j , EdOp . DELETE ) ; } else if ( A [ i % 2 ] [ j ] == A [ i % 2 ] [ j - 1 ] + 1 ) { B . set ( i , j , EdOp . INSERT ) ; } else { B . set ( i , j , EdOp . SUBSTITUTE ) ; } } } } return B ; }
Compute the table of basic edit operations needed to transform first into
 second
Compute the table of basic edit operations needed to transform first into second
// length of first  // length of second // distance table // edit operations // intialize  // Compute first row // Compute other rows