[英]What is the best way to represent similar inputs for rules in a relational database?
I am designing a rules database, which takes a number of inputs and determines the appropriate output.我正在设计一个规则数据库,它接受一些输入并确定适当的 output。
There is a set of ~20 input types that are very similar (can be represented with Id, Value) which all drive a set ~20 output types.有一组 ~20 个输入类型非常相似(可以用 Id、Value 表示),它们都驱动一组 ~20 个 output 类型。 Each input type has a number of possible values.每种输入类型都有许多可能的值。 Each output type has a number of possible values as well.每个 output 类型也有许多可能的值。
An example rule would be InputTypeA + InputTypeB determines OutputTypeA
or InputTypeA determines OutputTypeB
.一个示例规则是InputTypeA + InputTypeB determines OutputTypeA
或InputTypeA determines OutputTypeB
。 n
input types can drive an output, but currently the maximum number is 3. n
输入类型可以驱动一个 output,但目前最大数量为 3。
InputType
table FK'd to determine the type of the input value (they will all be strings from a db type perspective).存储在一个表中,使用InputType
表 FK 来确定输入值的类型(从 db 类型的角度来看,它们都是字符串)。I would think of this as 3 major concepts.我认为这是三个主要概念。
Condition : what needs to be true for a rule to fire?条件:触发规则需要满足什么条件? Rule : when a rule fires, which results are true?规则:当规则触发时,哪些结果是正确的? Result : which outputs fire, and with which values?结果:哪个输出火,以及哪些值?
Conditions are modelled as one or more inputs with their values (your example uses InputTypeA + InputTypeB so I assume a rule has one or more qualifying inputs).条件被建模为一个或多个输入及其值(您的示例使用 InputTypeA + InputTypeB 所以我假设一个规则有一个或多个合格输入)。
Results are modelled as one or more output, with their values.结果建模为一个或多个 output 及其值。
Specifically:具体来说:
Condition
-----------
ID
RuleID
InputType
InputValue
Rule
----
ID
Result
-------
ID
RuleID
OutputType
OutputValue
If there is more logic to input types and output types, you can create a lookup table with a foreign key relationship.如果输入类型和 output 类型有更多逻辑,您可以创建具有外键关系的查找表。
Example might be:示例可能是:
Condition健康)状况
ID RuleID InputType InputValue
1 1 DrivingIn30zone 1
2 1 CurrentSpeed 40
Rule
ID Name
1 Don't break the speed limit
Result
ID RuleID OutputType OutputValue
1. 1 SetSpeed 29
You would then search for conditions which match your current input values to see what the output states are:然后,您将搜索与当前输入值匹配的条件,以查看 output 状态是什么:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.