From aafef78100fe83e8e393da0aab657e58dbb3ee24 Mon Sep 17 00:00:00 2001 From: Diogo Cordeiro Date: Mon, 10 Dec 2018 17:37:34 +0000 Subject: [PATCH] Merged cenas com hugo --- polymani.pl | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/polymani.pl b/polymani.pl index 55cc0d6..43d2a74 100644 --- a/polymani.pl +++ b/polymani.pl @@ -155,15 +155,29 @@ is_number_in_predicate(C, F) :- /******************************* * NLP * *******************************/ + +/* DCG */ +separator --> ["and"]. +separator --> ["by"]. + +command --> ["show"]. +command --> ["multiply"]. +command --> ["simplify"]. +command --> ["add"]. +command --> ["forget"]. +expression(A,B,C):-writeln("oi"),writeln(A),writeln(B),writeln(C),writeln("bye"). +instruction(Left_expr, Right_expr) --> command, expression(Left_expr), separator, expression(Right_expr). + polyplay :- write("> "), - read(R), + read_line_to_codes(user_input, R), ( - R = bye, + writeln(R), + R = "bye", write("See ya") ; - ( - nlp_understand(R, P, I), + ( + nlp_understand(R, P, I), writeln("That's trivial:"), nlp_compute(P, I) ; @@ -172,9 +186,10 @@ polyplay :- polyplay ). -nlp_understand(R,P,I) :- +nlp_understand(R, P, I) :- + split_string(R, "\n", "\r\t ", RL), ( - R = simplify_x_squared, + RL = "simplify x squared", P = simplify, I = x^2 ; @@ -307,9 +322,6 @@ parse_expression(TL, TL-TR) --> parse_number(void, TR), { TR \= void, TL \= void %% ?- parse_expression(T, [two, times, times, two], _). %@ false. - - - /******************************* * BACKEND * *******************************/