得到最合适的句子 [英] Get the most appropriate sentence

查看:78
本文介绍了得到最合适的句子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能得到最合适的句子。 (查看上一个问题

例如:

(1)告诉我@city的预测

(2)告诉我预测of @city @date

(3) @city的天气是什么

(4) @city @date的天气是什么

以下是句子:

纽约的天气是什么

我需要输出(3)。

例如:

纽约的天气是什么 - > 3.

告诉我明天对拉斯维加斯的预测 - > 2.

今天拉斯维加斯的天气是什么 - > 4.

告诉我对华盛顿的预测 - > 1.

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.

推荐答案

嗯,也许您应该查看我之前回答中提供的链接。

http://www.regular-expressions.info/ [ ^ ]



但是确定。



正则表达式获取数字: \((?< number> \d +)\)
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+)\)


如果您知道确切的字符串,然后您可以将字符串转换为数组,然后在该索引处提取字符串。城市的索引在模板字符串中已知。只需在该索引处提取字符串,确保在输入命令时遵循模板。



这样的东西,



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,

// 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.


这篇关于得到最合适的句子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆