算法 Java中的String简单模糊相似度算法
2018-07-20 来源:open-open
[Java]代码
public List<char[]> bigram(String input)
{
ArrayList<char[]> bigram = new ArrayList<char[]>();
for (int i = 0; i < input.length() - 1; i++)
{
char[] chars = new char[2];
chars[0] = input.charAt(i);
chars[1] = input.charAt(i+1);
bigram.add(chars);
}
return bigram;
}
[Java]代码
public double dice(List<char[]> bigram1, List<char[]> bigram2)
{
List<char[]> copy = new ArrayList<char[]>(bigram2);
int matches = 0;
for (int I = bigram1.size(); --i >= 0;)
{
char[] bigram = bigram1.get(i);
for (int j = copy.size(); --j >= 0;)
{
char[] toMatch = copy.get(j);
if (bigram[0] == toMatch[0] && bigram[1] == toMatch[1])
{
copy.remove(j);
matches += 2;
break;
}
}
}
return (double) matches / (bigram1.size() + bigram2.size());
}
标签: 代码
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
最新资讯
热门推荐