src/main/java/eu/digitisation/distance/WordCompare.java
public static String wdiff(String first, String second) {
        MinimalPerfectHash mph = new MinimalPerfectHash(false); // case unsensitive  
        TokenArray a1 = new TokenArray(mph, first);
        TokenArray a2 = new TokenArray(mph, second);
        EditTable B = align(a1, a2);
        StringBuilder builder = new StringBuilder();

        int l1 = a1.length();
        int l2 = a2.length();
        int i = l1;
        int j = l2;

        while (i > 0 && j > 0) {
            switch (B.get(i, j)) {
                case KEEP:
                    builder.append(a1.wordAt(l1 - i)).append(" = ")
                            .append(a2.wordAt(l2 - j)).append('\n');
                    --i;
                    --j;
                    break;
                case DELETE:
                    builder.append(a1.wordAt(l1 - i)).append(" # []\n");
                    --i;
                    break;
                case INSERT:
                    builder.append("[] # ")
                            .append(a2.wordAt(l2 - j)).append('\n');
                    --j;
                    break;
                case SUBSTITUTE:
                    builder.append(a1.wordAt(l1 - i))
                            .append(" # ").append(a2.wordAt(l2 - j)).append('\n');
                    --i;
                    --j;
                    break;
            }

        }
        if (i > 0) {
            builder.append(a1.wordAt(l1 - i)).append(" # []\n");
            --i;
        }
        if (j > 0) {
            builder.append("[] # ")
                    .append(a2.wordAt(l2 - j)).append('\n');
            --j;
        }

        return builder.toString();
    }
/**
     * Show word-level differences based on a Levenshtein distance
     *
     * @param first the first text
     * @param second the second text
     * @return a report on the differences between files
     */
Show word-level differences based on a Levenshtein distance
@param first the first text
@param second the second text
@return a report on the differences between files
Show word - level differences based on a Levenshtein distance @param first the first text @param second the second text @return a report on the differences between files
public static String wdiff(String first, String second) {
        MinimalPerfectHash mph = new MinimalPerfectHash(false); 
        TokenArray a1 = new TokenArray(mph, first);
        TokenArray a2 = new TokenArray(mph, second);
        EditTable B = align(a1, a2);
        StringBuilder builder = new StringBuilder();
        int l1 = a1.length();
        int l2 = a2.length();
        int i = l1;
        int j = l2;
        while (i > 0 && j > 0) {
            switch (B.get(i, j)) {
                case KEEP:
                    builder.append(a1.wordAt(l1 - i)).append(" = ")
                            .append(a2.wordAt(l2 - j)).append('\n');
                    --i;
                    --j;
                    break;
                case DELETE:
                    builder.append(a1.wordAt(l1 - i)).append(" # []\n");
                    --i;
                    break;
                case INSERT:
                    builder.append("[] # ")
                            .append(a2.wordAt(l2 - j)).append('\n');
                    --j;
                    break;
                case SUBSTITUTE:
                    builder.append(a1.wordAt(l1 - i))
                            .append(" # ").append(a2.wordAt(l2 - j)).append('\n');
                    --i;
                    --j;
                    break;
            }
        }
        if (i > 0) {
            builder.append(a1.wordAt(l1 - i)).append(" # []\n");
            --i;
        }
        if (j > 0) {
            builder.append("[] # ")
                    .append(a2.wordAt(l2 - j)).append('\n');
            --j;
        }
        return builder.toString();
    }
public static String wdiff ( String first , String second ) { MinimalPerfectHash mph = new MinimalPerfectHash ( false ) ; TokenArray a1 = new TokenArray ( mph , first ) ; TokenArray a2 = new TokenArray ( mph , second ) ; EditTable B = align ( a1 , a2 ) ; StringBuilder builder = new StringBuilder ( ) ; int l1 = a1 . length ( ) ; int l2 = a2 . length ( ) ; int i = l1 ; int j = l2 ; while ( i > 0 && j > 0 ) { switch ( B . get ( i , j ) ) { case KEEP : builder . append ( a1 . wordAt ( l1 - i ) ) . append ( " = " ) . append ( a2 . wordAt ( l2 - j ) ) . append ( '\n' ) ; -- i ; -- j ; break ; case DELETE : builder . append ( a1 . wordAt ( l1 - i ) ) . append ( " # []\n" ) ; -- i ; break ; case INSERT : builder . append ( "[] # " ) . append ( a2 . wordAt ( l2 - j ) ) . append ( '\n' ) ; -- j ; break ; case SUBSTITUTE : builder . append ( a1 . wordAt ( l1 - i ) ) . append ( " # " ) . append ( a2 . wordAt ( l2 - j ) ) . append ( '\n' ) ; -- i ; -- j ; break ; } } if ( i > 0 ) { builder . append ( a1 . wordAt ( l1 - i ) ) . append ( " # []\n" ) ; -- i ; } if ( j > 0 ) { builder . append ( "[] # " ) . append ( a2 . wordAt ( l2 - j ) ) . append ( '\n' ) ; -- j ; } return builder . toString ( ) ; }
Show word-level differences based on a Levenshtein distance
 @param first the first text
 @param second the second text
 @return a report on the differences between files
Show word - level differences based on a Levenshtein distance @param first the first text @param second the second text @return a report on the differences between files
// case unsensitive  