我有一个intent.json文件
{"intents": [
{"tag": "greeting",
"patterns": ["Hi there", "How are you", "Is anyone there?", "Hello", "Good day"],
"responses": ["Hello, thanks for asking", "Good to see you again", "Hi there, how can I help?"],
"context": [""]
},
{"tag": "goodbye",
"patterns": ["Bye", "See you later", "Goodbye", "Nice chatting to you, bye", "Till next time"],
"responses": ["See you!", "Have a nice day", "Bye! Come back again soon."],
"context": [""]
}
]
}
我有python文件,其中以下函数获取句子的意图,输出如下
classify_local('Hello, good day!')
输出为
['greeting']
现在,我想获取一个与标签问候相对应的响应。我怎样才能做到这一点?
问题来源:stackoverflow
如果您只是想从所有问候中获得标签“ greeting”标签的第一个答复,那就是,
json_value = {
"intents": [
{
"tag": "greeting",
"patterns": ["Hi there", "How are you", "Is anyone there?", "Hello", "Good day"],
"responses": ["Hello, thanks for asking", "Good to see you again", "Hi there, how can I help?"],
"context": [""]
},
{
"tag": "goodbye",
"patterns": ["Bye", "See you later", "Goodbye", "Nice chatting to you, bye", "Till next time"],
"responses": ["See you!", "Have a nice day", "Bye! Come back again soon."],
"context": [""]
}
]
}
for intent in json_value['intents']:
if intent['tag'] == 'greeting':
response = intent['responses'][0]
print(response)
回答来源:stackoverflow
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。