Re: [rules-users] Mapping complex objects info Guvnor compatible shim classes?

2013-08-10 Thread Stephen Masters
Your plan seems about right to me. When working in pure Drools, you don't 
always need to do this. However, when working in Guvnor, I have always found it 
necessary to create a simplified domain model for facts.

In Guvnor, you can bind variables to fields and drill in, but it's fiddly. 
Guided rules are much more readable when they are dealing with matching 
bean-style facts with key attributes available through simple getX() accessor 
methods. And of course you definitely need the bean-style getX() methods.

The other thing to think about, is that when working with Guvnor, you should be 
avoiding any dependencies on external classes from within your facts. 
Otherwise, you will need to put everything on your Guvnor web server's class 
path, which totally messes with your ability to upload fact model updates. Yet 
another reason to keep them simple.


So given that you're going with that plan, here are my tips for the lazy (like 
me)...

To help with simplifying your transformations, it may be worth looking at Dozer 
or similar: http://dozer.sourceforge.net/

Personally, because I have often found that I'm doing things like mapping 
multiple objects into a single fact, I tend to just do the mapping in straight 
Java code. It tends not to be too painful, as I rarely find the need for 
bi-directional mappings. I don't often need to get a fact back out of working 
memory. So although it feels a bit naughty, I often avoid the 
fact-to-domain-object transform. :)

Think about what properties you really might want to write rules about. It's 
easy to spend a huge amount of time writing a huge fact model, and transforms 
for every single property of every class in your domain model. Truth is you 
probably won't write rules that look at all of it. So have a think about 
whether you do need to map everything or not. My tip here would be to follow a 
TDD approach. Look at what rules your users want to write. You should find that 
the rules mostly follow certain stereotypes, so create rule tests covering a 
representative selection of such stereotype (ensure coverage of all unique fact 
attributes which are examined). Create a fact model which can satisfy those 
tests. Create tests for transforming from your domain model to your fact model. 
Create transforms to that fact model. Assuming you have a reasonably iterative 
environment, you can add transforms for additional attributes when users have 
tried out the application and come up with new rule stereotypes they would like 
to work with.


As an alternative (or to complement the above), take a look at DSLs. Each DSL 
phrase becomes available in your guided editor, so you can have simple rule 
phrases which the users can understand, but underneath, you can have code which 
is drilling into nested objects.

I do hope that's helpful… :)

Steve



On 10 Aug 2013, at 00:47, Mark Bennett mark.benn...@lucidworks.com wrote:

 We want our domain experts to be able to create Guided Rules in Guvnor (5.5)
 
 But Guvnor seems pretty limited about what it will accept, and how it will 
 render it.
 
 We're attempting to create adapter classes that will:
 * Allow us to expose a rich set of fields and methods in UI
 * Use as injected facts into the engine
 
 Main issues we're having:
 * Native objects are nested, but Guvnor seems to want shallow
 * Our native objects can have different attributes (different schemas)
 - And you can't say getField( fieldName )
 * Some returned items can be multivalued, vs. singular
 
 Our idea is:
 * Have admin send a prototypical request  schema event into our native system
 * Scrape and flatten that into a java class that exposes Guvnor friendly 
 methods
 * Send that class into Guvnor
 * Keep a copy of that class to create instances of when injecting facts into 
 the engine
 
 Is there some type of easy way to map complex objects to/from the simpler 
 Guvnor/Drools model?  Some type of reflection based mapper with some simple 
 rules or a template?  We're wondering what others have done in this situation?
 
 Thanks,
 Mark
 
 --
 Mark Bennett / LucidWorks: Search  Big Data / mark.benn...@lucidworks.com
 Office: 408-898-4201 / Telecommute: 408-733-0387 / Cell: 408-829-6513
 
 
 ___
 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] Long pattern for Nurse Rostering

2013-08-10 Thread john poole
Thanks for the reply. The series of shifts that a Doctor works in my schedule
is 15 days straight, but not the same Shift for each of those days.
I ended up doing it like this, maybe it explains the requirements better.
Its working, but it looks ugly.

rule pattern15dayShiftAssignment
when
$pattern : Neuro15DaysPattern(  
$dayOfWeekFirst : getDayOfWeek(0),
$shiftType0: getShiftType(0),
$shiftType1: getShiftType(1),
$shiftType2: getShiftType(2),
$shiftType3: getShiftType(3),
$shiftType4: getShiftType(4),
$shiftType5: getShiftType(5),
$shiftType6: getShiftType(6),
$shiftType7: getShiftType(7),
$shiftType8: getShiftType(8),
$shiftType9: getShiftType(9),
$shiftType10: getShiftType(10),
$shiftType11: getShiftType(11),
$shiftType12: getShiftType(12),
$shiftType13: getShiftType(13),
$shiftType14: getShiftType(14)
 );
then
insertLogical( new PatternShiftAssignment($pattern,  
$shiftType1, 1) );
insertLogical( new PatternShiftAssignment($pattern,  
$shiftType2, 2) ); 
insertLogical( new PatternShiftAssignment($pattern,  
$shiftType3, 3) ); 
insertLogical( new PatternShiftAssignment($pattern,  
$shiftType4, 4) ); 
insertLogical( new PatternShiftAssignment($pattern,  
$shiftType5, 5) ); 
insertLogical( new PatternShiftAssignment($pattern,  
$shiftType6, 6) ); 
insertLogical( new PatternShiftAssignment($pattern,  
$shiftType7, 7) ); 
insertLogical( new PatternShiftAssignment($pattern,  
$shiftType8, 8) ); 
insertLogical( new PatternShiftAssignment($pattern,  
$shiftType9, 9) ); 
insertLogical( new PatternShiftAssignment($pattern,  
$shiftType10, 10) );
insertLogical( new PatternShiftAssignment($pattern,  
$shiftType11, 11) );   
insertLogical( new PatternShiftAssignment($pattern,  
$shiftType11, 11) );   
insertLogical( new PatternShiftAssignment($pattern,  
$shiftType12, 12) );   
insertLogical( new PatternShiftAssignment($pattern,  
$shiftType13, 13) );   
insertLogical( new PatternShiftAssignment($pattern,  
$shiftType14, 14) );   
System.out.println( $pattern + +  $shiftType14 );
end

rule unwantedPatternNeuro15Days
when 
$pattern : Neuro15DaysPattern($dayOfWeekFirst : getDayOfWeek(0),
$shiftType0: getShiftType(0), $code : code);

PatternShiftAssignment( pattern == $pattern, $shiftType : shiftType,
$dayIndex: patternIndex)

  
$shiftAssignment0 : ShiftAssignment($code == shiftDateDayIndex %
2,
shiftType == 
$shiftType0, 

shiftDateDayOfWeek == $dayOfWeekFirst, 
$employee: 
employee,

$shiftDateDayIndex0 : shiftDateDayIndex);

  
$shiftassignment : ShiftAssignment( shiftType == $shiftType,
shiftDateDayIndex ==
($dayIndex+$shiftDateDayIndex0),
$employee !=
employee 
)
   
then
insertLogical(new
IntConstraintOccurrence(unwantedPatternNeuro15Days,  
 ConstraintType.NEGATIVE_SOFT,
$pattern.getWeight(),
$employee, $pattern, $dayIndex));
end



--
View this message in context: 
http://drools.46999.n3.nabble.com/Long-pattern-for-Nurse-Rostering-tp4025432p4025444.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users