将可能性表转换为逻辑语句的方法
我不知道如何表达这个问题,所以如果它已经得到解决,我很抱歉。
我将业务规则总结为给定两个输入的输出表。对于一个轴上的五个可能值中的每一个和另一个轴上的五个可能值中的每一个,都有一个输出。这 25 个单元中有 10 种不同的可能性,因此并不是每个输入对都有唯一的输出。
我已经用嵌套的 CASE 语句在 TSQL 中对这些规则进行了编码,但是很难调试和修改。在 C# 中,我可能会使用数组文字。我想知道是否有一个学术主题涉及将逻辑规则转换为矩阵,反之亦然。
举个例子,可以将这个简单的矩阵:
A B C -- -- -- -- X 1 1 0 Y 0 1 0
...转换成这样的规则:
if B OR (A and X) then 1 else 0
...或者,在详细的 SQL 中:
CASE WHEN FieldABC = 'B' THEN 1
WHEN FieldABX = 'A' AND FieldXY = 'X' THEN 1
ELSE 0
我正在寻找一种处理更大矩阵的好方法,尤其是我可以在 SQL 中使用的方法(MS SQL 2K8,如果重要的话)。有什么建议吗?我应该搜索此类翻译的术语吗?
I'm not sure how to express this problem, so my apologies if it's already been addressed.
I have business rules summarized as a table of outputs given two inputs. For each of five possible value on one axis, and each of five values on another axis, there is a single output. There are ten distinct possibilities in these 25 cells, so it's not the case that each input pair has a unique output.
I have encoded these rules in TSQL with nested CASE statements, but it's hard to debug and modify. In C# I might use an array literal. I'm wondering if there's an academic topic which relates to converting logical rules to matrices and vice versa.
As an example, one could translate this trivial matrix:
A B C -- -- -- -- X 1 1 0 Y 0 1 0
...into rules like so:
if B OR (A and X) then 1 else 0
...or, in verbose SQL:
CASE WHEN FieldABC = 'B' THEN 1
WHEN FieldABX = 'A' AND FieldXY = 'X' THEN 1
ELSE 0
I'm looking for a good approach for larger matrices, especially one I can use in SQL (MS SQL 2K8, if it matters). Any suggestions? Is there a term for this type of translation, with which I should search?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来像是对 5x5 数据网格的查找。轴上的输入和每个单元格中的输出:
您可以将其存储在 x、y、outvalue 三元组的表中,然后在该表上进行查找。
Sounds like a lookup into a 5x5 grid of data. The inputs on axis and the output in each cell:
You can store this in a table of x,y,outvalue triplets and then just do a look up on that table.