【发布时间】:2020-03-12 06:08:18
【问题描述】:
我有一个 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']
现在我想获取与标签问候语相对应的响应。 我该怎么做?
【问题讨论】:
-
检查classify_local函数,它必须使用“tag”键返回值,您也可以更改/添加“responses”键。
-
这能回答你的问题吗? Parsing Through Nested JSON Python
-
你期待什么输出?
-
patterns中的第三个元素是标签greeting、"Hello", "Good day"还是"Hello, good day!"? -
所以你想要响应中的第一个元素?
标签: python json python-3.x dictionary