【问题标题】:Finding matching phrases between two pieces of text?在两段文本之间寻找匹配的短语?
【发布时间】:2012-01-25 03:11:16
【问题描述】:

我的目标是从两段文本中找到相似的短语。

我知道常用词会有问题。例如,and thewe are the。在这种情况下,我认为过滤器是必要的。

我想知道这是否是一个好方法?这使用递归,如果找到匹配项,它会查看下一个单词是否也是匹配项,并继续直到没有匹配项。

  1. the cat is on the roof
  2. a man is on the stage

  A1 = [the, cat, is, on, the, roof]
  A2 = [a, man, is, on, the, stage]

  [the]: no match
  [cat]: no match
  [is]: match
  [is, on]: match
  [is, on, the]: match
  [is, on, the, roof]: no match
  [on]: match
  [on, the]: match
  [on, the, roof]: no match
  [the]: match
  [the, roof]: no match
  [roof]: no match
  -end-

【问题讨论】:

  • 您希望我们对方法提出建议,您可以显示代码,方法似乎很好

标签: php string recursion logic


【解决方案1】:

在 Google 上的快速搜索显示 this website 包含您的问题的解决方案:

它的工作原理是找到两者共有的最长单词序列 字符串,并递归地找到最长的序列 字符串的其余部分,直到子字符串没有共同的单词。 此时它将剩余的新词添加为插入,并且 剩余的旧词作为删除。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-18
    • 1970-01-01
    • 2022-01-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多