Hi Karl,

This is pretty dangerous ground, as these representations are subject
to change. I'm not sure why I left some of these funcitons public,
since they're not really for public consumption. The best way to
assert any fact is to let Jess parse the string representation, using
executeCommand or assert-string or some such. The following will work
in Jess4.1b3, which it looks like you're using: 

(deffunction AssertFact ($?tokens)
  (assert-string (str-cat "( " $?tokens " )")))

(assert-fact (create$ foo bar baz))

In Jess 4.1b4, you can call AssertFact as written without the (create$).

If the fact you want to assert has external addresses in some of the
slots, you have to be a bit trickier, storing the objects someplace
where the string expression can get them, in a global variable,
perhaps, or using the nifty new (store) and (fetch) facility. You
may need to play tricks with 'eval' to get it to work. 

If you want to write the code in Java instead, you should take the
same approach rather than trying to build the ValueVector form of a
Fact. But a little explanation: the Fact constructor wants the head of
the fact as the first argument; you're passing "", which gives you the
blank space at the beginning of the printed-out fact. You want to
construct it with the AssertFact function's first argument. The
appearance of the double quotes is demonstrating, by the way, one of
the many ways in which Java's built-in tokenizing tools suck, and why
Jess no longer uses them at all. 

I think Karl Mueller wrote:
> 
> Thanx in advance for any ideas that you all might have!
> 
> 
> I am trying to do something fairly simple but for some reason I can't figure
> it out... I've got a mental block here and a fundamental misunderstanding I
> think? And right now my brain is fried! :^)
> 
> First of all I am adding my own user function with the purpose of parsing
> its parameters and creating an unordered fact which is simply composed of
> atoms. Thus, for example, I would like to call this function, AssertFact
> like this:
> (AssertFact "Inferred INT_INF"  34)
> 
> and have it result in the following fact:
> f-1 (Inferred INT_INF 34)
> 
> The fact that I'm getting instead is like this:
> f-1 ( "Inferred INT_INF" 34)   // Notice the space after the open-paren as
> well as the double quotes!
> 
> 
> Here is my code to attempt this rather simple feat:
> class AssertFact implements Userfunction
> {
>       int _name = RU.putAtom("AssertFact");
>       public int name() { return _name; }
> 
>       public Value call(ValueVector vv, Context context) throws ReteException
>       {
>               Fact fact = new Fact ("", RU.ORDERED_FACT, context.engine ()); // There
> must be a better way to create a new fact?
> 
>               for (int i = 1; i < vv.size(); i++)
>               {
>                       if (vv.get(i).type () == RU.STRING)
>                       {
>                               StringTokenizer stringTokenizer = new StringTokenizer 
>(vv.get
> (i).toString ());
>                               while (stringTokenizer.hasMoreTokens ())
> // Trying to de-volve this string into atoms!
>                                       fact.addValue (new Value 
>(stringTokenizer.nextToken (), RU.ATOM));
> 
> // This didn't work either!   fact.addValue (stringTokenizer.nextToken (),
> RU.ATOM);
> // Tried using a ValueVector directly like this but it didn't seem to work:
> // myValueVector.add (new Value (stringTokenizer.nextToken (), RU.ATOM);
> // Then at the end doing this: context.engine ().assert (myValueVector); //
> No luck on that either!
>                       }
>                       else
>                               fact.addValue (vv.get(i));
>               }
> 
>               context.engine ().assert (fact.factData ());
> 
>               return Funcall.TRUE();
>       }
> }
> 
> ---------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
> in the BODY of a message to [EMAIL PROTECTED], NOT to the
> list. List problems? Notify [EMAIL PROTECTED]
> ---------------------------------------------------------------------
> 
> 


---------------------------------------------------------
Ernest Friedman-Hill  
Distributed Systems Research        Phone: (510) 294-2154
Sandia National Labs                FAX:   (510) 294-2234
Org. 8920, MS 9214                  [EMAIL PROTECTED]
PO Box 969                  http://herzberg.ca.sandia.gov
Livermore, CA 94550

---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list. List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------

Reply via email to