开发者

How much two strings are similar?(90%,100%,40%)

I have an input string and a collection of strin开发者_JS百科gs and I want to compare the input string and find the best choices to view.I want to write a function that tell me how much this two string are similar.have you any idea?


For 'short' string differences the algorithm you are searching for is called:

Levenshtein distance

http://en.wikipedia.org/wiki/Levenshtein_distance

For seeking differences in sentences you may wish to check for algorithms that solve the 'longest common sequence' problem.

One tool that does that is the (originally unix) 'diff'


Well, Perl has a String::Approx function which seems that does the job for you. But in general, you might want to take a look at: Levenshtein Distance algorithm.

Some other good resources are (Mostly explained in C#):

Comparing strings with tolerance
http://mihkeltt.blogspot.com/2009/04/dameraulevenshtein-distance.html
http://www.perlmonks.org/?node=Levenshtein%20distance%3A%20calculating%20similarity%20of%20strings
http://www.dotnetperls.com/levenshtein

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜