Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all !!
I was trying to code a search program , where I will be able to search a given list of sentances with one sentence that that the user inputs and should display the results . that is the program should be able to get all the words in the sentence and try searching for all the following word combinationsto make different sentences and match it with the given sentances. Herre the sentence contains n words.
For example if we consider a 3 word sentence “hello world program “ it should try and match the given list with the following combinations of the sentances that are given below and then display the result of the matched sentances
Hello world program
Hello program world
World hello program
World program hello
Program hello world
Program world hello
What I know till now is that put the first word is kept constant then all the other n-1 words should be put in different possitions then change first word with any other n-1 word and all the remaining words should accupy the remaining n-1 possitions
I need help… can somebody help me with the algorithm for this thanks a ton in advance.
Posted

This is probably quite a bit more than you wanted, but it's a good place to start: Permutations, Combinations, and Variations using C# Generics[^]
 
Share this answer
 
Comments
shrav007 17-May-13 12:00pm    
hi! Griff.... thank a lot for that. It helped me very much and also helps me improve my algorithm even better....
OriginalGriff 17-May-13 12:04pm    
You're welcome - as I said it's a bit heavy duty for your example, but...
I would likely sort both sentences (lists of words) rather than try to find the permutations, though that could be done after a candidate is found.
You might also be able to use a variation of Levenshtein Distance using words rather than characters. You could then have some threshold distance for determining candidates.

http://en.wikipedia.org/wiki/Levenshtein_distance[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900