如何比较几乎相似的Java中的字符串? (字符串距离测量) [英] How to compare almost similar Strings in Java? (String distance measure)

查看:416
本文介绍了如何比较几乎相似的Java中的字符串? (字符串距离测量)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想比较两个字符串,并得到一些分数多少这些看起来一样。
例如。

I would like to compare two strings and get some score how much these look alike. For example "The sentence is almost similar" and "The sentence is similar".

我不熟悉Java中的现有方法,但对于PHP我知道 levenshtein函数

在Java中有更好的方法吗?

Are there better methods in Java?

推荐答案

Levensthein距离字符串相似度量。或者,更确切地说,必须做出多少改变,使得它们是相同的。

The Levensthein distance is a measure for how similar strings are. Or, more precisely, how many alterations have to be made that they are the same.

算法可在维基百科上的伪代码。将它转换为Java不应该是一个问题,但它不是内置在基类库中。

The algorithm is available in pseudo-code on Wikipedia. Converting that to Java shouldn't be much of a problem, but it's not built-in into the base class library.

维基百科有一些测量字符串相似性的算法。

Wikipedia has some more algorithms that measure similarity of strings.

这篇关于如何比较几乎相似的Java中的字符串? (字符串距离测量)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆