Hi Graham,
The pattern
(dataobject $?data)
matches an ordered fact with head "dataobject". An ordered fact is one
with no slots; they look like
(grocery-list bread milk butter)
Your defclass, like all defclasses, is represented as *unordered*
facts -- facts with named slots. You can see an example of an
unordered dataobject fact below in your runtime trace; they look like
(grocery-list (items bread milk butter))
You can't have both ordered and unordered facts with the same
head. Since you define a template using defclass for dataobject facts,
all dataobject facts (and thus all patterns that match them) must use
explicit slot names. So in your first rule, there's a syntax error
because the variable $?data is not inside a named slot. In your second
rule, there's no preexisting deftemplate named "dataobj", so an
ordered one is implicitly created -- and the rule is therefore
syntactically correct.
Now, as far as what you're trying to accomplish: the OBJECT slot of
the dataobject template holds a reference to the actual Java Bean, and
a pattern binding would hold a reference to the fact. So either of
these rules is at least an approximation to what you wanted to
do. There is no Jess syntax for binding the values of all the slots to
a single variable, if in fact that's what your original rule is
intended to do.
(defrule test1 (dataobject (OBJECT ?o)) =>
(printout "Activated by " (?o toString) crlf))
(defrule test2 ?d <- (dataobject) =>
(printout "Activated by " (?d toString) crlf))
I think Graham Heyes wrote:
> I have an application using Jade and Jess together to monitor data from
> hardware. The data is encapsulated in a class Data which has the correct
> form to allow me to create use dynamic with definstance...
> jess.defclass("dataobject",
> "org.jlab.coda.agents.ontologies.subscriber.Data", null);
>
> then later...
>
> jess.definstance("dataobject", data, true, jess.getGlobalContext());
>
> ... everything behaves as expected and after running for a while (facts)
> produces a list of facts of the form...
>
> f-7 (MAIN::dataobject (_0 "current_units") (_1 "DC3") (_2 "mV") (_3
> "java.lang.String") (class <External-Address:java.lang.Class>) (device
> "DC3") (driverClass "java.lang.String") (name "current_units") (value
> "mV") (valueClass "java.lang.String") (OBJECT <External-
> Address:org.jlab.coda.agents.ontologies.subscriber.Data>))
>
> ... the problem begins if I try to apply a rule to the dataobjects.
>
> Jess> (defrule test (dataobject $?data)=>(printout t "Jess triggered "
> $?data crlf))
> Jess reported an error in routine Jesp.parseDefrule.
> Message: Expected '=>' .
> Program text: ( defrule test ( dataobject $?data ) at line 20.
> at jess.Jesp.parseError(Jesp.java:1583)
> at jess.Jesp.doParseDefrule(Jesp.java:907)
> at jess.Jesp.parseDefrule(Jesp.java:859)
> at jess.Jesp.parseSexp(Jesp.java:153)
> at jess.Jesp.parse(Jesp.java:61)
> at
> org.jlab.coda.agents.behaviours.BasicJess$1.run(BasicJess.java:254)
>
> ... this appears to be due to the fact that the rule is being applied to
> dataobject since the following, slightly modified rule is parsed
> correctly but (of course) is useless since there are no facts with the
> root dataobj.
>
> Jess> (defrule test (dataobj $?data)=>(printout t "Jess triggered "
> $?data crlf))
> TRUE
>
> ...this is all with Jess6.0 and jdk1.3.1
>
> Any ideas anyone?
> Graham
> -------------------------------------------------------------------------------
> Beware of Geeks bearing GIFS. http://www.jlab.org/coda Jefferson lab DAQ
> group
---------------------------------------------------------
Ernest Friedman-Hill
Distributed Systems Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
Org. 8920, MS 9012 [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
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------