使用规则引擎进行验证
我们处理基于文本(无 XML)的消息。我们的目标是验证消息,如果内容正确,则消息有效。我们开发了自己的 XML 定义语言来表达消息规则。我们需要添加更复杂的规则,我们认为现在是时候考虑其他替代方案并使用真正的规则引擎了。我们支持这些类型的规则:
- 值列表中的名称或常规名称 表达式 ex {SMITH, MOORE, A*}
- 消息中存在名称 -
- 消息中不存在名称
- if condition then name = John else name = Jane 请注意,条件很简单,不包含任何逻辑运算符。
我们需要支持这些类型的规则:
- if then else 但条件包含逻辑运算符
- for ...loop :
- 对于消息中的所有客户,我们希望至少有一位来自美国,至少一位来自法国
- 对于消息中的所有客户,我们希望至少有五个来自美国且每年购买超过 1000 美元的客户
- 对于任何名为 John 的客户,姓氏必须为 Doe
- Total 客户,名为 John << 15
- 公司名称与消息中其他位置的公司名称相同
规则将取决于我们处理的消息类型。因此,我们正在研究几个现有的解决方案,例如:
- JESS
- OWL(一致性检查)
- Schematron(通过转换 XML 中的消息)
考虑到我们用 Java 开发,最好的替代方案是什么?另一件需要考虑的事情是我们应该能够进行错误报告,例如错误描述、错误位置(行号和列号)。
We work with messages that are text-based (no XML). Our goal is to validate the messages, a message is valid if the content is correct. We developed our own language defined in XML to express rules on the message. We need to add more complex rules and we think that it’s now time to look at other alternative and use real rules engine. We support these types of rules:
- name in a list of values or a regular
expression ex {SMITH, MOORE, A*} - name is present in the message-
- name is not present in the message
- if condition then name = John else name = Jane
Note that the condition is simple and does not contain any logical operators.
We need to support these types of rules:
- if then else but the condition contains logical operators
- for ... loop :
- For all the customers in the message we want at least one from the USA and at least one from France
- For all the customers in the message we want at least five that are from the USA and are buying more than $1000 a year
- For any customer with name John, the last name must be Doe
- Total customers with name John < 15
- The name of the company is equal to the name of the company in another location in the message
The rules will depend on the type of messages we process. So we were investigating several existing solutions like:
- JESS
- OWL (Consistency checking)
- Schematron (by transforming the message in XML)
What would be the best alternatives considering that we develop in Java? Another thing to consider is that we should be able to do error reporting like error description, error location (line and column number).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我看来,你已经走上了正确的道路;我的建议是:
It sounds to me like you're on the right track already; my suggestions are:
如果您的规则是静态的(即在编译时已知),您可以使用众所周知的 Java 解析器生成器来实现: JavaCC。
If you're rules are static (i.e. known at compile time) you could make this with well known Java parser generator: JavaCC.