[rules-users] variable 'or' constraints with a DSL

2008-07-15 Thread Reid Kaufmann

I really like how you can specify a DSL like this (for example):

[condition]There is a person=$p : Person()
[condition]- with {color} hair=hairColor matches {color}
[condition]- with {color} eyes=eyeColor matches {color}
[condition]- that is {height} inches tall =height == {height}
[condition]- that is {age} years old=yearsOld == {age}

If I'm reading the documentation correctly, the rules can then be
specified with any subset of the constraints (lines beginning with
"-").  These constraints are then essentially ANDed together since they
are comma separated when converted to DRL.  Since they are called
constraints, this makes sense.  My question is this:  Is there a similar
way to allow a variable number of "constraints" that are all ORed ("||")
together?

I've been reading the documentation and searching mail archives and so
far haven't found anything helpful.  Let me know if there is a way to do
this or any clever workarounds, since I don't want to delineate every
possible combination of attributes when OR is needed.

reid

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Re: variable 'or' constraints with a DSL

2008-07-16 Thread Reid Kaufmann






  
You should be able to write something close to 

There is a person with {color} hair or with {color} eyes or that is {height} inches tall or that is {age} years old

  

Thanks for the strategies on
writing DSL.  I'm actually having good luck converting my domain
specific code into DRL (using eclipse to play with it) and can see how
I'd form DSL for the example above.  The example is too simple for my
needs, however.  The user has to be able to specify any of the
attributes or any combination thereof and not necessarily in any order
or all of them.  How do I write DSL for that?  I think answer is adding
constraints with the dash syntax, which I brought up in my last email,
BUT that doesn't help me if the user needs to specify "There is a
person with {color} hair OR with {color} eyes".

Let me get into specifics and leave the theoretical example behind.  In
my app, the user specifies any number of
file attributes with which a file will be classified.  For example, the
user can create a policy that applies to files that are greater than 50
MB, or another that applies to files in directory abc OR xyz.  With
input from the user, it generates rules in a Domain Specific Language
(that gets converted to DRL using our DSL file).  The point of using
DSL in this case is to isolate user-level concepts from actual
implementation details.

Snippet from my DSL file:
[condition][File]file where=$f : File()
  [condition][File]- file_name matches {expr}=fileName matches
{expr}
  [condition][File]- dir_name matches {expr}=dirName matches {expr}
  [condition][File]- group_name matches {expr}=gName matches {expr}
  [condition][File]- user_name matches {expr}=uName matches {expr}
  ...

So if the user requests specifies jpg's owned by Bob, I can generate:
file where
  - file_name matches "*.jpg"
- user_name matches "Bob"
  
Which generates appropriate 'when' syntax in DRL:
$f : File(fileName matches "*.jpg", uName
matches "bob")
but I haven't figured out a good way to get ORs with the dash syntax to
get something like this:
$f : File(fileName matches "*.jpg" || uName matches
"bob")

Please let me know if there is a good way to do this.

reid

  You *might* have to use the variable typing feature new to Drools 5.0, but you may not.

A couple approaches that may help you out are...
1.  Write a unit test, and pass your DSL code through the DSLExpander and see what DRL code it generates (which may or may not be valid, but at least you'll see what the DSL engine is doing to your DSL rule).
2.  Download the source and use a step-through debugger with a breakpoint so you can examine the consequences of every match attempted against the RHS of the rule, and the consequent results of the replacement if a match is found.
3.  If you don't want to run a debugger, you could write some AOP code to emit the results of the RHS with each step of the expansion, but this approach would be more work than just running a debugger.

If you'd like to write a self-contained unit test with your DRL rule (the one that looks like the one I provided above, but verified to work), I can take a look at it and see what I'd do DSL-wise. 

Matt



  
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
  



___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Re: variable 'or' constraints with a DSL

2008-07-17 Thread Reid Kaufmann



No, dash syntax is not the answer.  Clever construction of the DSL mapping will 
get you what you need.

Allow me to take your example and modify it.

[condition][File]file_name = fileName
[condition][File]dir_name = dirName
[condition][File]group_name = gName
[condition][File]user_name = uName
 
[condition][]file where {constraints}=$f: File(where {constraints})
[condition][]where {attr} matches {value}={attr} matches {value} 
[condition][]and {attr} matches {value}=,{attr} matches {value}

[condition][]or {attr} matches {value}= || {attr} matches {value}
  
Matt, I'm catching on now -- Drools can make multiple substitutions on a 
line.  I'll see what I can do with this.  Thanks for your examples and help!


reid
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] compiler jar files

2008-08-06 Thread Reid Kaufmann
Is it possible to load rules from DRL using neither the eclipse-jdt-core 
or janino jars?  For example, is it possible to avoid this dependency if 
the mvel dialectic is used?


reid

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users