Re: Accessing instantiated variable in call predicate

Feliks Kluzniak <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
Hi,

I am afraid you don't provide nearly enough information, so we cannot give very specific advice. 

Offhand, I can think of three ways of addressing this sort problem:

1. The translator from Sent to Logic Form could produce the list of "interesting" variables that are going to be instantiated by executing LogicForm. Say: the result of s/3 could be of the form
translated( LogicForm, Variables ).   Then your clause would be something like:

    getAtom( Sent, Variables ) :-  
        s( translated( LogicForm, Variables ), Sent, [] ),
        call( LogicForm ).

and the second argument of getAtom/2 would magically have what you want upon exit.


2. If modifying the translator would be too inconvenient, and the number of possible forms produced by s/3 is very limited, then you could write a procedure ("predicate") extract/2 that handles the forms, along the following lines:

    extract( to( chair, A ), [ A ] ).
    extract( from_to( table, A, B ), [ A, B ] ).
    etc.

Again, adding an invocation of this to getAtom would do the trick.


3. If _all_ the variables in a "logic form" are "interesting", then there is a simple general solution: just extract the uninstantiated variables from the LogicForm (before calling it).

    getAtom( Sent, Variables ) :-
        s( LogicForm, Sent, [] ),
        term_variables( LogicForm, Variables ),
	call( LogicForm ).    

(Please notice that term_variables/2 is built-in.)

Hope this helps,
-- Feliks


On Jul 21, 2013, at 12:48, Emanuele Bastianelli <[email protected]> wrote:

> Hi to all,
> 
> i've just started using 'call' predicate, and i was wondering how i can
> access the variable that are instantiated in the predicate that is passed
> to the 'call' predicate as variable.
> For example, this is my case. I've this predicate:
> 
> getAtom(Sent) :- s(LogicForm,Sent,[]), call(LogicForm).
> 
> Now, LogicForm indeed represent the logic form of the analyzed sentence.
> Through the predicate 'call', I execute the query represented by the logic
> form on my KB. Again, the logic form represent a predicate, as:
> 
> to(chair,A)
> 
> where A is the variable that will be instantiated with the value I need to
> retrieve.
> Then, how can i access that value starting from the getAtom predicate? All
> that I can get is the instatiation of the variable LogicForm, as
> 
> LogicForm = to(chair, chair_1)
> 
> while* *I want to get just the chair_1 atom instance.
> 
> Thank you.
> EB
> -------------- next part --------------
> HTML attachment scrubbed and removed
> _______________________________________________
> SWI-Prolog mailing list
> [email protected]
> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
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.