src/main/java/eu/digitisation/distance/Aligner.java
public static Element alignmentMap(String header1, String header2,
            String first, String second, CharMap map) {
        EditTable B = (map == null)
                ? alignTab(first, second)
                : alignTab(map.normalForm(first), map.normalForm(second));
        DocumentBuilder builder = new DocumentBuilder("table");
        Element table = builder.root();
        Element row;
        Element cell1;
        Element cell2;
        int l1;
        int l2;
        int len;
        int i;
        int j;
        String s1;
        String s2;

        // features
        table.setAttribute("border", "1");
        // content 
        row = builder.addElement("tr");
        cell1 = builder.addElement(row, "td");
        cell2 = builder.addElement(row, "td");
        cell1.setAttribute("width", "50%");
        cell2.setAttribute("width", "50%");
        cell1.setAttribute("align", "center");
        cell2.setAttribute("align", "center");
        builder.addTextElement(cell1, "h3", header1);
        builder.addTextElement(cell2, "h3", header2);
        row = builder.addElement("tr");
        cell1 = builder.addElement(row, "td");
        cell2 = builder.addElement(row, "td");

        l1 = first.length();
        l2 = second.length();
        i = l1;
        j = l2;
        while (i > 0 && j > 0) {
            switch (B.get(i, j)) {
                case KEEP:
                    len = 1;
                    while (len < i && len < j
                            && B.get(i - len, j - len) == EdOp.KEEP) {
                        ++len;
                    }
                    s1 = first.substring(l1 - i, l1 - i + len);
                    s2 = second.substring(l2 - j, l2 - j + len);
                    builder.addText(cell1, s1);
                    builder.addText(cell2, s2);
                    i -= len;
                    j -= len;
                    break;
                case DELETE:
                    len = 1;
                    while (len < i && B.get(i - len, j) == EdOp.DELETE) {
                        ++len;
                    }
                    s1 = first.substring(l1 - i, l1 - i + len);
                    builder.addTextElement(cell1, "font", s1)
                            .setAttribute("style", uStyle);
                    i -= len;
                    break;
                case INSERT:
                    len = 1;

                    while (len < j && B.get(i, j - len) == EdOp.INSERT) {
                        ++len;
                    }
                    s2 = second.substring(l2 - j, l2 - j + len);
                    builder.addTextElement(cell2, "font", s2)
                            .setAttribute("style", uStyle);
                    j -= len;
                    break;
                case SUBSTITUTE:
                    len = 1;
                    while (len < i && len < j
                            && B.get(i - len, j - len) == EdOp.SUBSTITUTE) {
                        ++len;
                    }
                    s1 = first.substring(l1 - i, l1 - i + len);
                    s2 = second.substring(l2 - j, l2 - j + len);
                    Element span1 = builder.addElement(cell1, "span");
                    Element span2 = builder.addElement(cell2, "span");
                    String id1 = "l" + i + "." + j;
                    String id2 = "r" + i + "." + j;
                    span1.setAttribute("title", s2);
                    span2.setAttribute("title", s1);
                    span1.setAttribute("id", id1);
                    span2.setAttribute("id", id2);
                    span1.setAttribute("onmouseover",
                            "document.getElementById('"
                            + id2 + "').style.background='greenyellow'");
                    span2.setAttribute("onmouseover",
                            "document.getElementById('"
                            + id1 + "').style.background='greenyellow'");
                    span1.setAttribute("onmouseout",
                            "document.getElementById('"
                            + id2 + "').style.background='none'");
                    span2.setAttribute("onmouseout",
                            "document.getElementById('"
                            + id1 + "').style.background='none'");
                    builder.addTextElement(span1, "font", s1)
                            .setAttribute("color", "red");
                    builder.addTextElement(span2, "font", s2)
                            .setAttribute("color", "red");
                    i -= len;
                    j -= len;
                    break;
            }
        }
        if (i > 0) {
            s1 = first.substring(l1 - i, l1);
            builder.addTextElement(cell1, "font", s1)
                    .setAttribute("style", uStyle);

        }
        if (j > 0) {
            s2 = second.substring(l2 - j, l2);
            builder.addTextElement(cell2, "font", s2)
                    .setAttribute("style", uStyle);
        }
        return builder.document().getDocumentElement();
    }
/**
     * Shows text alignment based on a pseudo-Levenshtein distance where
     * white-spaces are not allowed to be replaced with text or vice-versa
     *
     * @param header1 first text title for table head
     * @param header2 second text title for table head
     * @param first the first text
     * @param second the second text
     * @param map a CharMap for character equivalences
     * @return a table in XHTML format showing the alignments
     */
Shows text alignment based on a pseudo-Levenshtein distance where
white-spaces are not allowed to be replaced with text or vice-versa


Shows text alignment based on a pseudo - Levenshtein distance where white - spaces are not allowed to be replaced with text or vice - versa
public static Element alignmentMap(String header1, String header2,
            String first, String second, CharMap map) {
        EditTable B = (map == null)
                ? alignTab(first, second)
                : alignTab(map.normalForm(first), map.normalForm(second));
        DocumentBuilder builder = new DocumentBuilder("table");
        Element table = builder.root();
        Element row;
        Element cell1;
        Element cell2;
        int l1;
        int l2;
        int len;
        int i;
        int j;
        String s1;
        String s2;
        table.setAttribute("border", "1");
        row = builder.addElement("tr");
        cell1 = builder.addElement(row, "td");
        cell2 = builder.addElement(row, "td");
        cell1.setAttribute("width", "50%");
        cell2.setAttribute("width", "50%");
        cell1.setAttribute("align", "center");
        cell2.setAttribute("align", "center");
        builder.addTextElement(cell1, "h3", header1);
        builder.addTextElement(cell2, "h3", header2);
        row = builder.addElement("tr");
        cell1 = builder.addElement(row, "td");
        cell2 = builder.addElement(row, "td");
        l1 = first.length();
        l2 = second.length();
        i = l1;
        j = l2;
        while (i > 0 && j > 0) {
            switch (B.get(i, j)) {
                case KEEP:
                    len = 1;
                    while (len < i && len < j
                            && B.get(i - len, j - len) == EdOp.KEEP) {
                        ++len;
                    }
                    s1 = first.substring(l1 - i, l1 - i + len);
                    s2 = second.substring(l2 - j, l2 - j + len);
                    builder.addText(cell1, s1);
                    builder.addText(cell2, s2);
                    i -= len;
                    j -= len;
                    break;
                case DELETE:
                    len = 1;
                    while (len < i && B.get(i - len, j) == EdOp.DELETE) {
                        ++len;
                    }
                    s1 = first.substring(l1 - i, l1 - i + len);
                    builder.addTextElement(cell1, "font", s1)
                            .setAttribute("style", uStyle);
                    i -= len;
                    break;
                case INSERT:
                    len = 1;
                    while (len < j && B.get(i, j - len) == EdOp.INSERT) {
                        ++len;
                    }
                    s2 = second.substring(l2 - j, l2 - j + len);
                    builder.addTextElement(cell2, "font", s2)
                            .setAttribute("style", uStyle);
                    j -= len;
                    break;
                case SUBSTITUTE:
                    len = 1;
                    while (len < i && len < j
                            && B.get(i - len, j - len) == EdOp.SUBSTITUTE) {
                        ++len;
                    }
                    s1 = first.substring(l1 - i, l1 - i + len);
                    s2 = second.substring(l2 - j, l2 - j + len);
                    Element span1 = builder.addElement(cell1, "span");
                    Element span2 = builder.addElement(cell2, "span");
                    String id1 = "l" + i + "." + j;
                    String id2 = "r" + i + "." + j;
                    span1.setAttribute("title", s2);
                    span2.setAttribute("title", s1);
                    span1.setAttribute("id", id1);
                    span2.setAttribute("id", id2);
                    span1.setAttribute("onmouseover",
                            "document.getElementById('"
                            + id2 + "').style.background='greenyellow'");
                    span2.setAttribute("onmouseover",
                            "document.getElementById('"
                            + id1 + "').style.background='greenyellow'");
                    span1.setAttribute("onmouseout",
                            "document.getElementById('"
                            + id2 + "').style.background='none'");
                    span2.setAttribute("onmouseout",
                            "document.getElementById('"
                            + id1 + "').style.background='none'");
                    builder.addTextElement(span1, "font", s1)
                            .setAttribute("color", "red");
                    builder.addTextElement(span2, "font", s2)
                            .setAttribute("color", "red");
                    i -= len;
                    j -= len;
                    break;
            }
        }
        if (i > 0) {
            s1 = first.substring(l1 - i, l1);
            builder.addTextElement(cell1, "font", s1)
                    .setAttribute("style", uStyle);
        }
        if (j > 0) {
            s2 = second.substring(l2 - j, l2);
            builder.addTextElement(cell2, "font", s2)
                    .setAttribute("style", uStyle);
        }
        return builder.document().getDocumentElement();
    }
public static Element alignmentMap ( String header1 , String header2 , String first , String second , CharMap map ) { EditTable B = ( map == null ) ? alignTab ( first , second ) : alignTab ( map . normalForm ( first ) , map . normalForm ( second ) ) ; DocumentBuilder builder = new DocumentBuilder ( "table" ) ; Element table = builder . root ( ) ; Element row ; Element cell1 ; Element cell2 ; int l1 ; int l2 ; int len ; int i ; int j ; String s1 ; String s2 ; table . setAttribute ( "border" , "1" ) ; row = builder . addElement ( "tr" ) ; cell1 = builder . addElement ( row , "td" ) ; cell2 = builder . addElement ( row , "td" ) ; cell1 . setAttribute ( "width" , "50%" ) ; cell2 . setAttribute ( "width" , "50%" ) ; cell1 . setAttribute ( "align" , "center" ) ; cell2 . setAttribute ( "align" , "center" ) ; builder . addTextElement ( cell1 , "h3" , header1 ) ; builder . addTextElement ( cell2 , "h3" , header2 ) ; row = builder . addElement ( "tr" ) ; cell1 = builder . addElement ( row , "td" ) ; cell2 = builder . addElement ( row , "td" ) ; l1 = first . length ( ) ; l2 = second . length ( ) ; i = l1 ; j = l2 ; while ( i > 0 && j > 0 ) { switch ( B . get ( i , j ) ) { case KEEP : len = 1 ; while ( len < i && len < j && B . get ( i - len , j - len ) == EdOp . KEEP ) { ++ len ; } s1 = first . substring ( l1 - i , l1 - i + len ) ; s2 = second . substring ( l2 - j , l2 - j + len ) ; builder . addText ( cell1 , s1 ) ; builder . addText ( cell2 , s2 ) ; i -= len ; j -= len ; break ; case DELETE : len = 1 ; while ( len < i && B . get ( i - len , j ) == EdOp . DELETE ) { ++ len ; } s1 = first . substring ( l1 - i , l1 - i + len ) ; builder . addTextElement ( cell1 , "font" , s1 ) . setAttribute ( "style" , uStyle ) ; i -= len ; break ; case INSERT : len = 1 ; while ( len < j && B . get ( i , j - len ) == EdOp . INSERT ) { ++ len ; } s2 = second . substring ( l2 - j , l2 - j + len ) ; builder . addTextElement ( cell2 , "font" , s2 ) . setAttribute ( "style" , uStyle ) ; j -= len ; break ; case SUBSTITUTE : len = 1 ; while ( len < i && len < j && B . get ( i - len , j - len ) == EdOp . SUBSTITUTE ) { ++ len ; } s1 = first . substring ( l1 - i , l1 - i + len ) ; s2 = second . substring ( l2 - j , l2 - j + len ) ; Element span1 = builder . addElement ( cell1 , "span" ) ; Element span2 = builder . addElement ( cell2 , "span" ) ; String id1 = "l" + i + "." + j ; String id2 = "r" + i + "." + j ; span1 . setAttribute ( "title" , s2 ) ; span2 . setAttribute ( "title" , s1 ) ; span1 . setAttribute ( "id" , id1 ) ; span2 . setAttribute ( "id" , id2 ) ; span1 . setAttribute ( "onmouseover" , "document.getElementById('" + id2 + "').style.background='greenyellow'" ) ; span2 . setAttribute ( "onmouseover" , "document.getElementById('" + id1 + "').style.background='greenyellow'" ) ; span1 . setAttribute ( "onmouseout" , "document.getElementById('" + id2 + "').style.background='none'" ) ; span2 . setAttribute ( "onmouseout" , "document.getElementById('" + id1 + "').style.background='none'" ) ; builder . addTextElement ( span1 , "font" , s1 ) . setAttribute ( "color" , "red" ) ; builder . addTextElement ( span2 , "font" , s2 ) . setAttribute ( "color" , "red" ) ; i -= len ; j -= len ; break ; } } if ( i > 0 ) { s1 = first . substring ( l1 - i , l1 ) ; builder . addTextElement ( cell1 , "font" , s1 ) . setAttribute ( "style" , uStyle ) ; } if ( j > 0 ) { s2 = second . substring ( l2 - j , l2 ) ; builder . addTextElement ( cell2 , "font" , s2 ) . setAttribute ( "style" , uStyle ) ; } return builder . document ( ) . getDocumentElement ( ) ; }
Shows text alignment based on a pseudo-Levenshtein distance where
 white-spaces are not allowed to be replaced with text or vice-versa
Shows text alignment based on a pseudo - Levenshtein distance where white - spaces are not allowed to be replaced with text or vice - versa
// features // content 