Last active
August 29, 2015 14:26
-
-
Save trishagee/2b945905a1f4f5e6d87b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int[][] computeLevenshteinAugustin(List<String> wordList, boolean parallel) { | |
final int LIST_SIZE = wordList.size(); | |
int[][] distances = new int[LIST_SIZE][LIST_SIZE]; | |
Stream<String> wordStream = wordList.stream(); | |
if (parallel) { | |
wordStream.parallel(); | |
} | |
wordStream.forEach(word -> { | |
int wordIndex = wordList.indexOf(word); | |
Stream<String> stream = wordList.subList(wordIndex + 1, wordList.size()).stream(); | |
if (parallel) { | |
stream.parallel(); | |
} | |
stream.forEach(wordToCompare -> { | |
int newWordIndex = wordList.indexOf(wordToCompare); | |
int lev = Levenshtein.lev(word, wordToCompare); | |
distances[wordIndex][newWordIndex] = lev; | |
distances[newWordIndex][wordIndex] = lev; | |
} | |
); | |
} | |
); | |
return distances; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment