Wednesday, March 4, 2015

Simple Renamer

Bored of renaming files?Do those filenames match a pattern such as dots instead of spaces and words like "etv","1080p"?Here's a solution:SimpleRenamer!Just run the .jar,drag and drop files/folders and click the button!Edit "Hotwords" to include more words you don't need in the final name.
Download
Source Code

Levenshtein distance on Java-Dynamic programming

In information theory and computer science, the Levenshtein distance is a string metric for measuring the difference between two sequences. Informally, the Levenshtein distance between two words is the minimum number of single-character edits.-Wikipedia
In practice, this distance can be used as the insertion key in a BK-tree used for auto-complete or spell checking, ie it is used in my JComplete project.
The dynamic programming approach in Java:

private int levenshtein(String string1, String string2) {

    int maxi = string1.length() + 1;
    int maxj = string2.length() + 1;
    int[][] distance = new int[maxi][maxj];

    for (int i = 1; i < maxi; i++) {
        distance[i][0] = i;
    }

    for (int j = 1; j < maxj; j++) {
        distance[0][j] = j;
    }

    for (int j = 1; j < maxj; j++) {
        for (int i = 1; i < maxi; i++) {
            if (string1.charAt(i - 1) == string2.charAt(j - 1)) {
                distance[i][j] = distance[i - 1][j - 1];
            } else {
                distance[i][j] = min(distance[i - 1][j] + 1,
                    distance[i][j - 1] + 1,
                    distance[i - 1][j - 1] + 1
                    );
            }
        }
    }
    return distance[maxi - 1][maxj - 1];
}