[Top][All Lists]

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

Re: [Info-gnuprologjava] Problems understanding the usage of the GNU Pro

From: Daniel Warzecha
Subject: Re: [Info-gnuprologjava] Problems understanding the usage of the GNU Prolog API
Date: Thu, 17 Feb 2011 17:36:13 +0100


yes, I found the manual, but it really didn't help me, I'm someone who learns best by example. The formatting on the manual is a bit off, also. 

So, by loading facts you mean load them from a prolog file? I wanted to use the library without resorting to loading prolog files at first, to see if I can programmatically build both knowledge base and rules. The second step will probably be building a prolog file to easily create the more complex rules.

ensureLoaded seems to load a prolog file and probably incorporate the facts etc. into the environment, am I right?

So if I have some Java strings which represent some atoms, e.g. "key1", is the following correct?
String keyAtom = "key1";
Environment prologEnv = new Environment();
AtomTerm.get(keyAtom); // creates the AtomTerm "key1" in the environment?

Or is there another way to put atoms in the environment?
Something like Environment.put(Term)? Environment.createFact(Term)?

Does stringToTerm(String,Environment) create a Term from the String and put it into the Environment?

And what about predicates (e.g. key/1) ? Is there a mechanism to let the environment know a predicate with an arity exists? Is the Predicate class used to do this?
Or rather, is the following correct?
String functor = "key";
int arity = 1;
Module mod = new Module();
Predicate keyPred = new Predicate(mod, CompoundTermTag.get(functor, arity));

And last but not least, to construct a CompoundTerm, e.g. key("key1"), what do I do?
Is the following correct?
String keyAtom = "key1";
String functor = "key";
CompoundTerm keyComp = new CompoundTerm(functor, keyAtom);

What do I have to do to incorporate the CompoundTerms and Predicates into the environment? Is this happening automatically?

Sorry for all the questions, I really don't understand the online manual yet.

Thanks for your help,
Daniel W. , Germany

2011/2/17 Daniel Thomas <address@hidden>

Have you found the GNU Prolog for Java manual?

You can load prolog facts and rules using the ensureLoaded see and

If you are asserting facts at runtime then you do this as normal in
Prolog using assertz or asserta or similar (having previously declared
it to by dynamic as usual in a prolog file which you then ensureloaded)
- you can find instructions on creating terms here:
or if you want to construct a term from a string (if you already have
the data you want as a string representation of a prolog term) then you
might want to use, gnu.prolog.vm.Environment) though it doesn't look like that has been documented properly yet. Sorry.

Apologies that you found the API documentation irritating. I will try to
get it improved in the next release.

I hope this helps,


On Thu, 2011-02-17 at 15:52 +0100, Daniel Warzecha wrote:
> Hello,
> I hope someone can help me. I'm trying to understand how to use the
> API in a correct way and am a bit overwhelmed.
> The background: I'm trying to parse messages in UML Sequence Diagrams
> and transform their facts, i.e. the message data to Prolog. Then I
> want to pose questions to the Prolog interpreter in regards to the
> knowledge base.
> Okay, sadly I don't understand how to do the following basic things
> with the API:
> 1. Tell the environment (if that's right) that some predicates exist:
> e.g. key/1 or knows/2 .
> 2. Tell Prolog that some facts exist: e.g. key("key1") or
> knows("attacker","key1")
> 3. Tell Prolog that certain rules exist: e.g.
> knows("attacker","message") :- encrypted("message","key1"),
> symmetricKey("key1").
> Can somebody please help me? The API docs only irritated me even more.
> Thanks in advance,
> Daniel W.

reply via email to

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