[rules-users] Granularity of facts

Scott Reed sreed at avacoda.com
Wed Mar 5 22:32:28 EST 2008


Here's how I'd address this issue. I haven't compiled or run this but I 
hope it communicates the idea.

rule "Every mother and father produce a child"
	no-loop
	when
		$mother : Mother(  )
		$father : Father(  )
		not Child( mother = $mother, father = $father )
	then
		Child child = new Child($mother.getId() + "-" + $father.getId());
		child.setMother($mother);
		child.setFather($father);
		insertLogical( child );
end

rule "Every child gets his/her father's first and last name"
	no-loop
	when
		$father : Father( $first: first, $last: last )
		$child : Child( father == $father,
                                first != $first,
	 			last != last )
	then
		$child.setFirst($first);
		$child.setLast($last);
		update($child);
end

rule "Every child gets his/her mother's middle name"
	no-loop
	when
		$mother : Mother( $middle: middle )
		$child : Child( mother == $mother, 
				middle != middle )
	then
		$child.setMiddle($middle);
		update($child);
end





More information about the rules-users mailing list