src/main/java/eu/digitisation/distance/StringEditDistance.java
public static int[] alignment(String first, String second) {
        int i, j;
        int[][] A;

        // intialize
        A = new int[first.length() + 1][second.length() + 1];

        // Compute first row
        A[0][0] = 0;
        for (j = 1; j <= second.length(); ++j) {
            A[0][j] = A[0][j - 1] + 1;
        }

        // Compute other rows
        for (i = 1; i <= first.length(); ++i) {
            A[i][0] = A[i - 1][0] + 1;
            for (j = 1; j <= second.length(); ++j) {
                if (first.charAt(i - 1) == second.charAt(j - 1)) {
                    A[i][j] = A[i - 1][j - 1];
                } else {
                    A[i][j] = min(A[i - 1][j] + 1, A[i][j - 1] + 1,
                            A[i - 1][j - 1] + 1);
                }
            }
        }

        int[] alignments = new int[first.length()];
        java.util.Arrays.fill(alignments, -1);

        i = first.length();
        j = second.length();
        while (i > 0 && j > 0) {
            if (first.charAt(i - 1) == second.charAt(j - 1)
                    || A[i][j] == A[i - 1][j - 1] + 1) {
                alignments[--i] = --j;
            } else if (A[i][j] == A[i - 1][j] + 1) {
                --i;
            } else if (A[i][j] == A[i][j - 1] + 1) {
                --j;
            } else { // remove after debugging
                Messages.info(ErrorMeasure.class.getName() + ": Wrong code");
            }
        }

        return alignments;
    }
/**
     * Aligns two strings (one to one alignments with substitutions).
     *
     * @param first the first string.
     * @param second the second string.
     * @return the mapping between positions.
     * @deprecated use Aligner class
     */
Aligns two strings (one to one alignments with substitutions).
@param first the first string.
@param second the second string.
@return the mapping between positions.
@deprecated use Aligner class
Aligns two strings ( one to one alignments with substitutions ) . @param first the first string . @param second the second string . @return the mapping between positions . @deprecated use Aligner class
public static int[] alignment(String first, String second) {
        int i, j;
        int[][] A;
        A = new int[first.length() + 1][second.length() + 1];
        A[0][0] = 0;
        for (j = 1; j <= second.length(); ++j) {
            A[0][j] = A[0][j - 1] + 1;
        }
        for (i = 1; i <= first.length(); ++i) {
            A[i][0] = A[i - 1][0] + 1;
            for (j = 1; j <= second.length(); ++j) {
                if (first.charAt(i - 1) == second.charAt(j - 1)) {
                    A[i][j] = A[i - 1][j - 1];
                } else {
                    A[i][j] = min(A[i - 1][j] + 1, A[i][j - 1] + 1,
                            A[i - 1][j - 1] + 1);
                }
            }
        }
        int[] alignments = new int[first.length()];
        java.util.Arrays.fill(alignments, -1);
        i = first.length();
        j = second.length();
        while (i > 0 && j > 0) {
            if (first.charAt(i - 1) == second.charAt(j - 1)
                    || A[i][j] == A[i - 1][j - 1] + 1) {
                alignments[--i] = --j;
            } else if (A[i][j] == A[i - 1][j] + 1) {
                --i;
            } else if (A[i][j] == A[i][j - 1] + 1) {
                --j;
            } else { 
                Messages.info(ErrorMeasure.class.getName() + ": Wrong code");
            }
        }
        return alignments;
    }
public static int [ ] alignment ( String first , String second ) { int i , j ; int [ ] [ ] A ; A = new int [ first . length ( ) + 1 ] [ second . length ( ) + 1 ] ; A [ 0 ] [ 0 ] = 0 ; for ( j = 1 ; j <= second . length ( ) ; ++ j ) { A [ 0 ] [ j ] = A [ 0 ] [ j - 1 ] + 1 ; } for ( i = 1 ; i <= first . length ( ) ; ++ i ) { A [ i ] [ 0 ] = A [ i - 1 ] [ 0 ] + 1 ; for ( j = 1 ; j <= second . length ( ) ; ++ j ) { if ( first . charAt ( i - 1 ) == second . charAt ( j - 1 ) ) { A [ i ] [ j ] = A [ i - 1 ] [ j - 1 ] ; } else { A [ i ] [ j ] = min ( A [ i - 1 ] [ j ] + 1 , A [ i ] [ j - 1 ] + 1 , A [ i - 1 ] [ j - 1 ] + 1 ) ; } } } int [ ] alignments = new int [ first . length ( ) ] ; java . util . Arrays . fill ( alignments , - 1 ) ; i = first . length ( ) ; j = second . length ( ) ; while ( i > 0 && j > 0 ) { if ( first . charAt ( i - 1 ) == second . charAt ( j - 1 ) || A [ i ] [ j ] == A [ i - 1 ] [ j - 1 ] + 1 ) { alignments [ -- i ] = -- j ; } else if ( A [ i ] [ j ] == A [ i - 1 ] [ j ] + 1 ) { -- i ; } else if ( A [ i ] [ j ] == A [ i ] [ j - 1 ] + 1 ) { -- j ; } else { Messages . info ( ErrorMeasure . class . getName ( ) + ": Wrong code" ) ; } } return alignments ; }
Aligns two strings (one to one alignments with substitutions).
Aligns two strings ( one to one alignments with substitutions ) .
// intialize // Compute first row // Compute other rows // remove after debugging