[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Info-gnuprologjava] few questions about your package
From: |
Daniel Thomas |
Subject: |
Re: [Info-gnuprologjava] few questions about your package |
Date: |
Mon, 07 May 2012 15:29:12 +0100 |
Hello,
Sorry for the terrible delay.
So what you want to do is send a line of text into the standard input so
that read_words can pull it out?
You might be able to use use set_input and use
TextInputPrologStream(OpenOptions,Reader) with Environment#open to get
the standard input for prolog to point at something other than
System.in.
Alternatively use Environment#setDefaultInputStream before you construct
the Environment and that input stream will be automatically used instead
of System.in.
I hope that helps,
Daniel
On Sun, 2011-12-25 at 12:46 +0300, Noor Ahmed wrote:
> Hello again,
>
> I used the tips you gave me, but it's still not working. I am using
> WIN-Prolog, and in order to run the .pl code I have to write:
>
> ?- read_words(A).
> :- "line of text for processing".
>
> In the Java code, all I did was invoke the "read_words" method. And
> then, how can I send a line of text to the prolog code from Java? I
> can't use the line of text as an argument, I tried it and it won't
> work.
>
> Here's where I'm stuck at:
>
> Environment en = new Environment();
>
> en.ensureLoaded(AtomTerm.get("this://e-Q/src/pkginterface/code.pl"));
>
> Interpreter intr;
> Term ans = null;
>
> intr = en.createInterpreter();
>
>
> VariableTerm str = new VariableTerm(label.getText());
> VariableTerm arg1 = new VariableTerm("A");
>
> Term[] args = {arg1};
>
> CompoundTerm goalTerm = new
> CompoundTerm(AtomTerm.get("read_words"), args);
>
> en.runInitialization(intr);
>
> Goal goal =intr.prepareGoal(goalTerm);
> try {
> int rc = intr.execute(goal);
> } catch (PrologException ex) {
>
> Logger.getLogger(checkBalance.class.getName()).log(Level.SEVERE, null,
> ex);
> } //I need to send the line of text after invoking the
> read_words method
>
>
> ans = (AtomTerm) goalTerm.dereference();
>
> String check = ans.toString();
>
> Thank you in advance.
>
> Regards.
>
>
> On Wed, Dec 21, 2011 at 4:44 PM, Daniel Thomas <address@hidden>
> wrote:
> How exactly is it not working properly?
>
> I won't compile as 'label.getText()"."' is invalid and you
> don't need to
> add in "." like that which might be the problem you are
> getting when you
> create the goalTerm as you put a . in when you don't need to.
> The the
> CompoundTerm is not being correctly constructed as the first
> argument is
> the functor and so should just be "read_words" without any
> brackets or
> arguments - that is what args is for.
>
> I hope that helps,
>
> Daniel
>
>
> On Tue, 2011-12-20 at 21:35 +0300, Noor Ahmed wrote:
> >
> > Hello,
> >
> > I have a few questions about your package. The setup
> instructions are
> > not clear. I am using WIN-Prolog, and want to connect it to
> an
> > interface created in Java.
> > In WIN-Prolog I have to write "read_words" to run the
> program, which
> > takes a line of string -that comes from the interface- for
> processing.
> >
> > So this is the code I wrote, I'm very sure it's wrong
> because it's not
> > working properly:
> > "
> >
> > Environment en = new Environment();
> >
> >
>
> en.ensureLoaded(AtomTerm.get("/Users/NetBeansProjects/e-Q/src/pkginterface/code.pl"));
> >
> > Interpreter intr;
> > AtomTerm ans = null;
> >
> > intr = en.createInterpreter();
> >
> >
> > VariableTerm str = new
> VariableTerm(label.getText()".");
> >
> > Term[] args = {str};
> >
> > CompoundTerm goalTerm = new
> CompoundTerm("read_words(A).", args);
> >
> > en.runInitialization(intr);
> > try {
> > intr.runOnce(goalTerm);
> > } catch (PrologException ex) {
> >
> >
> Logger.getLogger(checkBalance.class.getName()).log(Level.SEVERE, null,
> > ex);
> > }
> >
> > ans = (AtomTerm) goalTerm.dereference();
> >
> > String check = ans.toString();
> > "
> >
> > Please can you reply soon. Thank you.
> >
> >
> > Regards.
> >
>
>
>
>
>
signature.asc
Description: This is a digitally signed message part
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [Info-gnuprologjava] few questions about your package,
Daniel Thomas <=