我在 Python 中工作,我决定分解并制作大量短语,以便与语音识别模块的结果进行比较。到目前为止,我有:
phrases = [
"what time is it",
"what's the weather",
"what's the date",
"hello",
"hi",
"what's up",
"how are you"
]
(我几分钟前才刚刚开始,所以我还没有太多......主要只是一个大纲)但无论如何,我想要一个像这样的函数......
def match(phrase):
#match_greatest will start at zero but continuously update if the string
#being compared has a higher percentage match
match_greatest = 0
#match will store the actual string that is closest
match = ""
for i in phrases:
#this is the part I need help with...
match_current = #somehow get the percentage that the argument phrase matches the phrase it's comparing to
#if the current phrase is a closer match than before, update it
if match_current > match_greatest:
match_greatest = match_current
match = i
return match
...举个例子,如果我调用 match("what time it a") 或 match("what time sat") - 这些是语音识别可能给出的误读示例 - 并使用我当前的设置短语,它将返回“现在几点”。