<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:st1="urn:schemas-microsoft-com:office:smarttags" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]--><o:SmartTagType
namespaceuri="urn:schemas-microsoft-com:office:smarttags" name="City"/>
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
name="place"/>
<!--[if !mso]>
<style>
st1\:*{behavior:url(#default#ieooui) }
</style>
<![endif]-->
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:blue;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:Arial;
        color:navy;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
-->
</style>
</head>
<body lang=EN-US link=blue vlink=blue>
<div class=Section1>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>I was hoping the recent conversation
regarding maps this would come up, but so far it hasn’t.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>How do I check for conditions on the
element referenced in the map? <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>So given the following scenario: <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>SearchItem is the item being searched for
by the user <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Item has the attributes: UPC (String) and
OnSale (Boolean)<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>StockRoom has an attribute of stock which
is Stock = HashMap<String, Item> (key value is UPC)<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Now let’s say I want to write a rule
that says, “If the provided Item is in Stock, and on <st1:City w:st="on"><st1:place
w:st="on">Sale</st1:place></st1:City>.. purchase it”<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>rule “deal finder”<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>when<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'> SearchItem($upc : upc != null) // see
if a UPC was provided<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'> StockRoom($stock : stock) // get a
handle to the stock<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'> HashMap (this[$upc] != null) from
$stock // look for the UPC in stock<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'> Item (onSale == true) from $item //
Where do I obtain the reference handle that is $item?<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>then<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'> // Buy stuff<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>End<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>What I’m trying to understand syntactically
is how do I obtain a reference handle to the “Item” found in the
HashMap reference (IE: $item) so that I can check additional attributes on
that Item.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>I haven’t found any good examples of
how to do this yet.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<div>
<div class=MsoNormal align=center style='text-align:center'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>
<hr size=2 width="100%" align=center tabindex=-1>
</span></font></div>
<p class=MsoNormal><b><font size=2 face=Tahoma><span style='font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:</span></font></b><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'>
rules-users-bounces@lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] <b><span style='font-weight:bold'>On
Behalf Of </span></b>Edson Tirelli<br>
<b><span style='font-weight:bold'>Sent:</span></b> Friday, August 21, 2009 9:16
AM<br>
<b><span style='font-weight:bold'>To:</span></b> Rules Users List<br>
<b><span style='font-weight:bold'>Subject:</span></b> Re: [rules-users] Maps in
Drools</span></font><o:p></o:p></p>
</div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='margin-bottom:12.0pt'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'><o:p> </o:p></span></font></p>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>2009/8/20 André Thieme <<a
href="mailto:address.good.until.2009.dec.14@justmail.de">address.good.until.2009.dec.14@justmail.de</a>><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>Would there not be an addition to the syntax needed, for the default<br>
rule language? For mvel it would not require a change I guess.<o:p></o:p></span></font></p>
<div>
<p class=MsoNormal style='margin-bottom:12.0pt'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'><br>
No, as I mentioned to you, the idea is for the DRL to remain the same, so that
the rules author does not have to worry about what the IT guys are doing with
the domain model. So, the rules author would write:<br>
<br>
Customer( name == "bob" )<br>
<br>
The IT guy would simply use a configuration to tell the engine: this object
type uses a map format, that one is a POJO, that other is an XML entity, etc. <br>
For instance, if he wants to do that in DRL (he could also use API, or conf
files), he could do:<br>
<br>
declare Customer<br>
@format( map )<br>
end<br>
<br>
declare Order<br>
@format( pojo )<br>
end<br>
<br>
So, we have a clear distinction between the technical aspects and the business
aspects of the application.<br>
<br>
Your clojure macro would generate always the same DRL code "Customer( name
== "bob" )", but you said yourself that clojure is 100% java
compatible, so imagine the enterprise had a domain model implemented as pojos
already and as part of the new application some new entities are modeled in
clojure. The macro would generate always the same code, but you would configure
some entities in the domain as POJOs and other entities as Maps.<br>
<br>
<o:p></o:p></span></font></p>
</div>
<blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;
margin-left:4.8pt;margin-right:0in'>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>Hmm, but the MVEL syntax can not magically eliminate the eval. Under
the<br>
hood the map accesses will still be inside an eval. Marc confirmed that<br>
a few days ago.<br>
MVEL only hides this from the user. This is what I will also do.<br>
But under the hood it will become<br>
<br>
$a:Map()<br>
$b:Map()<br>
eval( $a.get("type") == "Customer" )<br>
eval( $b.get("type") == "DailyOrders" )<o:p></o:p></span></font></p>
</blockquote>
<div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><br>
Here I think we have other misunderstanding. I will try to explain, but ideally
you need to learn a bit about the Rete algorithm to see the whole picture.
There are 2 types of eval(). Inline eval() and top level eval(). What you wrote
above is a top level eval, meaning it will become a node in the rete network.
So your example above generates an "execution plan" (making an
analogy with SQL) that will get all Maps in the working memory, join them in
tuples size 2, and then test each tuple for the 2 evals. So, you see why this
will generate C(n,2) partial matches, while C(n,2) as we know is n!/(n-2)!,
what is really bad for growing "n".<br>
<br>
Now, the same thing could be written using inline evals as:<br>
<br>
$a:Map( eval( $a.get("type") == "Customer" ) )<br>
$b:Map( eval( $b.get("type") == "DailyOrders" ) )<br>
<br>
In this case, the inline eval() will generate an alpha constraint in the
network, i.e., it will be applied BEFORE the joins. So, instead of doing all
combinaions possible between all maps as above, it will first find all Customer
maps and all DailyOrders maps and only after that will make a join between
them. So you get Customers * DailyOrders partial matches. The above evals are
semantically equivalent as:<br>
<br>
$a:Map( this[ "type" ] == "Customer" ) <br>
$b:Map( this[ "type" ] == "DailyOrders" )<br>
<br>
<br>
> But currently I am forced to produce this cross product, as there is no
direct support for Maps yet.<br>
<br>
I hope that by the above you see that the problem of the cross products is not
a problem with Maps support, but rather a question of how to write better
rules. The same way you can write 2 completely different SQL queries that
return the same result but one is fast and the other is completely heavy and
slow, you can also write good rules and really bad rules.<br>
<br>
[]s<br>
Edson<o:p></o:p></span></font></p>
</div>
</div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font></p>
</div>
</body>
</html>