Hi,
Assuming you can have your rules in a byte[], you can use something along
the lines of:
bytes[] KB = ... your rules ...
KnowledgeBuilderConfiguration builderConf =
KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder(builderConf);
kbuilder.add(ResourceFactory.newByteArrayResource(KB), ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error : errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge.");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
try {
ksession.fireAllRules();
} finally {
ksession.dispose();
}
The above snippet can easily be modified for String representation of rules.
Hope it helps,
-Stathis
nkumar wrote:
Hi,
Is there any way to get the rules from external source rather than loading
this from .drl file every time? because of changing behavior of the rules,
rule file has to be changed if a user introduces a new rule in the system.
Please help me out how can we solve this. i am new to drools and even i
don't know how to write rules properly. Can we store this in a database or
can we save rules somewhere so that next time rather than loading this
from
direct rule file, we load this from that data source. User of this
application is non technical and i also need to make an interface to get
the
rules in plane English which will convert those into rules accordingly.
Guvnor is not much user friendly. Can anyone please help me out. My
deadline
is near.
this is the structure of the rule which i need to make after loading the
data.
when
b:Feature(featureClass.name=="FrontSuspension")
c:Feature(featureClass.name=="FrontAxle")
eval(b.attributes.Capacity>=c.attributes.Capacity)
then
AvailabilityRuleState s = new
AvailabilityRuleState();
s.setValue("A");//Available
s.setReason("");
s.setReference("FA-FS:1");
resultState.add(s);
end
Please help me out. i will really appreciate your help.
Thanks
--
View this message in context:
http://drools-java-rules-engine.46999.n3.nabble.com/Urgent-Dynamic-nature...
Sent from the Drools - User mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users