如何测量2个字符串之间的相似性? [英] How can I measure the similarity between 2 strings?

查看:139
本文介绍了如何测量2个字符串之间的相似性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定两个字符串 text1 text2

public SOMEUSABLERETURNTYPE Compare(string text1, string text2)
{
     // DO SOMETHING HERE TO COMPARE
}

示例:


  1. 第一个字符串:StackOverflow

  1. 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 overflow stack overflowasstaw overflow尽管第一个在发音方面更相似。

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.

我刚刚发现另一个页面,它提供了更多的选项...特别是 Soundex 算法( 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.

这篇关于如何测量2个字符串之间的相似性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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