Re: Pengine ask and success template

Torbjörn Lager <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <CA+Y3JZg0ob6BU8AktdF+NnyAXXUmUy7p4XfVKM-qKMxRF9DnvQ@mail.gmail.com>
Hi Anne,

The template is modelled after the template (i.e. the first arg) in
the all-solutions predicatex. So, the answer to your question is,
e.g.:

            function handleCreate () {
                pengine.ask("q(X, Y)", {
                    template:'X-Y'
                });
            }

Then, you need to know the structure of the JSON being returned. There
is a little bit about that in the manual (mapping terms into JSON),
and another way to find out is

            function handleSuccess() {
                $('#out').html(JSON.stringify(this.data));
            }

Note that in this particular case, nothing is won by using a template.
You can instead do

            function handleCreate () {
                pengine.ask("q(X, Y)");
            }

Hope this helps!


Cheers,
Torbjörn

On Sat, Feb 8, 2014 at 11:21 PM, Anne Ogborn <[email protected]> wrote:
> I'm afraid your simple example is a tad too simple.
>
>
> Not entirely clear how I'm to transfer more than one piece of data.
>
> From the simple.html example, lets get the cartesian product of solutions to
> p and
> a new predicate r. Obviously in a real situation we're more likely to want
> somethign that
> has some correlation between the two, but this will suffice
>
>
>
>         <script type="text/x-prolog">
>
>   q(X,Y) :- p(X),r(Y).
>
>   p(a).
>   p(b).
>   p(c).
>   p(d).
>   p(e).
>   p(f).
>   p(g).
>
>   r(zip).
>   r(mort).
>
>         </script>
>         <script>
>             var pengine = new Pengine({
>                 oncreate: handleCreate,
>                 onsuccess: handleSuccess,
> onerror: handleSuccess
>             });
>             function handleCreate () {
>                 pengine.ask("q(X,_)", {     // <--  How can I get Y?
>                     template:'X'      // Whats this things format?
>                 });
>             }
>             function handleSuccess() {
>                 $('#out').html(this.data);
>             }
>         </script>
>     </head>
>     <body>
>         <div>?- q(X,Y).</div>
>         <div id="out"></div>
>
>         <button onclick="pengine.next()">Next</button>
>
>



-- 
Torbjörn Lager
Professor of General and Computational Linguistics
Department of Philosophy, Linguistics and Theory of Science
University of Gothenburg
Box 200, SE-405 30 Gothenburg, Sweden
Phone: +46317864962
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.