Merge branch 'nlp' of github.com:diogogithub/polynomialmani.pl into nlp

This commit is contained in:
Hugo Sales 2018-12-17 14:41:14 +00:00
commit fc12b219c0
3 changed files with 26 additions and 12 deletions

BIN
assignment-part2.pdf Normal file

Binary file not shown.

View File

@ -155,26 +155,42 @@ is_number_in_predicate(C, F) :-
/******************************* /*******************************
* NLP * * 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 :- polyplay :-
write("> "), write("> "),
read(R), read_string(user_input, "\n", "\r\t ", _, Stdin),
split_string(Stdin, " ", "", R),
( (
R = bye, R == ["bye"],
write("See ya") write("See ya"),
!
; ;
( (
nlp_understand(R, P, I), nlp_understand(R, P, I),
writeln("That's trivial:"), writeln("That's trivial:"),
nlp_compute(P, I) nlp_compute(P, I)
; ;
writeln("I didn't understand what you want.") writeln("I didn't understand what you want.")
), ),
polyplay polyplay
). ),
!.
nlp_understand(R,P,I) :- nlp_understand(R, P, I) :-
( (
R = simplify_x_squared, R == ["simplify", "x", "squared"],
P = simplify, P = simplify,
I = x^2 I = x^2
; ;
@ -182,6 +198,7 @@ nlp_understand(R,P,I) :-
). ).
nlp_compute(simplify, P) :- nlp_compute(simplify, P) :-
!,
simplify_polynomial(P, O), simplify_polynomial(P, O),
writeln(O). writeln(O).
nlp_compute(_,_) :- nlp_compute(_,_) :-
@ -391,9 +408,6 @@ parse_command(op(*, TN, TP)) -->
[by], [by],
parse_polynomial(TP). parse_polynomial(TP).
/******************************* /*******************************
* BACKEND * * BACKEND *
*******************************/ *******************************/