Finding matching phrases between two pieces of text?

冷暖自知 提交于 2019-12-11 01:58:36

问题


My objective is to find similar phrases from two pieces of text.

I know that common words will be a problem. For example, and the we are the. In that case, I think a filter will be necessary.

I want to know if this was a good approach? This uses recursion, if it finds a match, it sees if the next word is also a match, and continues on till there s no match.

  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-

回答1:


A quick search on Google showed me this website containing the solution to your problem:

It works by finding the longest sequence of words common to both strings, and recursively finding the longest sequences of the remainders of the string until the substrings have no words in common. At this point it adds the remaining new words as an insertion and the remaining old words as a deletion.



来源:https://stackoverflow.com/questions/8587582/finding-matching-phrases-between-two-pieces-of-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!