如何衡量两个字符串之间的相似性? [英] How can I measure the similarity between 2 strings?
问题描述
由于两个字符串文本1
和文本2
public SOMEUSABLERETURNTYPE Compare(string text1, string text2)
{
// DO SOMETHING HERE TO COMPARE
}
例如:
-
第一个字符串:计算器
First String: StackOverflow
第二个字符串:StaqOverflow
Second String: StaqOverflow
返回:相似度为91%
返回可在%或类似的东西。
The return can be in % or something like that.
第一个字符串:简单的文本测试
First String: The simple text test
第二个字符串:复杂的文本测试
Second String: The complex text test
返回:值可以被视为等于
Return: The values can be considered equal
任何想法?什么是做到这一点的最好方法是什么?
Any ideas? What is the best way to do this?
推荐答案
有这样做的各种不同的方式。看一看在维基百科字符串相似性措施的链接,与其他算法的网页页面。
There are various different ways of doing this. Have a look at the Wikipedia "String similarity measures" page for links to other pages with algorithms.
我不的认为的任何这些算法采取的声音考虑,但是 - 所以STAQ溢出将如类似堆栈溢出作为斯托溢出,尽管第一个是多在发音方面是相似的。
I don't think any of those algorithms take sounds into consideration, however - so "staq overflow" would be as similar to "stack overflow" as "staw overflow" despite the first being more similar in terms of pronunciation.
我只是发现另一个页面这使得相当多的选择在...特别是,探测法算法(的Wikipedia )可能会接近你追求的。
I've just found another page which gives rather more options... in particular, the Soundex algorithm (Wikipedia) may be closer to what you're after.
这篇关于如何衡量两个字符串之间的相似性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!