2010/10/14 Navdeep Kumar <nkumar@objectwave.com>
Thanks for your reply...could you please tell me what is this myGlobal?
2010/10/13 Michael Anstis <michael.anstis@gmail.com>
You could store all rules in a global and remove those that execute in an AgendaEventListener's activtionCreated event (re-adding those that get retracted by Truth Maintenance in the AgendaEventListeners activationCancelled event).
//Loads rules
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("myrules.drl"), ResourceType.DRL);
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
Collection<KnowledgePackage> kpackages = kbuilder.getKnowledgePackages();
kbase.addKnowledgePackages(kpackages);
//Get all rules
for(KnowledgePackage kpackage : kpackages) {
for(Rule rule : kpackage.getRules()) {
myGlobal.add(rule);
}
}
//The usual suspects
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
ksession.addEventListener(new DefaultAgendaEventListener() {
@Override
void activationCreated(ActivationCreatedEvent event) {
myGlobal.remove(event.getActivation().getRule());
}
@Override
void activationCancelled(ActivationCancelledEvent event) {
myGlobal.add(event.getActivation().getRule());
}
});
ksession.fireAllRules();
You could also use an AgendaEventListener to better manage the contents of the Rule collection for more complex scenarios where Truth Maintenance could retract an activation - that the simpler solution above wold
2010/10/13 Navdeep Kumar <nkumar@objectwave.com>_______________________________________________Hi All,I am new to Drools. I am working on a project where nature of rules are dynamic. I want to capture that rule which does not get executed. i need to store that rule because i have to display that rule in the UI.Here is my rule filerule "FrontAxle:Capacity|FrontSuspension:Capacity"whenb:Feature(featureClass.name=="FrontSuspension")c:Feature(featureClass.name=="FrontAxle")//eval(b.getCapacity() >= c.getCapacity())thenSystem.out.println("These are compatible");System.out.println(b.getFeatureClass().getName());availablity.put(b.getFeatureClass().getName()+"-"+c.getFeatureClass().getName(),"12.35");//availablity.put(b.getName()+"-"+c.getName(),new Double(b.getCapacity()));insert(availablity);endrule "FrontSuspension:Type|FrontAxle:Type"whenb:Feature(featureClass.name=="FrontSuspension")c:Feature(featureClass.name=="FrontAxle")not Feature(b.attributes.Type=="I Beam" && c.attributes.Type=="Multi Link Air")//NOT (FrontAxle.type = "I-Beam" AND FrontSuspension.type = "Multi-link Air") - mounting restrictionthenSystem.out.println("I am in 2");endrule "FrontAxle:FeatureCode|FrontSuspension:Type"whenb:Feature(featureClass.name=="FrontSuspension")Feature(featureClass.name=="FrontAxle" && code=="002ASW")and not Feature(b.attributes.Type=="Multi Link Air" || b.attributes.Type=="Monoleaf Spring")//FrontAxle.featureCode = "002ASW" AND NOT (FrontSuspension.type = "Multi-link Air" OR FrontSuspension.type = "Monoleaf Spring")thenSystem.out.println("I am in 3");endnow if these two objects named FrontAxle and FrontSuspension are compatible then it has to meet all the 3 rules, but if any combination of these objects does not meet one of the rule listed above then i have to store the rule for the displaying purpose that this combination didn't meet this rule thats why they are not compatible. any kind of help will be appreciated.Thanks.
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
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users