Skip to content

Instantly share code, notes, and snippets.

@trishagee
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trishagee/2b945905a1f4f5e6d87b to your computer and use it in GitHub Desktop.
Save trishagee/2b945905a1f4f5e6d87b to your computer and use it in GitHub Desktop.
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