prolog - 在 Prolog 中编辑 Eliza 聊天机器人

标签 prolog

我一直在努力尝试在 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).
旧代码:elizarwl

关于prolog - 在 Prolog 中编辑 Eliza 聊天机器人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33179839/

相关文章:

math - 将罗马数字翻译成阿拉伯数字

Prolog - ASP 'not' 到 Prolog 否定

prolog - 我需要 "base step"在 Prolog 中进行递归吗?

binary - Prolog 二进制加法问题?

Prolog间接关系

prolog - LearnPrologNow 编译器无法按预期工作

Prolog - 祖先谓词实现的 2 种方法

prolog - lib(ic) 的精确解

prolog - 给定现金金额和货币列表生成找零

prolog - 用 `last/2` 或 `append/3` 实现 `reverse/2`