[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Info-gnuprologjava] FW: problem in creating complex prolog queries
From: |
Daniel Thomas |
Subject: |
Re: [Info-gnuprologjava] FW: problem in creating complex prolog queries , queries created by conjugating more that 5 simple queries . |
Date: |
Thu, 24 May 2012 11:55:05 +0100 |
On Thu, 2012-05-24 at 15:56 +0530, Suman Roy wrote:
> Hi,
>
> We have tried using PrepareGoal, But gnu prolog is showing an error message,
> “ Exception in thread "main" gnu.prolog.vm.PrologException:
> error(system_error,'java.lang.StackOverflowError') ” .
>
> Unfortunately, the documentation does not have these details about using
> PrepareGoal. It would be better if we know a little more about it.
It is documented here:
http://www.gnu.org/software/gnuprologjava/manual/Setup.html#Setup
and also (badly) here:
http://www.gnu.org/software/gnuprologjava/api/gnu/prolog/vm/Interpreter.html#prepareGoal(gnu.prolog.term.Term)
It might be cleaner to use CompoundTerm.getConjunction(Term head, Term
tail) to construct the goal. You might be nesting your conjunctions in
an odd way in that I think you are doing
','(','(','(p(x),q(y)),r(z)),s(l)) rather than
','(p(x),','(q(y),','(r(z),s(l))))
Maybe that is somehow causing the StackOverflowError. If you could get a
stacktrace of when this happens hten that would be great. Alternatively
if you attach a .java file I can just compile and run I could try and
get one.
Daniel
> Query intended to construct : :- p(x) , q(y) , r(z),s(l).
>
>
>
> rules_01.pl file :
> --------
> p (x).
> q(y).
> r(z).
> s(l ).
>
> Code snippet :
> -----------------
>
> Term t1[]={AtomTerm.get("x")};
> Term t2[]={AtomTerm.get("y")};
> Term t3[]={AtomTerm.get("z")};
> Term t4[]={AtomTerm.get("l")};
>
>
> CompoundTerm ct1=new CompoundTerm("p",t1);
> CompoundTerm ct2=new CompoundTerm("q",t2);
> CompoundTerm ct3=new CompoundTerm("r",t3);
> CompoundTerm ct4=new CompoundTerm("s",t4);
>
> String functor = ",";
> CompoundTerm mt1 = new CompoundTerm(functor, 2);
> mt1.args[0]=ct1;
> mt1.args[1]=ct2;
> CompoundTerm mt2 = new CompoundTerm(functor, 2);
>
> mt2.args[0]=mt1;
> mt2.args[1]=ct3;
>
> CompoundTerm mt3 = new CompoundTerm(functor, 2);
> mt3.args[0]=mt2;
> mt3.args[1]=ct4;
>
>
> Goal prepareGoal1 = in.prepareGoal(mt3);
>
>
> int chk =in.execute(prepareGoal1);
>
> if (chk == PrologCode.SUCCESS || chk == PrologCode.SUCCESS_LAST) {
> System.out.println("Succesful execution ");
> }
> else {
> System.out.println("Failed execution ");
> }
>
>
> Regards and thanks,
> --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: Wednesday, May 23, 2012 2:10 PM
> To: Suman Roy
> Cc: address@hidden; Jagadish Koneti
> Subject: Re: FW: problem in creating complex prolog queries , queries created
> by conjugating more that 5 simple queries .
>
> Sorry.
>
> I think that the error message is misleading and due to a bug in the way I
> used finally in my implementation of runOnce. Try using prepareGoal and then
> execute (which is essentially what runOnce does) as then you should hopefully
> get the correct error message when prepareGoal fails which should help with
> working out what the actual problem is.
>
> Daniel
>
> On Thu, 2012-05-17 at 14:12 +0530, Suman Roy wrote:
> >
> >
> > Hello ,
> >
> >
> >
> > I want to construct a complex prolog query with the help of “ gnu
> > prolog “ jar file , which will be conjugation of 5 simple prolog
> > queries .
> >
> >
> >
> > For instance : :- p (a) , q(b), r(c), s(d ), l(e ) .
> >
> >
> >
> > But gnu prolog is showing an error message , “ The goal is not
> > currently active ”. Can you please let me what can be done to create
> > such queries?
> >
> >
> >
> >
> >
> > rules_01.pl file :
> >
> > --------
> >
> > p (a).
> >
> > q(b).
> >
> > r(c).
> >
> > s(d ).
> >
> > l(e ) .
> >
> >
> >
> > Code snippet :
> >
> > -----------------
> >
> >
> >
> > Term t1[] = {AtomTerm.get("a")};
> >
> > Term t2[] = {AtomTerm.get("b")};
> >
> > Term t3[] = {AtomTerm.get("c")};
> >
> > Term t4[] = {AtomTerm.get("d")};
> >
> > Term t5[] = {AtomTerm.get("e”)};
> >
> >
> >
> > CompoundTerm ct1=new CompoundTerm("p",t1);
> >
> > CompoundTerm ct2=new CompoundTerm("q",t2);
> >
> > CompoundTerm ct3=new CompoundTerm("r",t3);
> >
> > CompoundTerm ct4=new CompoundTerm("s",t4);
> >
> > CompoundTerm ct5=new CompoundTerm("l",t5);
> >
> >
> >
> > String functor = ",";
> >
> > CompoundTerm mt1 = new CompoundTerm(functor, 2);
> >
> > mt1.args[0]=ct1;
> >
> > mt1.args[1]=ct2;
> >
> > CompoundTerm mt2 = new CompoundTerm(functor, 2);
> >
> >
> >
> > mt2.args[0]=mt1;
> >
> > mt2.args[1]=ct3;
> >
> >
> >
> > CompoundTerm mt3 = new CompoundTerm(functor, 2);
> >
> > mt3.args[0]=mt2;
> >
> > mt3.args[1]=ct4;
> >
> >
> >
> > CompoundTerm mt4 = new CompoundTerm(functor, 2);
> >
> > mt3.args[0]=mt3;
> >
> > mt3.args[1]=ct5;
> >
> >
> >
> >
> >
> > int rc = in.runOnce(mt4);
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > =======================================
> >
> >
> >
> >
> > **************** 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***
>
signature.asc
Description: This is a digitally signed message part