JESS: Print Jess rule in detail using Java code

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

JESS: Print Jess rule in detail using Java code

Vu Le-2

In my Java code, I have:

            Rete engine = new Rete();

engine.batch("myrule.clp");     

Now how do I print out, by Java code, LHS and RHS of the rules that are in "myrule.clp"?

I had tried to use this to print the LHS:

for (Iterator iterator = engine.listDefrules(); iterator.hasNext();) {

            Defrule rule = (Defrule) iterator.next();

            for (Iterator iterator2 = rule.getNodes(); iterator2.hasNext();) {

                  Node node = (Node) iterator2.next();

                  if (node.getNodeType() == 1) {

                        System.out.println("--" + node);

                  }

            }

            System.out.println("Action: " + rule.getAction(0));

      }

But the output looks really annoying.

Can anyone help me?

Reply | Threaded
Open this post in threaded view
|

Re: JESS: Print Jess rule in detail using Java code

Friedman-Hill, Ernest
See http://www.jessrules.com/jess/docs/71/library.html#prettyprinting


On Apr 23, 2011, at 1:47 PM, Vu Le wrote:

> In my Java code, I have:
>             Rete engine = new Rete();
> engine.batch("myrule.clp");
> …
> Now how do I print out, by Java code, LHS and RHS of the rules that  
> are in "myrule.clp"?
> I had tried to use this to print the LHS:
> for (Iterator iterator = engine.listDefrules(); iterator.hasNext();) {
>             Defrule rule = (Defrule) iterator.next();
>             for (Iterator iterator2 = rule.getNodes();  
> iterator2.hasNext();) {
>                   Node node = (Node) iterator2.next();
>                   if (node.getNodeType() == 1) {
>                         System.out.println("--" + node);
>                   }
>             }
>             System.out.println("Action: " + rule.getAction(0));
>       }
> But the output looks really annoying.
> Can anyone help me?

---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences          Phone: (925) 294-2154
Sandia National Labs
PO Box 969, MS 9012                            [hidden email]
Livermore, CA 94550                             http://www.jessrules.com






--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [hidden email]'
in the BODY of a message to [hidden email], NOT to the list
(use your own address!) List problems? Notify [hidden email].
--------------------------------------------------------------------