Editing Eliza chatbot in Prolog

I am trying to edit Eliza chatbot in Prolog. every time I try to edit something, a new error appears. Is it protected by any editing?

I edited using the SWI prolog editor. The problem is that I'm trying to minimize the code without fully understanding it. I am trying to make a small short version. So, I could remove something important, maybe! for example, "my_char_type". The error I received is "retract / 1: no permission to modify the static procedure" rules / 1 '"

Is there any code for a little chatbot that I can understand?

Please, help: '(

+4
source share
2 answers

Prolog . , program.pl, :

foo(tabitha).
foo(darlene).

. ( ).

asserta/1, assertz/1 retract/1 retractall/1 . , , - :

?- asserta(baz(tabitha)).
true.

?- baz(X).
X = tabitha.

?- retract(baz(tabitha)).
true.

?- baz(X).
false.

, program.pl foo(tabitha), :

?- retract(foo(tabitha)).
ERROR: retract/1: No permission to modify static procedure `foo/1'
ERROR: Defined at /Users/fusion/program.pl:1

, foo/1 , , asserta/1 assertz/1 , :

:- dynamic foo/1.

, :

  • .
  • rules/1, .

, SWI-Prolog , make. .

№ 1, , , .

+1

SWISH , , -.

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, -, IO, read_line_from_codes, )

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.IL RWL.IL

+1

Source: https://habr.com/ru/post/1611997/


All Articles