2011-12-21 77 views
2

我的目标是从两段文字中找到类似的短语。在两段文字之间找到匹配的短语?

我知道常见的词将是一个问题。例如,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- 
+0

您希望我们对方法提供建议,您可以在方法看起来没问题的情况下显示代码 – RageZ 2011-12-21 09:39:55

回答

3

在谷歌快速搜索我看了this website包含解决问题的方法:

它通过寻找共同字的最长序列既 字符串,递归发现的最长的序列该字符串的剩余部分直到子字符串没有共同的字。 此时,它将剩余的新单词添加为插入,并将其余的旧单词添加为删除。

相关问题