Obtain human-language scasp justifications over swiplserver

I am running swipl through swiplserver, and using the following query to get the scasp answers and justifications.

scasp(winner(G,P)),scasp_embed:scasp_justification(J,[]),with_output_to(string(JOut), scasp_just_human:human_justification_tree(J,[])).

The resulting JOut binding is using the default NLG method, so it generates statements like “winner holds for testgame and bob”, but it is not using the #pred statements in the loaded file, which would cause it to generate statements like “bob is the winner of testgame.” The same code in SWISH works fine, if I query ? winner(G,P)..

How can I modify the query to obtain the justification that is displayed in SWISH, using the natural language forms set out the #pred statements?

There are two potential problems. One is that if you load a s(CASP) file using Prolog consult/1, etc. you must be aware that if the file starts with #, the first line is taken as comment. This allows for #!/usr/bin/env swipl to make a Prolog file executable on POSIX systems. So, leave the first line blank.

Second, explicitly using scasp_embed probably gets the module context wrong. Doing all in the user module I get the desired results using

:- use_module(library(scasp)).
:- use_module(library(scasp/human)).

query_human_tree(Query, Human) :-
    scasp(Query, [tree(Tree)]),
        human_justification_tree(Tree, [])).

A simpler alternative might be to use the (demo) webserver. It is running at s(CASP) web server and its sources are in examples/dyncall/http.pl. Simply run as swipl examples/dyncall/http.pl. First pull the latest sCASP as there was a bug.

1 Like

Thanks very much, Jan. That solved the problem for me.