【发布时间】:2021-09-26 22:17:17
【问题描述】:
我想使用语音命令来搜索我的 prolog 知识库,我正在使用 pyswip,它可以工作,但我必须为每个可能的查询编写一个 if 语句,我有一个超过 100 行的庞大知识库,如果我这样做这样我就必须写超过 100 个 if 语句。我想知道是否有更好的方法。例如,我可以编写一个语音激活的函数,它只是将要搜索的查询放入并说出搜索返回的内容
我的意思是,如果我必须为所有事件写这个,那么使用 pyswip 没有意义:
if "son" in commands:
test12 = list(prolog.query("father(michael, B)"))
print(test12)
elif "daugher" in commands:
test12 = list(prolog.query("father(dory, B)"))
print(test12)
现在我尝试过这样的事情:
def prolog_search(A, B):
value1 = '('
value2 = ', '
value3 = 'X'
value4 = ')\"'
value5 = '\"'
tot_value = value5 + A + value1 + B + value2 + value3 + value4
tot_value = str(tot_value)
print(tot_value)
# tot_value would be "asd(sa, B)"
test12 = list(prolog.query(tot_value))
#test12 = list(prolog.query())
print(test12)
prolog_search("asd", "sa")
理论上是稍后用实际声音替换“asd”和“sa”,但现在我无法让它运行
运行后我得到这个错误:
raise PrologError("".join(["Caused by: '", query, "'. ", pyswip.prolog.PrologError: Caused by: '"asd(sa, X)"'. Returned: 'error(type_error(callable, b'asd(sa, X)'), context(/(pyrun, 2), Variable(74)))'.
有什么建议吗?
【问题讨论】:
标签: python python-3.x search prolog