【问题标题】:How to effectively compare two sentences and say both are equal如何有效地比较两个句子并说两者相等
【发布时间】:2013-11-02 15:28:38
【问题描述】:

我要比较两个句子。我要模式匹配技术

例如:

  The first thing you will do is choose a topic
  Vs
  The first thing you will do is choose a topic

对此的预期结果是:模式匹配

  The first thing  will do is choose a topic
  Vs
  The first thing you will do is choose  topic

在这种情况下,模式也匹配,但有一些错误。

这是一个简单的例子,我必须为复杂的句子匹配模式。

我在谷歌上搜索并得到了点阵法。这是正确的申请吗?还有其他方法可以找出两个句子是否相互匹配。

【问题讨论】:

  • @Arthur 我标记了它。它可以帮助那些不想在此站点上阅读离题问题的人。无论如何,它都需要版主的关注,因此它可以重新打开,然后顺利迁移。
  • 对于cross validated SE 来说可能是一个合适的问题。
  • SVM 中的字符串内核
  • 你找到解决办法了吗?如果那时请告诉我。我也处于类似情况,需要一些帮助。 ahmedshihab7@gmail.com

标签: pattern-recognition


【解决方案1】:

我在早期的一个项目中遇到了类似的问题,我通过以下算法解决了它。

I applied the "Longest Common Substring" algorithm and founded the longest common substring between the two strings.

Then I used "Levenshtein Distance algorithm" to compare my String A with the "Longest Common Substring" found from step 1.

If the result available from the algorithm mentioned in step 2 is above certain threshold, then it implies that the string A and String B matches.

【讨论】:

  • 我想找出两个字符串之间的区别。怎么办?
【解决方案2】:

假设您已经有一些方法可以解析出句子,并且您只关心句子是否相同而不是 它们如何不同,那么您可以简单地寻找字符串相等.考虑这个 Ruby 方法:

def sentences_eql? sentence_one, sentence_two
  sentence_one == sentence_two
end

当你给这个方法提供一对句子时,你会得到一个基于字符串比较的布尔结果。例如:

sentences_eql? 'The first thing you will do is choose a topic.',
               'The first thing you will do is choose a topic.'
#=> true

sentences_eql? 'The first thing you will do is choose a topic.',
               'The first thing you will do is choose   topic.'
#=> false

如果您关心差异的实际细节,您可以使用Levenshtein Distance 或使用最长公共子字符串算法创建单词差异。作为后者的示例,请参阅diff-lcs gem。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-31
    • 1970-01-01
    • 2022-01-10
    • 2014-09-20
    • 2016-06-25
    • 1970-01-01
    • 1970-01-01
    • 2021-05-23
    相关资源
    最近更新 更多