我需要比较2个字符串并计算它们的相似性,以过滤掉最相似字符串的列表.
例如.寻找"狗"会回来
例如.寻找"破解"将返回
我遇到过:
你知道更多的字符串相似度算法吗?
嘿,我正在使用Levenshteins算法来获得源和目标字符串之间的距离.
我也有从0到1返回值的方法:
/// <summary>
/// Gets the similarity between two strings.
/// All relation scores are in the [0, 1] range,
/// which means that if the score gets a maximum value (equal to 1)
/// then the two string are absolutely similar
/// </summary>
/// <param name="string1">The string1.</param>
/// <param name="string2">The string2.</param>
/// <returns></returns>
public static float CalculateSimilarity(String s1, String s2)
{
if ((s1 == null) || (s2 == null)) return 0.0f;
float dis = LevenshteinDistance.Compute(s1, s2); …Run Code Online (Sandbox Code Playgroud) 我们有一个大约150,000个单词的列表,当用户输入自由文本时,系统应该显示字典中的单词列表,这些单词与自由文本中的单词非常接近.
例如,用户输入:"我想在沃尔玛购买legoe玩具".如果字典包含"乐高","汽车"和"沃尔玛",系统应在列表中显示"乐高"和"沃尔玛"."沃尔玛"是显而易见的,因为它与句子中的单词相同,但"乐高"与"乐高"相似,也被提及.但是,没有什么与"Car"相似,所以没有显示单词.
显示列表应该是实时的,这意味着当用户输入句子时,屏幕上必须出现单词列表.有人知道一个很好的算法吗?
字典实际上包含可能包含空格的概念.例如,"乐高太空飞船".完美的解决方案也能识别这些多字概念.
任何建议表示赞赏.
我有一个简单的联系人数据库,但我遇到用户输入重复数据的问题.我已经实现了一个简单的数据比较,但不幸的是,输入的重复数据并不完全相同.例如,名字拼写不正确,或者一个人将放入"Bill Smith",另一个人将为同一个人输入"William Smith".
那么是否存在某种算法可以给出一个条目与另一个条目的相似程度的百分比?
按照这个在相关的线程评论,我想知道为什么基于Levenshtein距离方法比探测法更好.
是否有任何算法可以从字符串集合中找到与字符串最接近的匹配项?例如:
string_to_match = 'What color is the sky?'
strings = [
'What colour is the sea?',
'What colour is the sky?',
'What colour is grass?',
'What colour is earth?'
]
answer = method_using_string_matching_algorithm(string_to_match, strings)
answer # returns strings[1] 'What colour is the sky?'
Run Code Online (Sandbox Code Playgroud) algorithm ×6
string ×3
fuzzy-search ×2
c# ×1
comparison ×1
dictionary ×1
filtering ×1
match ×1
ranking ×1
soundex ×1
text ×1