Java 如何通过编程生成.drl文件。任何示例都会对我有所帮助
我搜索了很多网站,但找不到任何关于.drl文件生成的具体相关示例。关于.drl文件生成的文档也不值得使用。Drools的最新版本开始以一种使用fluent API以编程方式定义规则的方式工作。我自己也在一些内部项目中使用过这个API,它足够灵活,可以满足我的需要。此API的缺点是:Java 如何通过编程生成.drl文件。任何示例都会对我有所帮助,java,jboss,drools,kie,Java,Jboss,Drools,Kie,我搜索了很多网站,但找不到任何关于.drl文件生成的具体相关示例。关于.drl文件生成的文档也不值得使用。Drools的最新版本开始以一种使用fluent API以编程方式定义规则的方式工作。我自己也在一些内部项目中使用过这个API,它足够灵活,可以满足我的需要。此API的缺点是: 它没有文档记录(你可以找到,差不多就是这样) 它被认为是内部API,因此将来可能会在没有向后兼容性的情况下更改 有时,API不够“类型化”。约束的某些部分必须指定为字符串块 但是有一个可能更好的选择,你可能需要考
- 它没有文档记录(你可以找到,差不多就是这样)
- 它被认为是内部API,因此将来可能会在没有向后兼容性的情况下更改
- 有时,API不够“类型化”。约束的某些部分必须指定为字符串块
希望有帮助,你想从什么生成这些文件?我想要自己的规则生成抱歉,我不明白。.drl文件是一个程序。通常人们不生成程序,而是在IDE中编写程序。如果确实要生成程序,可以通过将文本写入文本文件来实现。您不会找到太多生成程序的文档或示例,因为在一般情况下不可能提供此类文档:过程完全取决于生成程序的依据。我有一些规则,这些规则可能会不断更新,因此我需要一个规则生成程序。我浏览了drool和相关链接,但我对此并不满意。当$pc:PotentialCustomer(creditLimit)时,规则“向信用额度低于或等于500美元的潜在客户发送电子邮件报价”(creditLimit我非常感谢您,感谢您提供了宝贵的意见。
// -------package section-------
PackageDescr pkg=new PackageDescr();
pkg.setName("com.demo.model");
// -------import section here-------
ImportDescr importEntry1= new ImportDescr();
importEntry1.setTarget("com.demo.model.Purchase");
pkg.addImport(importEntry1);
ImportDescr importEntry2= new ImportDescr();
importEntry2.setTarget("com.demo.model.PotentialCustomer");
pkg.addImport(importEntry2);
ImportDescr importEntry3= new ImportDescr();
importEntry3.setTarget("com.demo.model.PaymentMethod");
pkg.addImport(importEntry3);
//-------global section here-------
GlobalDescr globalEntry=new GlobalDescr();
globalEntry.setType("org.slf4j.Logger");
globalEntry.setIdentifier("logger");
pkg.addGlobal(globalEntry);
//------- rule section here
RuleDescr ruleEntry=new RuleDescr();
ruleEntry.setName("Identify potential customers");
// ------- lhs starts here -------
AndDescr lhs=new AndDescr();
//------- pattern starts here -------
PatternDescr patternEntry1=new PatternDescr();
patternEntry1.setIdentifier("$p");
patternEntry1.setObjectType("Purchase");
//------- ExprConstraint starts here -------
ExprConstraintDescr ecd1=new ExprConstraintDescr();
ecd1.setExpression("paymentMethod");
ExprConstraintDescr ecd2=new ExprConstraintDescr();
ecd2.setExpression("PaymentMethod.CASH");
//------- Added exprConstraint into relational expr-------
RelationalExprDescr red1=new RelationalExprDescr("==",false, null, ecd1, ecd2);
ExprConstraintDescr ecd3=new ExprConstraintDescr();
ecd3.setExpression("subTotal");
ExprConstraintDescr ecd4=new ExprConstraintDescr();
ecd4.setExpression("300");
RelationalExprDescr red2=new RelationalExprDescr(">",false, null, ecd3, ecd4);
patternEntry1.addConstraint(red1);
patternEntry1.addConstraint(red2);
lhs.addDescr(patternEntry1);
NotDescr notDescr=new NotDescr();
notDescr.setText("not");
PatternDescr pattDescr1=new PatternDescr();
pattDescr1.setObjectType("PotentialCustomer");
ExprConstraintDescr ecd11=new ExprConstraintDescr();
ecd11.setExpression("customerName");
ExprConstraintDescr ecd12=new ExprConstraintDescr();
ecd12.setExpression("$p.getCustomerName()");
RelationalExprDescr red11=new RelationalExprDescr("==",false, null, ecd11,ecd12);
pattDescr1.addConstraint(red11);
notDescr.addDescr(pattDescr1);
lhs.addDescr(notDescr);
ruleEntry.setLhs(lhs);
pkg.addRule(ruleEntry);
String drl = new DrlDumper().dump( pkg );
// here drl is in form of String