Merge branch 'nlp' of github.com:diogogithub/polynomialmani.pl into nlp
This commit is contained in:
commit
fc12b219c0
BIN
assignment-part2.pdf
Normal file
BIN
assignment-part2.pdf
Normal file
Binary file not shown.
38
polymani.pl
38
polymani.pl
@ -155,26 +155,42 @@ 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_string(user_input, "\n", "\r\t ", _, Stdin),
|
||||
split_string(Stdin, " ", "", R),
|
||||
(
|
||||
R = bye,
|
||||
write("See ya")
|
||||
R == ["bye"],
|
||||
write("See ya"),
|
||||
!
|
||||
;
|
||||
(
|
||||
nlp_understand(R, P, I),
|
||||
(
|
||||
nlp_understand(R, P, I),
|
||||
writeln("That's trivial:"),
|
||||
nlp_compute(P, I)
|
||||
;
|
||||
writeln("I didn't understand what you want.")
|
||||
writeln("I didn't understand what you want.")
|
||||
),
|
||||
polyplay
|
||||
).
|
||||
),
|
||||
!.
|
||||
|
||||
nlp_understand(R,P,I) :-
|
||||
nlp_understand(R, P, I) :-
|
||||
(
|
||||
R = simplify_x_squared,
|
||||
R == ["simplify", "x", "squared"],
|
||||
P = simplify,
|
||||
I = x^2
|
||||
;
|
||||
@ -182,6 +198,7 @@ nlp_understand(R,P,I) :-
|
||||
).
|
||||
|
||||
nlp_compute(simplify, P) :-
|
||||
!,
|
||||
simplify_polynomial(P, O),
|
||||
writeln(O).
|
||||
nlp_compute(_,_) :-
|
||||
@ -391,9 +408,6 @@ parse_command(op(*, TN, TP)) -->
|
||||
[by],
|
||||
parse_polynomial(TP).
|
||||
|
||||
|
||||
|
||||
|
||||
/*******************************
|
||||
* BACKEND *
|
||||
*******************************/
|
||||
|
Reference in New Issue
Block a user