Quantcast
Channel: Converting a string to a list of terms in prolog - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Converting a string to a list of terms in prolog

$
0
0

Background:I don't know very much about prolog but I've been playing around with a STRIPS planner concept (world of blocks) which works by itself when querying a plan in the SWI-PL terminal directly. I'm trying to create a web interface to the SWI-Prolog http server and would like to pass the goal state and the initial state as query string parameters to the Prolog server but it seems that the query string parameters are treated as strings and not really as a list of terms.

What I have so far:Following examples on http://www.pathwayslms.com/swipltuts/html/ I have been able to create and HTTP server and start it at port 9999 that accepts the goal state and initial state using a url:

http://localhost:9999/block_plan?init=[clear(2),clear(4),clear(b),clear(c),on(a,1),on(b,3),on(c,a)]&goal=[on(a,b)]

but I get a server 500 error: Out of global stack. Now I believe this is caused because the Initial and Goal variables are strings and not really terms since if I ignore the plan(Init,Goal,P,F) conjunction and replace it with plan([clear(2), clear(4), clear(b), clear(c), on(a,1), on(b,3), on(c,a)],[on(a,b)], Plan, FinState) the server responds with correct plan.

:- use_module(library(http/thread_httpd)).:- use_module(library(http/http_dispatch)).:- use_module(library(http/http_parameters)).:- use_module(library(uri)).:- http_handler(root(block_plan), get_block_planner_solution, []).server(Port) :-    http_server(http_dispatch, [port(Port)]).get_block_planner_solution(_Request) :-    format('content-type: text/plain~n~n'),    http_parameters(_Request, [ init(Init,[optional(false)]),                                goal(Goal,[optional(false)])                    ]),    format('Content-type: text/html~n~n', []),    format('<html><div>~n', []),    format('<div>Start State: ~w </div>~n', Init),    format('<div>Goal State: ~w </div>~n', Goal),%   plan([clear(2), clear(4), clear(b), clear(c), on(a,1), on(b,3), on(c,a)],[on(a,b)], Plan, FinState),        plan(Init,Goal,P,F),    format('<div>Plan: ~w </div>~n~n', [P]),    format('<table border=1>~n', []),    print_request(_Request),    format('~n</table>~n',[]),    format('</html>~n', []).    print_request([]).    print_request([H|T]) :-        H =.. [Name, Value],        format('<tr><td>~w<td>~w~n', [Name, Value]),        print_request(T).

The question is how do I take the inputs Initial and Goal and convert them to proper lists of terms that can be passed off to the STRIPS planner?

If this approach is not an optimal approach I am open to any other suggestions to interface a Web UI with the SWI prolog planner.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images