Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
How I can get the most appropriate sentence. (Look here the previous question)
For example:
(1) "Tell me the forecast of @city"
(2) "Tell me the forecast of @city for @date"
(3) "What is the weather in @city"
(4) "What is the weather in @city for @date"
And here is the sentence:
"What is the weather in New York"
I need to output (3).
For example:
"What is the weather in New York" -> 3.
"Tell me the forecast of Las Vegas for tomorrow" -> 2.
"What is the weather in Las Vegas for today" -> 4.
"Tell me the forecast of Washington" -> 1.
Posted
Comments
[no name] 1-Nov-14 11:25am    
As tried to imply in the comment in your previous question: Where is the Problem? It Looks very similar to an SQL with Parameters, therefore write a class which handles these Parameters....

Hmm, maybe you should look into the link I provided in my previous answer.
http://www.regular-expressions.info/[^]

But ok.

Regex to get the number: \((?<number>\d+)\)
 
Share this answer
 
v2
If you know the exact string then you can convert the string to array, and then extract the string at that index. The index of the city is known in the template string. Just extract the string at that index, make sure that the template is followed while typing the command.

Something like this,

C#
// get the variable
string toUser = "the string from the user";
// split
string[] strings = toUser.Split(' ');
// extract the letters at indices.


This would require a tough logic to get the city names and date. Most of the cities would include spaces in their names too.
 
Share this answer
 
v2

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