问题
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