确定两个字符串的相似性

时间:2019-01-31 13:40:25

标签: python

让我说我有一个长字符串str_1:

**str_1** : 'Computer once meant a person who did computations, but now the term almost universally refers to automated electronic machinery. The first section of this article focuses on modern digital electronic computers and their design'

,我有一个字符串str_2在长字符串中寻找:

**str_2** : 'The second section of this article focuses on modern digital electronic computers and their design'

str_2实际上存在于str_1中,但是str_2中的单词“ second”在str_1中被写为“ first”,唯一的区别是。

我想要的是在带有某些错误的字符串中搜索句子。我想找到有一定百分比错误的str,然后检查错误。有没有办法做到这一点。谢谢。

2 个答案:

答案 0 :(得分:0)

您可以使用句子之间的jaccard相似度评分来确定两者之间的相似度。 Link Here

答案 1 :(得分:0)

您可以使用简单的正则表达式,例如

The (?:first|second) section of this article focuses on modern digital electronic computers and their design

请参见a demo on regex101.com


但是,这似乎是一些文本/语料库问题,因此您可以缩小句子范围并使用其他“模糊”逻辑。