I will try to explain my objective with an example which will be easier to understand.


Suppose I have a sentence like "A B C D E F G H".(Each word seperated using single space).

I have a Database like:

> B C D E
> 
> A B
> 
> F G
> 
> C D E F G
> 
> ..


I need to find the maximum number of units from the database that match the sentence. The outcome should be such that "C D E F G" should be disocvered first instead of "B C D E" and after finding "C D E F G" only the remaining part of the sentence should be matched against the database. Any change/suggestion is welcomed.

The maximum match units can be anywhere in the sentence.The problem here is that I could not come up with an algorithm which can accomplish this task.