Reusing html and human output from sCASP

The modules that integrate sCASP into SWISH provide a very nice rendering of sCASP’s outputs: models and justifications. In the Logical English project, we wonder whether some of those modules could be reused to produce the same service for our explanatory system.

To test it, we installed an unsandboxed swish server and got this to work:

scasp(p(X), [tree(T)]),
scasp_just_html:html_justification_tree(T, [], Output, []),
html(Output).

So, we could actually call html_justification_tree//2 to use it (having it made into a safe predicate first in scasp) with our own raw trees put in that format.

But we wonder how to actually hook it into SWISH for the final output. Any general advise? Can we have this as a general service?

Thank you!

1 Like

I’m afraid I don’t really understand what you are after. The integration is scasp/swish.pl of the sCASP distro. The trick is that we add “bindings” to the answer that are not part of the query. Something similar is done for the CHR global constraint store. So, you have

 ?- ? p(X).

And that succeeds not only with e.g., X=1, but with something like

 X=1, _swish__scasp_model=<html string>, _swish__scasp_justification=<html string>

Then there is (unfortunately) some dedicated code in SWISH’s answer.js to deal with that. Ideally that should be generalized such that we can play this trick without modifying SWISH.

Hopefully that somewhat answers your question or allows you to be more precise on what you want to achieve. A good description on what interaction you try to achieve may help.

Thank you Jan. We just want to set that

_swish__scasp_justification=<html string>

with the html_string that correspond to the translation of a tree generated by LE. Not by scasp. For instance, from this combination:

 scasp_just_html:phrase(html_justification_tree(query-[goal_origin(p(a))-[]], []), Output), print_html(Output). 

we obtain:

<div class="scasp-justification">

<ul class="scasp-justification">

<li>

<div class="node"><span class="scasp-atom"><span class="human" title="goal_origin(p(a))"><span class="atom pos">goal_origin</span> holds for <span class="pl-compound pl-adaptive pl-level-0" data-arity="1" data-name="p"><span class="pl-functor pl-trigger">p<span class="pl-punct">(</span></span><span class="pl-compound-args"><span class="pl-compound-arg"><span class="pl-atom">a</span></span><span class="pl-compound-close pl-punct">)</span></span></span></span><span class="machine"><span class="atom pos"><span class="pl-compound pl-adaptive pl-level-0" data-arity="1" data-name="goal_origin"><span class="pl-functor pl-trigger">goal_origin<span class="pl-punct">(</span></span><span class="pl-compound-args"><span class="pl-compound-arg"><span class="pl-compound pl-adaptive" data-arity="1" data-name="p"><span class="pl-functor pl-trigger">p<span class="pl-punct">(</span></span><span class="pl-compound-args"><span class="pl-compound-arg"><span class="pl-atom">a</span></span><span class="pl-compound-close pl-punct">)<

/span></span></span></span><span class="pl-compound-close pl-punct">)</span></span></span></span></span></span></div>

</li>

<span class="machine">∎</span>

</ul>

</div>

What do we do to render it as scasp do with

_swish__scasp_justification=<html string>

?

Thank you.

I guess you need to rewrite scasp/swish.pl. The swish_trace:post_context/1 predicate there fills these pseudo bindings.

If you want to run this on the public swish this should be changed into something that dynamically figures out whether we are in normal sCASP or LE mode. I’m happy to merge something like that into the sCASP repo if reasonably clean.