本文介绍了在数据库中存储条件逻辑表达式/规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用RDBMS存储逻辑表达式?

How can I store logical expressions using a RDBMS?

我标记对象,并希望能够基于这些标签构建真值语句。 (这些可能会被视为虚拟代码。)

I tag objects and would like to be able to build truth statements based on those tags. (These might be considered as virtual tags.)

标记



for_sale

使用

优惠

规则

second_hand_goods =(!new or used)and for_sale

new_offer = new and offer

second_hand_offer = second_hand_goods and offer


  • 规则应能够引用两个标记和其他规则。

  • 可以被hibernate轻松访问的模式将是首选。

  • 最好能够检索整个规则选择/调用?

如何在数据库中存储表达式和业务规则?

How do you guys store expressions and business rules in your databases?

提前感谢。

更新

要清楚,规则不能在内部使用而是由需要持久保存这些标记和规则的外部应用程序创建和使用。感谢。

Update
To be clear, the rules are not for use internally by the database but created and used by an external application that needs to persist these tags and rules. Thanks.

推荐答案

从实用的角度来看,如果计算所需的所有列,在同一个表上 - 计算字段只能从单个记录工作。大多数现代DBMS平台对此功能有一些支持。

From a pragmatic standpoint, you can make computed fields on the database if all of the columns necessary for the computation live on the same table - computed fields can only work from a single record. Most modern DBMS platforms have some support for this feature.

从理论的角度来看,您将进入。关于此的最佳文章是Hammer和MacLeods 论文,其中描述了一种语义数据建模符号,称为SDM。 SDM使用结构化的英语类型符号来标记所描述类别的数据库规则。如果你想概括你的能力,并且不介意为SDM编写一个解析器,你可以做一个规则引擎,这种逻辑可以配置。这种类型的模型也应该可以适应使用O / R映射器。

From a theoretical standpoint, you are getting into Semantic Data Modelling. The best paper on this is Hammer and MacLeods Ruritanian Oil Tankers paper, which describes a semantic data modelling notation imaginatively called SDM. SDM uses a structured english type notation for marking up database rules of the sort you describe. If you wanted to generalise your capability and didn't mind writing a parser for SDM, you could make a rule engine where this sort of logic could be configured. This type of model should also be possible to adapt to play nicely with an O/R mapper.

在负面,使这种工具将是相当时间,因此,如果您对管理数据语义的需求非常大,那么这是值得的。对于你举的例子,它会舒适地适应过度杀伤的领域,但如果你的问题是更大,可能值得建立这样的东西。如果你不想写一个解析器,你可以创建一个XML模式来标记类似SDM的语言。

On the minus side, making this sort of tool would be quite time-consuming, so it would only be worth doing if your requirement for managing data semantics was very large. For the example you cite it would comfortably fit into the realms of overkill, but if your problem is much bigger, it might be worth building something like this. If you didn't want to write a parser, you could make an XML schema for marking up a SDM-like language.

这篇关于在数据库中存储条件逻辑表达式/规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 03:46