我一直在努力尝试在 Prolog 中编辑 Eliza 聊天机器人。每次我尝试编辑某些内容时,都会出现一个新错误。它是否受任何类型的编辑保护?
我使用 SWI-prolog 编辑器进行了编辑。问题是我试图在没有完全理解的情况下最小化代码。我正在尝试做一个简单的简短版本。所以,我可能会删除一些重要的东西!例如“my_char_type”。我得到的错误是“retract/1: No permission to modify static procedure `rules/1'”
有没有我能理解的小型聊天机器人的代码?
请帮忙 :'(
最佳答案
SWISH 拥有 simplest Eliza曾经,我有下面的旧代码,用于测试我的 Prolog interpreter .
这是一个示例 session
1 ?- eliza.
? i am hungry
how long have you been hungry ?
? very long
please go on
? bye
Goodbye. I hope I have helped you
true.
SWI-Prolog 测试版本,从 ELIZA.IL 下面移植(唉,SWISH 显然缺少像 read_line_from_codes 这样的 IO 原语,所以粘贴完整代码更简单)eliza :-
write('? '), read_word_list(Input), eliza(Input), !.
eliza([bye]) :-
write('Goodbye. I hope I have helped you'), nl.
eliza(Input) :-
pattern(Stimulus, Response),
match(Stimulus, Dictionary, Input),
match(Response, Dictionary, Output),
reply(Output),
!, eliza.
match([N|Pattern], Dictionary, Target) :-
integer(N), lookup(N, Dictionary, LeftTarget),
append(LeftTarget, RightTarget, Target),
match(Pattern, Dictionary, RightTarget).
match([Word | Pattern], Dictionary, [Word | Target]) :-
atom(Word), match(Pattern, Dictionary, Target).
match([], _Dictionary, []).
pattern([i,am,1],[how,long,have,you,been,1,'?']).
pattern([1,you,2,me],[what,makes,you,think,i,2,you,'?']).
pattern([i,like,1],[does,anyone,else,in,your,family,like,1,'?']).
pattern([i,feel,1],[do,you,often,feel,that,way,'?']).
pattern([1,X,2],[can,you,tell,me,more,about,your,X,'?']) :- important(X).
pattern([1],[please,go,on]).
important(father).
important(mother).
important(son).
important(sister).
important(brother).
important(daughter).
reply([Head | Tail]) :-
write(Head), write(' '), reply(Tail).
reply([]) :- nl.
lookup(Key, [(Key, Value) | _Dict], Value).
lookup(Key, [(Key1, _Val1) | Dictionary], Value) :-
Key \= Key1, lookup(Key, Dictionary, Value).
read_word_list(Ws) :-
read_line_to_codes(user_input, Cs),
atom_codes(A, Cs),
tokenize_atom(A, Ws).
旧代码:eliza和 rwl
关于prolog - 在 Prolog 中编辑 Eliza 聊天机器人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33179839/