How about:
MyClass myClass = new MyClass();
String facts = myClass.myMethod();
String name = myClass.myName();
rete.executeCommand("(deffacts " + name + " \n"
+ facts
+ "\n"
+ ")");
The advantage (or disadvantage) of the above is that the facts will be
re-asserted upon reset.
-----Original Message-----
From: Bill Wheeler [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 08, 2001 1:20 PM
To: '[EMAIL PROTECTED]'; Bill Wheeler
Cc: [EMAIL PROTECTED]
Subject: RE: JESS: parsing multiple facts in a string
If you want to do something like that, then change the return statement to
something like
return(fact1 + "|" + fact2);
(assuming that the vertical bar can be used as a separator)
then, you can take that returned string and use a StringTokenizer to
separate the individual facts and then executeCommand( assert...) in a loop
as I mentioned before. 'MyClass' can be changed to use hard-coded facts or
read them from a file or get them from any type of I/O operation. Hope that
helps.
-----Original Message-----
From: Ryan Beckes [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 08, 2001 10:57 AM
To: Bill Wheeler
Cc: [EMAIL PROTECTED]
Subject: RE: JESS: parsing multiple facts in a string
Bill,
I think what you're asking for is an example java
class to call from jess. Anyway, here's my simple,
crude example.
Ryan
-------
class called by jess code below
public class MyClass {
public String myMethod() {
String fact1 = "(examplefact (slot1 data) (slot2
moredata) (slot3 evenmoredata))";
String fact2 = "(examplefact (slot1 data2) (slot2
moredata2) (slot3 evenmoredata2))";
return(fact1 + fact2);
}
}
-------
jess code that only asserts one fact returned by
MyClass.myMethod (therefore incorrect)
(defglobal ?*MyClass* = (new MyClass))
(defrule initialize
=>
(assert-string (call ?*MyClass* myMethod
)
)
)
-------
Jess code (suggested by Ernest Friedman-Hill) that
asserts all facts returned by MyClass.myMethod, but
requires making Jesp.loadFacts public in jess versions
previous to 6.0a4.
(defglobal ?*MyClass* = (new MyClass))
(defrule initialize
=>
(bind ?r (new java.io.StringReader (call ?*MyClass*
myMethod)))
(bind ?j (new jess.Jesp ?r (engine)))
(call ?j loadFacts)
)
--- Bill Wheeler <[EMAIL PROTECTED]> wrote:
> Do you have a sample string of these facts. I had
> to do something similar.
> It is a matter of parsing out the individual rules
> then doing a
>
> engine.executeCommand("(assert (factstring)");
>
> for each rule. Easier than doing an assert on the
> whole mess.
>
>
> -----Original Message-----
> From: Ryan Beckes [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, March 07, 2001 12:36 PM
> To: [EMAIL PROTECTED]
> Subject: JESS: parsing multiple facts in a string
>
>
> Hello,
> I have a java method that returns a String with
> multiple facts in that String. I would like to call
> that method and parse the facts it returns and
> assert
> all of them, similar to load-facts, but without the
> file.
> Please let me know if you need me to clarify.
>
> Thanks,
> Ryan
>
> EXAMPLE------
> Here's my example, which will assert a single fact
> from mymethod, which is not acceptable since
> mymethod
> returns a single string with multiple facts.
>
> (defglobal ?*myclass* = (new myclass))
>
> (defrule initialize
> =>
> (assert-string (call ?*myclass* mymethod
> )
> )
> )
>
>
> __________________________________________________
> Do You Yahoo!?
> Get email at your own domain with Yahoo! Mail.
> http://personal.mail.yahoo.com/
>
>
---------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe
> jess-users [EMAIL PROTECTED]'
> in the BODY of a message to [EMAIL PROTECTED],
> NOT to the
> list (use your own address!) List problems? Notify
> [EMAIL PROTECTED]
>
---------------------------------------------------------------------
__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/
---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list (use your own address!) List problems? Notify
[EMAIL PROTECTED]
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list (use your own address!) List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------