确定两个字符串的相似性

2024-09-28 21:50:54 发布

您现在位置:Python中文网/ 问答频道 /正文

假设我有一个长字符串stru\ 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'

我要在长字符串中查找字符串str2:

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

str\u 2实际上存在于str\u 1中,但是str\u 2中的单词'second'在str\u 1中被写成'first'。唯一的区别是这一点

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


Tags: ofthe字符串on错误articlesectionthis
2条回答

你可以用一个简单的正则表达式,比如

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

a demo on regex101.com


然而,这似乎是一些文本/语料库的问题,所以你可以缩小句子的范围,并使用其他“模糊”逻辑。

你可以使用jaccard句子间的相似度来确定两个句子之间的相似度。 Link Here

相关问题 更多 >