我似乎无法找到正确方向的指针,我甚至不确定我应该研究的条款是什么,但无数小时的谷歌搜索似乎在旋转我的圈子,所以希望堆栈智能的集体蜂巢溢出可以帮助.
问题是,我需要一种方法来过滤数据,我只能称之为复合逻辑树.目前,该系统实现了一个简单的AND过滤系统.例如,假设我们有一个人的数据集.你添加了一堆过滤器,显示所有人(性别=女性)和(年龄> 23)AND(年龄<30)和(状态=单身).很容易,遍历每个项目,只有在每个条件都为真时才添加到有效的项目集合.
我遇到的问题是如何处理用户能够构建涉及的复杂查询和/或?我正在考虑像每个节点所代表的树和表达式,将其子节点评估为真或假.一个简单的例子是 - 过滤到((性别= =男性和年龄= = 25)或(性别==女性和状态==单身))和智商> 120.对不起我想不出一个更好的例子在此时此刻.但是,您将如何表示此类型的表达式树,并针对这些过滤器评估集合中的项目.有哪些参考资料会有所帮助?天啊,谷歌搜索什么可能会导致一个积极的方向?!
感谢任何可以提供任何帮助的人.
以下是使用人员数据集的树形式的复合查询示例
所以在树形式即时思考
o-Root Node
- And - Sex = Male
- And - Eyes = Blue
- Or - Sex = Female
- And Eyes = Blue
- Or Status = Single
Run Code Online (Sandbox Code Playgroud)
我相信解决方案是在数据结构中表示每个节点
Node
{
OpType - AND or OR
ExpressionField - The field to evaluate
ExpressionOp - =, !=, >, >=, <, <=
ExpressionValue - the value to compare the field's value against …
Run Code Online (Sandbox Code Playgroud) user-interface boolean-logic expression-trees expression-evaluation decision-tree
采用以下表达式: FALSE AND (expression)
MySQL会评估表达式,还是只要看到它就继续前进FALSE
?
一些背景上下文 - 我想通过以下方式加快查询:
JOIN... ON (indexed_column1=indexed_column2 AND non_indexed_column_a=non_indexed_column_b)
有关我为什么要执行此查询的背景,请参阅此答案
如果它总是要评估non_indexed_column_a=non_indexed_column_b
那么就没有时间了.
出于某种原因,这个功能使我困惑:
def protocol(port):
return port == "443" and "https://" or "http://"
Run Code Online (Sandbox Code Playgroud)
有人可以解释幕后发生的事情的顺序,使其按照它的方式工作.
直到我尝试它才明白这一点:
要么A)
def protocol(port):
if port == "443":
if bool("https://"):
return True
elif bool("http://"):
return True
return False
Run Code Online (Sandbox Code Playgroud)
或者B)
def protocol(port):
if port == "443":
return True + "https://"
else:
return True + "http://"
Run Code Online (Sandbox Code Playgroud)
这是Python中的某种特殊情况,还是我完全误解了语句的工作原理?
如何在PHP中编写以下布尔表达式:
$foo = "";
if($var==TRUE){
$foo = "bar";
}
Run Code Online (Sandbox Code Playgroud)
要么
if($var==TRUE){
$foo = "bar";
}else{
$foo = "";
}
Run Code Online (Sandbox Code Playgroud)
要么
$foo = ($var==TRUE) ? "bar": "";
Run Code Online (Sandbox Code Playgroud) 在C和C++中,!
否定结果:
if( !( a == b ) )
Run Code Online (Sandbox Code Playgroud)
在Scheme中,我发现只有eq?
.我怎么说"不平等"?或者我们必须明确说出来
(eq? #f (eq? expr expr))
Run Code Online (Sandbox Code Playgroud) 我是Mathematica(v8)的新手,并且正在使用它来编写命题逻辑.
我想知道运营商If
和Implies
运营商之间的区别.例如,
既If[p,q]
和Implies[p,q]
返回q
的p=True
(如预期).
但是当我尝试获得满意度时,我得到以下结果:
SatisfiabilityInstances[If[p, q], {p, q}]
(*
{{True, True}}
*)
Run Code Online (Sandbox Code Playgroud)
除非我要求更多实例:
SatisfiabilityInstances[If[p, q], {p, q}, All]
Run Code Online (Sandbox Code Playgroud)
SatisfiabilityInstances :: boolv:"如果[p,q]不是布尔值{False,True}.
然而:
SatisfiabilityInstances[Implies[p, q], {p, q}, All]
Run Code Online (Sandbox Code Playgroud)
返回预期的:
(* {{True, True}, {False, True}, {False, False}} *)
Run Code Online (Sandbox Code Playgroud)
造成这种差异的原因是什么?
在java中,有一个逻辑OR运算符(||
)和一个逻辑AND运算符(&&
).是否有逻辑XOR运算符?我试过^^
但它不起作用.
我有以下代码
output = T.switch(cond, a, b)
Run Code Online (Sandbox Code Playgroud)
这里cond
是一个(N,1)
布尔张量,而a
和b
是(N, M)
与数值张量M
是相当大的.该条件以行方式运行.
我可以很容易地通过运行开关工作T.repeat()
的cond
,但是这是相当缓慢.有没有办法在我能够有效地使布尔变量cond
决定是否a
或b
应该归还?
我对这个问题有类似的问题Xpath Get elements that are Between 2 elements。但在我的具体情况下,html 可能会有所不同,并且我无法使用第二个元素的文本
基本上我有这样的结构:
<h1>Account Information</h1>
<a class="null" href="http:...">Remarks</a>
<a class="null" href="http:...">Owner Information</a>
<b>Account Detail</b>
<a class="null" href="http:...">Industrial</a>
<a class="null" href="http:...">land</a>
<b >Transfers</b>
<a class="null" href="http:...">11111</a>
<a class="null" href="http:...">22222</a>
Run Code Online (Sandbox Code Playgroud)
所以我想<a>
在 b='Account Detail' 和下一个可以改变文本的 b 之间获取。
//a[preceding-sibling::b='Account Detail' and following-sibling::b]
Run Code Online (Sandbox Code Playgroud)
对于这种情况,工作正常,因为我得到的 b='Account Detail' 之后只有一个 b
[工业、土地]
<b>
但是如果b='Account Detail' 之后有多个
但是如果我们有多个<b>
<h1>Account Information</h1>
<a class="null" href="http:...">Remarks</a>
<a class="null" href="http:...">Owner Information</a>
<b>Account Detail</b>
<a class="null" href="http:...">Industrial</a>
<a class="null" href="http:...">land</a> …
Run Code Online (Sandbox Code Playgroud) 我正在开发一个应用 MISRA 2004 的项目。
对于大多数违规行为,我都找到了原因,但有一个我不明白:
它在 if 语句中带有&&
和||
操作。
例子:
uint8 getValue()
{
// Some algorithm, simplified with return 1
uint8 someValue = 1u;
return someValue;
}
int main(int argc, char *argv[]) {
uint8 currentState = 0u;
uint8 var_a = getValue();
uint8 var_b = getValue();
uint8 var_c = getValue();
uint8 var_d = getValue();
const uint8 const_a = 1u;
const uint8 const_b = 2u;
const uint8 const_c1 = 3u;
const uint8 const_c2 = 30u;
const uint8 const_d = …
Run Code Online (Sandbox Code Playgroud)