Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
dd4d3276c4 | ||
|
515d5cb7c0 |
100
polymani.pl
100
polymani.pl
@ -5,7 +5,7 @@
|
||||
*
|
||||
* polimani.pl
|
||||
*
|
||||
* Assignment 1 - Polynomial Manipulator
|
||||
* Assignment - Polynomial Manipulator
|
||||
* Programming in Logic - DCC-FCUP
|
||||
*
|
||||
* Diogo Peralta Cordeiro
|
||||
@ -40,6 +40,52 @@
|
||||
*/
|
||||
:- use_module(library(porter_stem)).
|
||||
|
||||
/*******************************
|
||||
* WEB SETTINGS *
|
||||
*******************************/
|
||||
|
||||
:- use_module(library(http/thread_httpd)).
|
||||
:- use_module(library(http/http_dispatch)).
|
||||
:- use_module(library(http/http_path)).
|
||||
:- use_module(library(http/html_write)).
|
||||
:- use_module(library(http/mimetype)).
|
||||
:- use_module(library(http/http_error)).
|
||||
:- use_module(library(settings)).
|
||||
:- use_module(library(error)).
|
||||
|
||||
:- setting(http:served_file_extensions,
|
||||
list(atom),
|
||||
[ html ],
|
||||
'List of extensions that are served as plain files').
|
||||
:- setting(http:port,
|
||||
integer,
|
||||
3040,
|
||||
'Default port').
|
||||
|
||||
% HTTP handler for pages
|
||||
:- http_handler(root(''), web_polyplay, []).
|
||||
|
||||
/*******************************
|
||||
* WEB SERVER *
|
||||
*******************************/
|
||||
|
||||
server :-
|
||||
setting(http:port, Port),
|
||||
server([port(Port)]).
|
||||
|
||||
server(Options) :-
|
||||
http_server(http_dispatch, Options).
|
||||
|
||||
/*******************************
|
||||
* WEB SERVICES *
|
||||
*******************************/
|
||||
|
||||
web_polyplay(_Request) :-
|
||||
format('Content-type: text/html~n~n'),
|
||||
format('Welcome to PolyMani!~n'),
|
||||
format('Ask me something:~n'),
|
||||
format('<form method="GET" action="process"><input type="text"></input></form>~n').
|
||||
|
||||
/*******************************
|
||||
* NLP *
|
||||
*******************************/
|
||||
@ -67,34 +113,34 @@ polyplay :-
|
||||
nl,
|
||||
!
|
||||
;
|
||||
(
|
||||
%% Parse the input into a tree
|
||||
parse_input(TIn, LA, NC),
|
||||
(
|
||||
%% Parse the input into a tree
|
||||
parse_input(TIn, LA, NC),
|
||||
(
|
||||
%% If the tree is empty, it means nothing was understood
|
||||
TIn == void,
|
||||
writeln("I didn't understand what you want."),
|
||||
writeln(NC)
|
||||
;
|
||||
(
|
||||
%% If there is unconsumed input, it means there was a syntatic error
|
||||
NC \== [],
|
||||
write("Syntax error in token: "),
|
||||
%% Take the head of the list
|
||||
cons(H, _, NC),
|
||||
write(H),
|
||||
nl
|
||||
;
|
||||
%% Otherwise, process the parse tree and execute the commands within
|
||||
process_input(TIn)
|
||||
)
|
||||
)
|
||||
%% If the tree is empty, it means nothing was understood
|
||||
TIn == void,
|
||||
writeln("I didn't understand what you want."),
|
||||
writeln(NC)
|
||||
;
|
||||
%% Parsing failed
|
||||
writeln("Could not parse input, so I didn't understand what you want.")
|
||||
),
|
||||
%% Go back to the beginning
|
||||
polyplay
|
||||
(
|
||||
%% If there is unconsumed input, it means there was a syntatic error
|
||||
NC \== [],
|
||||
write("Syntax error in token: "),
|
||||
%% Take the head of the list
|
||||
cons(H, _, NC),
|
||||
write(H),
|
||||
nl
|
||||
;
|
||||
%% Otherwise, process the parse tree and execute the commands within
|
||||
process_input(TIn)
|
||||
)
|
||||
)
|
||||
;
|
||||
%% Parsing failed
|
||||
writeln("Could not parse input, so I didn't understand what you want.")
|
||||
),
|
||||
%% Go back to the beginning
|
||||
polyplay
|
||||
),
|
||||
!.
|
||||
|
||||
|
Reference in New Issue
Block a user