Good afternoon,
For project purpose, I need to create a chat with the user, then save a music genre based on an emotion the user will type. I came up with this simple solution:
%suggested musical genre based on emotions
genre(['jazz,classical'],M) :- M = sad.
genre(['pop,rock'],M) :- M = happy.
genre(['haevy metal,hard rock'],M) :- M = angry.
chat(G) :-
write('How do you feel?'),
read(M),
genre(G,M).
Idea: the predicate genre simply tells what kind of genre is suggested based on an emotion (i.e, if the user types ‘sad’, the variable G
must be equal to ['jazz, classical']
).
Having said this, I need also to include the chat(G)
predicate in a loop. Now, I tired to do the classical solution using this peace of code:
loop(0,G).
loop(N,G) :-
chat(G),
loop(N1,G1),
N1 is N-1,
not(G1=G).
but in this case I came up with errors and, if working, the values of G are not saved somewhere. I don’t know if I explained the problem correctly, I hope so. In short, I need to loop N
times, over the chat(G)
predicate and save all the values that the predicate genre(_,_)
tells me. All for consult the prolog file with python, call the chat(G)
predicate and save the values on a python list.