我需要找到一种方法来查找与用户在各个变量变量列表中输入的字符串最相似的字符串。
L666485 = [u9027, m616, "CHELMSFORD, ", "Yes?"]
L666461 = [u9027, m616, "CHELMSFORD, ", "Thank you."]
L666460 = [u9029, m616, "CREALOCK, ", "The only reports of enemy activity have come from the direction of the Royal Kraal, at Ulundi."]
L666385 = [u9027, m616, "CHELMSFORD, ", "Our runners bare his dispatches, do they not?"]
例如变量的名称以L开头,后跟数字,然后是一个列表,其中包含(从左至右顺序)字符ID,电影ID,字符名称,行表示。 我需要搜索每个L变量列表项的行[3]
我正在使用python创建聊天机器人,该机器人使用康奈尔电影对话语料库进行搜索并找到与脚本中所说的内容相似的内容,
然后,代码应找到匹配的对话,然后找到下一行。
我调查了difflib.get_close_matches
,但据我所知,它仅搜索单个变量内的列表。
#List of variables
from movie_variables import *
def main():
#user input
user_input = input(":// ")
#This is something that I would like it to do
#use difflib.get_close_matches to search movie variables for something similar to user_input
matching_line = difflib.get_close_matches(user_input, movie_variables[3])
理想情况下,我希望它为类似的行输出变量ID。 L6551
答案 0 :(得分:0)
您可以在列表的开头添加变量名,然后像InvokeRequest request = null;
InvokeResult response = null;
for(String payload : payloads){
request = new InvokeRequest().withClientContext(clientContext).withFunctionName(functionName)
.withQualifier(alias).withPayload(payload).withInvocationType(InvocationType.Event);
response = lambdaClient.invoke(request);
}
一样返回它。