如何使用pswip搜索prolog知识库



我想使用语音命令来搜索我的prolog知识库,我使用pswip,它工作,但我必须为每一个可能的查询写一个if语句,我有一个巨大的知识库超过100行,如果我这样做,我将不得不写100多个if语句。我想知道的是有没有更好的办法。例如,我可以编写一个语音激活的函数它只输入要搜索的查询并显示搜索返回的内容

我的意思是,如果我必须为所有事件写这个,那么使用pswip:

就没有意义了。
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)))'. 

任何建议吗?

忘记添加

prolog.consult("knowledgebase.pl")

开头

最新更新