List Info

Thread: Question about Metadata for Rules




Question about Metadata for Rules
country flaguser name
United States
2008-05-18 06:58:46
Hello everybody,

I have a simple question about annotations for rules. Is it
possible to add
metadata
to a rule in the following or in a similar way?

------------------------------------------------------------
------------------------------------
CostumAnnotation(ruleType=RuleType.GOOD,
otherInformation="This rule ist
very important since ...")
rule "A rule with metadata"
when
    eval(true)
then
   
System.out.println(drools.getRule().getAnnotation(CostumAnno
tation.class).toString());
end
------------------------------------------------------------
------------------------------------
The annotatons should also be accesible within my java
program otherwise it
wouldn't be very useful at all. So for example I should be
able to do the
following

Package[] packages = ruleBase.getPackages();
for (Package pack : packages) {
    Rule[] rules = pack.getRules();
    for (Rule rule : rules) {
       
rule.getAnnotation(CostumAnnotation.class).toString();
    }
} 

Why would I like to have such meta information along with my
rules in one
file? ... here it comes ...

The result of firing all my rules is a list of all rules
(whether they have
been fired or not)
with certain meta information.
On the lhs of each rule I append an entry to that list with
all the meta
information. Depending
on the inserted facts only a subset of all my rules fires
and only a few
rules will add entries to
the list. My problem is that I want the rules that havn't
been fired to
appear in the list with all
the meta information.

A possible but not feasible solution would be to double all
my rules. For
each rule I could
add second rule that fires if the original rule doesn't fire
and this newly
added rule inserts the
entry in the list with all the meta information. Doubling
the number of
rules makes editing rules
error prone and tedious.

Another strategy could be to put all the meta information in
a separate
file. Via the rule name
all meta information could be uniquely assigned to one rule.
This strategy
is also not very appealing
since I have a lot of rules and editing rules again becomes
error prone and
tedious, since I have to
keep the metadata file in sync.

The by far best solution I can think of is to allow
annotaions in the drl
file as shown above.

Any hints or suggestions about the stated problem are highly
appreciated. 

Thanks in advance

-- 
View this message in context: http://www.nabble.com/Question-a
bout-Metadata-for-Rules-tp17301548p17301548.html
Sent from the drools - user mailing list archive at
Nabble.com.

_______________________________________________
rules-users mailing list
rules-userslists.jboss.org

https://lists.jboss.org/mailman/listinfo/rules-users

Re: Question about Metadata for Rules
country flaguser name
United States
2008-05-24 03:46:11
Answer by Edson Tirelli:

It is not possible to add metadata to rules through use of
annotations. It
is an interesting idea for the future in case you want to
open a feature
request.

   Having said that, I believe that in your case, to know
which rules fired
and which don't, what you need is simply to use an
AgendaListener. Take a
look at the documentation. It will allow your application to
know exactly
what is happening in terms of rules firing in your session.
Metadata,
however, you will have to store somewhere else, for now.
-- 
View this message in context: http://www.nabble.com/Question-a
bout-Metadata-for-Rules-tp17301548p17445790.html
Sent from the drools - user mailing list archive at
Nabble.com.

_______________________________________________
rules-users mailing list
rules-userslists.jboss.org

https://lists.jboss.org/mailman/listinfo/rules-users

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )