Compare commits

...
This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.

2 Commits
nlp ... web

Author SHA1 Message Date
Diogo Cordeiro
dd4d3276c4 Add form 2018-12-23 19:33:42 +00:00
Diogo Cordeiro
515d5cb7c0 Start of a WEB framework 2018-12-23 18:28:30 +00:00

View File

@ -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
),
!.