【发布时间】:2020-02-06 06:35:07
【问题描述】:
假设我们在strs 中有 n 个字符串。您将所有字符串比较在一起,全排列 (n^2) 并构建一个 nxn 矩阵,其中每个单元格是 2 个字符串 (i, j) 之间的相似度分数。
如何更进一步并将它们分组到存储桶中?实际上,我希望这些字符串相似/落入一个桶中——但有可能一些新字符串可能不会,所以我想找到最相似的地方或重新计算桶。
public Map<String, List<String>> bucketIt(String[] strs) {
int[][] arr = new int[strs.length][strs.length];
for (int i = 0; i < strs.length; i++) {
for (int j = 0; j < strs.length; j++) {
arr[i][j] = getSimilarityScore(strs[i], strs[j]);
}
}
// How do I take the scores out of arr[][] and group the strings of strs into buckets.
}
我打算使用tdebatty/java-string-similarity 来计算分数。对所有桶使用阈值的解决方案也是可以接受的。
【问题讨论】:
-
到目前为止你尝试/研究了什么?分享您的想法/发现。
-
那么在计算了成对相似度之后,你想cluster他们吗?
标签: java algorithm sorting data-science computer-science