对抽象过滤器进行操作(列表理解):组合两个过滤器
短而尖锐:
给定两个布尔语句,在像 Lua 这样的语言中计算它们的交集方程的最简单方法是什么?
(红色 = 过滤器 1,蓝色 = 过滤器 2,紫色 = 交叉区域)
又长又感叹:
过滤器 A:
object.ID < 300
过滤器 B:
object.ID < 600
过滤器 A 是过滤器 B 的子集,即:过滤器 B 将包含所有内容与过滤器 A 匹配,加上 0 个或多个对象。 在维恩图上,过滤器 A 将位于过滤器 B 内部。
如何计算交叉面积方程?
更复杂的示例:
- 过滤器 X:
object.Col == 'GREEN' and (object.ID == 2 or object.ID == 64 or object.ID > 9001)
- 过滤 Y:
(object.Col == 'RED' 或 object.Col == 'GREEN') and (object.ID == 3 或 object.ID > 22)
过滤器 A 与过滤器 B 相交。 在维恩图上,它们会重叠。 重叠面积的方程为:object.Col == 'GREEN' and (object.ID == 64 or object.ID > 9001)
这个方程如何用 Python 或 Haskell 等语言计算?
我希望最终用 Lua 实现这一点,但如果 Python、Haskell 或其他语言提供了该功能,我将能够查看源代码并将其转换过来。
以下是我在 Lua 中表示过滤器的方式:
filter = DataFilter(
{"and",
{"or",
{"==", "Col", "RED"},
{"==", "Col", "GREEN"},
},
{"or",
{"==", "ID", 3},
{">" , "ID", 22},
},
}
)
请为我指出正确的方向。
Short and sharp:
Given two Boolean statements, what is the easiest way to calculate the equation of their intersection in a language like Lua?
(Red = Filter 1, Blue = Filter 2, Purple = Area of intersection)
Long and lamenting:
Filter A:
object.ID < 300
Filter B:
object.ID < 600
Filter A is a subset of Filter B, that is: Filter B will contain everything matched by Filter A, plus 0 or more objects.
On a Venn diagram, Filter A would be inside Filter B.
How can I calculate the equation of the area of intersection?
A more complicated example:
- Filter X:
object.Col == 'GREEN' and (object.ID == 2 or object.ID == 64 or object.ID > 9001)
- Filter Y:
(object.Col == 'RED' or object.Col == 'GREEN') and (object.ID == 3 or object.ID > 22)
Filter A intersects with Filter B.
On a Venn Diagram, they would overlap.
The equation for the overlapping area would be:object.Col == 'GREEN' and (object.ID == 64 or object.ID > 9001)
How would this equation be calculated in a language such as Python or Haskell?
I wish to eventually make this in Lua, but if Python, Haskell or another language provided the functionality, I would be able to look at the source code and convert it over.
Here is how I am representing filters in Lua:
filter = DataFilter(
{"and",
{"or",
{"==", "Col", "RED"},
{"==", "Col", "GREEN"},
},
{"or",
{"==", "ID", 3},
{">" , "ID", 22},
},
}
)
Please point me in the right direction.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
疯狂猜测:将“过滤器”引入析取范式并使用适当的方法进行归约(x == 8 包含在 x > 5 中)。
Wild guess: Bring the "Filters" into disjunctive normal form and reduce using appropriate methods (x == 8 contained in x > 5).
这是你可以通过某种方式实现的。自注释代码将帮助您理解该方法
This is somehow you can achieve this. The self commented code would help you understand the approach
我不知道我是否遗漏了重要的一点。看来您的过滤器只是根据“对象”的质量返回一个布尔值。为什么不直接使用常规的“and”和“or”以及函数来组成它们呢?
这就是我在 Lua 中制作过滤器的方式:
您可以使用这些额外函数定义这些过滤器的“并集”或“交集”:
这是您的组合方式:
或者,如果您想经常重用它们:
我希望这样有帮助。
I don't know if I'm missing an important point here. It seems that your filters just return a boolean depending on the qualities of "object". Why don't you just use regular "and" and "or"s and functions to compose them?
This is how I'd make your filters in Lua:
You can define the "union" or "intersection" of those filters with these extra functions:
And here's how you compose:
Or, if you want to reuse them often:
I hope this helps.