<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">my &nbsp; &nbsp;assertDocument method uses all the data types Jess supports. The assertParameters is always just strings or a list of strings<div><br><div><div>On Sep 10, 2010, at 11:18 AM, Wolfgang Laun wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">So everthing is String or list of String? (What if your data contains numbers, where you'd like to use &gt; in patterns?)<br><br>Is there a stable relationship between key/slot and its type, i.e., scalar String or list of String?<br>
<br>You realize that a record of untyped fields (slots) is fundamentally different from an approach where data is bound to be stored in (necessarily) strongly typed fields of an object. There's no difficulty with writing similar code for storing values from a Map into an object of some class, but class fields must have fixed types.&nbsp; <br>
<br>-W<br><br><br><div class="gmail_quote">2010/9/10 Donald Winston <span dir="ltr">&lt;<a href="mailto:satchwinston@yahoo.com">satchwinston@yahoo.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div style="word-wrap: break-word;">This is what I'm doing:<div><br></div><div><div style="margin: 0px; color: rgb(78, 144, 114);">/* Assert unordered facts from the request parameter map. A deftemplate with matching id and&nbsp;</div>
<div style="margin: 0px; color: rgb(78, 144, 114);"><span style="white-space: pre-wrap;">        </span> * slots should already exist.&nbsp;</div><div style="margin: 0px; color: rgb(78, 144, 114);"><span style="white-space: pre-wrap;">        </span> */</div>
<div style="margin: 0px;"><span style="white-space: pre-wrap;">        </span><span style="color: rgb(147, 26, 104);">public</span> <span style="color: rgb(147, 26, 104);">void</span> assertParameterMap(String id, Map map, Rete engine) <span style="color: rgb(147, 26, 104);">throws</span> JessException {</div>
<div style="margin: 0px;"><span style="white-space: pre-wrap;">                </span>Fact fact = <span style="color: rgb(147, 26, 104);">new</span> Fact(id, engine);</div><div style="margin: 0px;"><span style="white-space: pre-wrap;">                </span>Iterator keys = map.keySet().iterator();</div>
<div style="margin: 0px;"><span style="white-space: pre-wrap;">                </span><span style="color: rgb(147, 26, 104);">while</span> (keys.hasNext() == <span style="color: rgb(147, 26, 104);">true</span>) {</div><div style="margin: 0px;">
<span style="white-space: pre-wrap;">                        </span>String key = (String)keys.next();</div><div style="margin: 0px;"><span style="white-space: pre-wrap;">                        </span><span style="color: rgb(147, 26, 104);">if</span> (<span style="color: rgb(0, 39, 204);">ID</span>.equals(key) == <span style="color: rgb(147, 26, 104);">true</span>) <span style="color: rgb(147, 26, 104);">continue</span>;</div>
<div style="margin: 0px;"><span style="white-space: pre-wrap;">                        </span>String[] paramValues = (String[])map.get(key);</div><div style="margin: 0px;"><span style="white-space: pre-wrap;">                        </span><span style="color: rgb(147, 26, 104);">if</span> (paramValues.<span style="color: rgb(0, 39, 204);">length</span> &gt; 1) {</div>
<div style="margin: 0px;"><span style="white-space: pre-wrap;">                                </span>ValueVector values = <span style="color: rgb(147, 26, 104);">new</span> ValueVector();</div><div style="margin: 0px;"><span style="white-space: pre-wrap;">                                </span><span style="color: rgb(147, 26, 104);">for</span>(String value : paramValues)</div>
<div style="margin: 0px;"><span style="white-space: pre-wrap;">                                        </span>values.add(<span style="color: rgb(147, 26, 104);">new</span> Value(value, RU.<span style="color: rgb(0, 39, 204);">STRING</span>));</div><div style="margin: 0px;">
<span style="white-space: pre-wrap;">                                </span>fact.setSlotValue(key, <span style="color: rgb(147, 26, 104);">new</span> Value(values, RU.<span style="color: rgb(0, 39, 204);">LIST</span>));</div><div style="margin: 0px;">
<span style="white-space: pre-wrap;">                        </span>}</div><div style="margin: 0px; color: rgb(147, 26, 104);"><span style="color: rgb(0, 0, 0);"><span style="white-space: pre-wrap;">                        </span></span>else</div><div style="margin: 0px;">
<span style="white-space: pre-wrap;">                                </span>fact.setSlotValue(key, <span style="color: rgb(147, 26, 104);">new</span> Value(paramValues[0], RU.<span style="color: rgb(0, 39, 204);">STRING</span>));</div><div style="margin: 0px;">
<span style="white-space: pre-wrap;">                </span>}</div><div style="margin: 0px;"><span style="white-space: pre-wrap;">                </span>engine.assertFact(fact);</div><div style="margin: 0px;"><span style="white-space: pre-wrap;">        </span>}</div>
<div style="margin: 0px;"><br></div><div style="margin: 0px;">I'm working on something similar for a jdom document object. I'm not using POJOs. I'm using a data structure. (technically they're objects because java is object oriented, but they're not "problem domain objects").</div>
<div><div></div><div class="h5"><div style="margin: 0px;"><br></div><div><div>On Sep 10, 2010, at 10:12 AM, Wolfgang Laun wrote:</div><br><blockquote type="cite">If you insert POJOs as facts in Jess, you'll have to write a <br>
&nbsp;&nbsp; (deftemplace X (declare (from-class X)))<br>and the fields available for pattern matching in rules rely on the JavaBeans convention.<br><br>I have (quite successfully) used POJOs resulting from unmarshalling an XML document (via JAXB) as facts, both in Drools and in Jess; most certainly without writing any "copycat" fact classes and tedious transformations.<br>

<br>As for globals: They play the same role in Drools as in Jess; in neither system are they part of the working memory.<br><br>I don't know what you could mean by a "standard fact class".<br><br>As for iterating over all fact objects in Drools' WM, Drools provides getObjects() in WorkingMemory; or you could set up a query and run this.<br>

<br>-W<br><br><br><div class="gmail_quote">On 10 September 2010 14:54, Donald Winston <span dir="ltr">&lt;<a href="mailto:satchwinston@yahoo.com" target="_blank">satchwinston@yahoo.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

I'm reviewing JBoss Rules (Drools) for an application I'm starting to build. It appears that the only way to assert facts is to use the insert(Object) method where the object is a bean using the proper naming conventions for it's properties. There also appears to be a way to use arbitrary objects using globals but do these end up in the fact base? It's disturbing to me that I have to create a bunch of classes whose sole purpose in life is to support the rule base. This is similar to using java server pages and having to create a bunch of classes just to support each page. That's why I don't use java server pages and use xsl transformations instead. I want to use my xml jdom document to represent my data and not have to create a bunch of beans. I can't seem to find anything in the api where I can assert facts without creating my own custom classes. There's no standard Fact class?<br>


<br>
I've been also experimenting with Jess and it provides an easy way for me to do this. I just iterate through my jdom document and create Fact objects and assert them. I can then execute the rules and then iterate through the updated fact base using engine.listFacts() and update my jdom document. It couldn't be easier or more natural. Is there an analogous way to do this in Drools?<br>


<br>
<br>
Thank you very much.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</blockquote></div><br>
_______________________________________________<br>rules-users mailing list<br><a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br><a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</blockquote></div><br></div></div></div></div><br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>
_______________________________________________<br>rules-users mailing list<br><a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>https://lists.jboss.org/mailman/listinfo/rules-users<br></blockquote></div><br></div></body></html>