info-gnuprologjava
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Info-gnuprologjava] Problem of Creating queries having a term invol


From: SUZUKI Hisao
Subject: Re: [Info-gnuprologjava] Problem of Creating queries having a term involving function symbols
Date: Thu, 26 Apr 2012 08:09:04 +0900

You can use \+ as a "not" predicate in ISO Prolog.

   \+ bird(cat)

See

  http://pauillac.inria.fr/~deransar/prolog/bips.html#notprovable

and see http://www.oki-osk.jp/esc/llsp/and3-gpj/24-03-28-102031.png
at http://www.oki-osk.jp/esc/llsp/and3-gpj.html
for my example in GNU Prolog for Java.

suzuki 

> -----Original Message-----
> From: address@hidden 
> [mailto:address@hidden 
> On Behalf Of Suman Roy
> Sent: Wednesday, April 25, 2012 8:59 PM
> To: Daniel Thomas
> Cc: Jagadish Koneti; address@hidden
> Subject: Re: [Info-gnuprologjava] Problem of Creating queries 
> having a term involving function symbols
> 
> Hi Daniel,
> 
> Sorry to bother you once more. We are still facing problem 
> when try to generate query with NOT (negation as failure) as below.
> 
> We are unable to create queries which involve NOT as negation 
> as failure like, "not( bird (cat) )". 
> In order to form such query we tried implementing in the way 
> as you mentioned previously .
> 
> Here is the code snippet  : 
> ------------------
> 
>           Term t1[] = {  AtomTerm.get ( " cat " )  } ; 
> 
>    CompoundTerm ct1=new CompoundTerm ( " bird ", t1 ) ;
> 
>    CompoundTerm goalTerm=new 
> CompoundTerm(CompoundTermTag.get("not",1),ct1);
> 
>             int rc = in.runOnce(goalTerm);
> 
> But we are getting a Java Exception :  "  Exception in thread 
> "main" java.lang.IllegalArgumentException: The goal is not 
> currently active  " .
> 
> We are actually stuck with our work. It will be great if you 
> can kindly provide some input to this. 
> Would greatly appreciate any help from you in this regard.
> 
> Best regards,
> --Suman
> 
> Suman Roy, Ph.D.
> Infosys LABS,
> Infosys Technologies Ltd.,
> Bangalore, India.
> Mob. +91 98860 23203 
> 
> 
> 
> -----Original Message-----
> From: Daniel Thomas [mailto:address@hidden
> Sent: Thursday, April 19, 2012 2:16 PM
> To: Suman Roy
> Cc: Jagadish Koneti; address@hidden
> Subject: RE: [Info-gnuprologjava] Problem of Creating queries 
> having a term involving function symbols
> 
> Hello,
> 
> Yes it is possible, you create a compound term using "," as 
> the functor.
> A more detailed response will have to wait until I have more time.
> 
> Daniel
> 
> On Thu, 2012-04-19 at 10:31 +0530, Suman Roy wrote:
> > Hi Daniel,
> > 
> > I have sent the following mail to you. Do you think will it 
> be possible to generate the following query using JAVA APIs, 
> other can we use something else?
> > 
> > Regards,
> > --Suman
> > 
> ----------------------------------------------------------------------
> > ----------------------------
> > 
> > Hello,
> > 
> > Thanks a lot. It worked. 
> > 
> > However, we are finding it difficult to generate query 
> which is a conjunction of literals! For example, we are 
> trying to generate the following query using the JAVA API:
> > 
> > :- isSonOf(brother(Paul), John), hasGrandson(John, _). 
> > 
> > We shall appreciate any suggestion from you.
> > 
> > Regards,
> > --Suman
> > 
> > Suman Roy, Ph.D.
> > Infosys LABS,
> > Infosys Technologies Ltd.,
> > Bangalore, India.     
> > Mob. +91 98860 23203
> > 
> > 
> > 
> > -----Original Message-----
> > From: Daniel Thomas [mailto:address@hidden
> > Sent: Saturday, April 14, 2012 1:21 PM
> > To: Suman Roy
> > Cc: Jagadish Koneti
> > Subject: RE: [Info-gnuprologjava] Problem of Creating 
> queries having a 
> > term involving function symbols
> > 
> > constructor
> > 
> CompoundTerm(gnu.prolog.term.CompoundTermTag,gnu.prolog.term.CompoundT
> > erm,gnu.prolog.term.Term[]) Note that you have a Term[] 
> rather than a 
> > Term as the last argument because t2 is a Term[] rather 
> than a Term. If you don't create it as an array but rather 
> than just as a Term then this should work.
> > 
> > Daniel
> > 
> > On Fri, 2012-04-13 at 16:07 +0530, Suman Roy wrote:
> > > Hi,
> > > 
> > > Thanks. 
> > > 
> > > We just tried. But still encountered the following problem.
> > > 
> > > Error : 
> > > 
> > > Cannot find symbol
> > > Symbol : constructor
> > > 
> CompoundTerm(gnu.prolog.term.CompoundTermTag,gnu.prolog.term.Compoun
> > > dT
> > > erm,gnu.prolog.term.Term[]) Location : class 
> > > gnu.prolog.term.CompoundTerm
> > > 
> > > Is there any way out of it?
> > > 
> > > Regards,
> > > --Suman
> > > 
> > > 
> > > Suman Roy, Ph.D.
> > > Infosys LABS,
> > > Infosys Technologies Ltd.,
> > > Bangalore, India.     
> > > Mob. +91 98860 23203
> > > 
> > > 
> > > -----Original Message-----
> > > From: Daniel Thomas [mailto:address@hidden
> > > Sent: Friday, April 13, 2012 4:01 PM
> > > To: Suman Roy
> > > Cc: Jagadish Koneti
> > > Subject: RE: [Info-gnuprologjava] Problem of Creating 
> queries having 
> > > a term involving function symbols
> > > 
> > > Ahh ok,
> > > 
> > > > CompoundTerm goalTerm=new CompoundTerm("isSonOf",ct1,t2);
> > > Which constructor are you trying to call? Your calling 
> signature is (String, Term, Term) but there is no constructor 
> with that signature, hence the compilation error.
> > > Try something like:
> > > CompoundTerm goalTerm=new
> > > CompoundTerm(CompoundTermTag.get("isSonOf",2),ct1,t2);
> > > Which should work modulo any typos.
> > > 
> > > I hope that helps,
> > > 
> > > Daniel
> > > 
> > > On Fri, 2012-04-13 at 11:53 +0530, Suman Roy wrote:
> > > > Hello,
> > > > 
> > > > Thanks a lot for your mail. However we are still facing 
> some problem with this.
> > > > 
> > > > 
> > > > As I wrote to you earlier that we are trying to create 
> query with a term having function symbols inside a predicate. 
> > > > 
> > > > For example, consider generating  a query  predicate " 
> > > > isSonOf(brother(Paul), John)" to the Prolog reasoner 
> with the help 
> > > > of the API ( "gnuprologjava-0.2.5 " ) . For this we have 
> > > > constructed a CompundTerm as " brother(paul )" by writing
> > > > 
> > > >   ""
> > > > Term t1[]={AtomTerm.get("paul")};
> > > >    CompoundTerm ct1 =new CompoundTerm("brother",t1);
> > > > 
> > > > ""
> > > > After that we are trying to write compound term which will 
> > > > encapsulate both " brother(paul) " and " john " by writing
> > > >  
> > > > "" 
> > > >  CompoundTerm goalTerm=new CompoundTerm("isSonOf",ct1,t2);
> > > > 
> > > > ""
> > > > 
> > > > But this kind of compoundTerm object inside a 
> compundTerm object is not allowed by the API ( 
> "gnuprologjava-0.2.5 " ) . hence we are getting compilation error .
> > > > 
> > > > Kindly suggest on how to use such compoundTerm object 
> within a compound term object with the help of  API .
> > > > 
> > > > Here is the code snippet.
> > > > 
> > > > 
> ==================================================================
> > > > ==
> > > > ==
> > > > ================
> > > > import gnu.prolog.term.AtomTerm;
> > > > import gnu.prolog.term.CompoundTerm; import 
> > > > gnu.prolog.term.CompoundTermTag; import gnu.prolog.term.Term; 
> > > > import gnu.prolog.vm.Environment; import 
> > > > gnu.prolog.vm.Interpreter; import 
> gnu.prolog.vm.PrologCode; import 
> > > > gnu.prolog.vm.PrologException; import java.util.logging.Level; 
> > > > import java.util.logging.Logger; import javax.swing.JOptionPane;
> > > > 
> > > > 
> > > > public class settingupQuery {
> > > > 
> > > >     public static void main (String []args){
> > > > 
> > > >             try {
> > > > 
> > > >             gnu.prolog.vm.Environment gve = new Environment();
> > > >             gve.ensureLoaded(AtomTerm.get("D:/jagadish 
> java/usecase_editr/src/usecase_editr/rules_01.pl"));
> > > >             Interpreter in = gve.createInterpreter();
> > > >             gve.runInitialization(in);
> > > > 
> > > >           Term t1[]={AtomTerm.get("paul")};
> > > >           Term t2[]={AtomTerm.get("John")};
> > > >           Term t3[]={AtomTerm.get("brother")};
> > > > 
> > > > 
> > > >             CompoundTerm ct1 =new CompoundTerm("brother",t1);
> > > >          CompoundTerm goalTerm=new 
> CompoundTerm("isSonOf",ct1,t2);
> > > >           
> > > >             int rc = in.runOnce(goalTerm);
> > > > 
> > > > 
> > > >            if (rc == PrologCode.SUCCESS || rc == 
> PrologCode.SUCCESS_LAST) {
> > > >                 System.out.println("Succesful execution ");
> > > >             }
> > > >            else {
> > > >                 System.out.println("Failed execution ");
> > > >            }
> > > > 
> > > > 
> > > > 
> > > >         } catch (PrologException ex) {
> > > >             
> Logger.getLogger(RAE.class.getName()).log(Level.SEVERE, null, ex);
> > > >         }
> > > > 
> > > >     }
> > > > 
> > > > }
> > > > 
> > > > 
> ==================================================================
> > > > ==
> > > > ==
> > > > =======================
> > > > 
> > > > Regards,
> > > > --Suman
> > > > 
> > > > Suman Roy, Ph.D.
> > > > Infosys LABS,
> > > > Infosys Technologies Ltd.,
> > > > Bangalore, India.     
> > > > Mob. +91 98860 23203
> > > > 
> > > > 
> > > > 
> > > > -----Original Message-----
> > > > From: Daniel Thomas [mailto:address@hidden
> > > > Sent: Thursday, April 12, 2012 5:55 PM
> > > > To: Suman Roy
> > > > Cc: address@hidden; Jagadish Koneti
> > > > Subject: Re: [Info-gnuprologjava] Problem of Creating queries 
> > > > having a term involving function symbols
> > > > 
> > > > Hello,
> > > > 
> > > > There shouldn't be any problem here, you construct 
> brother(Paul) and then use that when constructing 
> isSonOf(brother(Paul), John). The relevant documentation is:
> > > > 
> http://www.gnu.org/software/gnuprologjava/manual/Constructing-Terms.
> > > > ht
> > > > ml#Constructing-Terms
> > > > and
> > > > 
> http://www.gnu.org/software/gnuprologjava/api/gnu/prolog/term/
> CompoundTerm.html#CompoundTerm(gnu.prolog.term.AtomTerm, 
> gnu.prolog.term.Term[]) (or one of the similar constructors).
> > > > 
> > > > If you are having problems it would be helpful to know 
> what it is you are trying to do. What is the code you have 
> written that does not work?
> > > > There should not be any problems as the API does 
> support what you are trying to do - just possibly not the way 
> you are trying to do it.
> > > > 
> > > > I hope that helps,
> > > > 
> > > > Daniel
> > > > 
> > > > On Thu, 2012-04-12 at 16:59 +0530, Suman Roy wrote:
> > > > > Hello,
> > > > > 
> > > > >  
> > > > > 
> > > > > We have created some rule base in Prolog for some industrial 
> > > > > application. Now we want to create queries through 
> Java APIs and 
> > > > > subsequently fire them to Prolog interpreter on this 
> rule base.
> > > > > Specifically, we are using  "gnuprologjava-0.2.5 " API .  
> > > > > However, we are having problem creating queries which 
> has a term 
> > > > > involving function symbol inside a query predicate by 
> using this 
> > > > > API. For example, consider the following query,
> > > > > 
> > > > > :- isSonOf(brother(Paul), John). 
> > > > > 
> > > > > We cannot create the term brother(Paul) using this API, where 
> > > > > `brother' is a function symbol in the vocabulary.
> > > > > 
> > > > > Can you please suggest us how to create such terms using the 
> > > > > above API?
> > > > > 
> > > > >  
> > > > > 
> > > > > Regards,
> > > > > 
> > > > > --Suman
> > > > > 
> > > > > Suman Roy, Ph.D.
> > > > > Infosys LABS,
> > > > > 
> > > > > Infosys Technologies Ltd.,
> > > > > 
> > > > > Bldg.-19, # 44 Electronics City, Hosur Road, 
> Bangalore 560 100, India.
> > > > > Tel. +91 80 2852 0261 x 50850
> > > > >      +91 80 4116 3850 (D)
> > > > >      +91 80 2351 2373 (R)
> > > > >      +91 98860 23203 (M)
> > > > > Fax. +91 80 2852 0362
> > > > > E-mail address@hidden <mailto:address@hidden>
> > > > >        address@hidden <mailto:address@hidden>
> > > > > 
> > > > > 
> > > > > 
> > > > >  
> > > > > 
> > > > > 
> > > > > **************** CAUTION - Disclaimer ***************** This 
> > > > > e-mail contains PRIVILEGED AND CONFIDENTIAL 
> INFORMATION intended 
> > > > > solely for the use of the addressee(s). If you are not the 
> > > > > intended recipient, please notify the sender by 
> e-mail and delete the original message.
> > > > > Further, you are not to copy, disclose, or distribute this 
> > > > > e-mail or its contents to any other person and any 
> such actions are unlawful.
> > > > > This e-mail may contain viruses. Infosys has taken every 
> > > > > reasonable precaution to minimize this risk, but is 
> not liable 
> > > > > for any damage you may sustain as a result of any 
> virus in this 
> > > > > e-mail. You should carry out your own virus checks 
> before opening the e-mail or attachment.
> > > > > Infosys reserves the right to monitor and review the 
> content of 
> > > > > all messages sent to or from this e-mail address. 
> Messages sent to or from this e-mail address may be stored on 
> the Infosys e-mail system.
> > > > > ***INFOSYS******** End of Disclaimer ********INFOSYS***
> > > > 
> > > 
> > 
> 
> 
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]