有什么方法可以仅使用 AND 来复制 OR 运算符?
Any way to replicate the OR operator with only ANDs?
所以我试图找到一种方法允许在我的应用程序的前端进行 OR 操作,然后在后端服务器上转换条件,然后后端服务器将与 Intrinio(财务数据 API ).我尝试使用的端点(以节省 api 通话积分)仅允许使用 AND 运算符,但我希望有某种解决方法。
这是我尝试使用的端点:http://docs.intrinio.com/#securities-search-screener
这只是我要发送到我的服务器进行翻译的示例条件:
open_price > 10 && (current_volume > 1000000 || current_volume > average_volume)
P.S
open_price、current_volume 和 average_volume 都是 Intrinio 生态系统中使用的标签
我可能还应该提到他们没有 NOT
我恳求你们在评论之前先看看link...
根据 DeMorgan's laws,a && b
等价于 !(!a || !b)
你可以把and
想成
"a
and b
are both true
"
或等效
"Neither a
nor b
are false
"
先判断average_volume和1000000哪个大然后根据结果选择条件判断:
if(average_volume <= 1000000)
//use this condition: open_price > 10 && current_volume > 1000000
else
//use this condition: open_price > 10 && current_volume > average_volume
一般情况下,你不能。
在此API中,您只能否定原子条件,将~gt~
更改为~lte~
等,e。 G。将 open_price~gt~10
更改为 open_price~lte~10
.
但是你不能否定这个 API 中的非原子条件,特别是你不能使用德摩根定律。
只有3n(+1)个变量的n个布尔函数,可以使用合取和原子否定来表达。 n个变量的布尔函数总数为22ⁿ。顺便说一句,所有这些都可以使用合取和非原子否定来表达。因此,存在无法使用合取和原子否定表达的布尔函数。
您应该发出两个或更多请求,然后在 API 客户端上合并结果。
有几种方法可以做到这一点,它们在请求数量、检索记录总数(某些记录可能被检索多次)以及所需的 API 通话信用(等于数量)方面有所不同条件)。
假设原始数据如下所示(让我们跳过 open_price
属性)。
{
{
"identifier": "A-OK",
"current_volume": 1000002, "average_volume": 1000001
},
{
"identifier": "B-OK",
"current_volume": 1000001, "average_volume": 999999
},
{
"identifier": "D-OK",
"current_volume": 999999, "average_volume": 999998
},
{
"identifier": "E-OK",
"current_volume": 1000001, "average_volume": 1000002
},
{
"identifier": "G-NO",
"current_volume": 999999, "average_volume": 1000001
},
{
"identifier": "H-NO",
"current_volume": 999998, "average_volume": 999999
}
}
您需要检索标识符为 A-OK
、B-OK
、D-OK
、E-OK
.
的记录
方法 1(两个请求,结果集不相交)
current_volume~gt~1000000
current_volume~gt~average_volume
如您所见,我们只是在客户端执行析取,而不是在服务器...
方法 2(三个请求,结果集不相交)
current_volume~gt~1000000,current_volume~gt~average_volume
current_volume~gt~1000000,current_volume~lte~average_volume
current_volume~lte~1000000,current_volume~gt~average_volume
在这种方法中,我们依赖于这个事实:A||B
等于 (A && B) ^^ (A && !B) ^^ (!A && B)
。
方法 3(两个请求,结果集不相交)
current_volume~gt~1000000
current_volume~lte~1000000,current_volume~gt~average_volume
在这种方法中,我们依赖于这个事实:A||B
等于 A ^^ (!A && B)
。
方法 4(两个请求,结果集不相交)
在您的特定情况下,存在一种依赖于实数顺序关系的传递性的方法。
average_volume~gt~1000000,current_volume~gt~1000000
average_volume~lte~1000000,current_volume~gt~average_volume
但是,这种方法在 API 话费方面并没有带来多少利润。
比较
+----------+----------+-----------+--------------+----------+
| Approach | Number of| Records | Resultsets | Total |
| | requests | retrieved | disjointness | credits |
+----------+----------+-----------+--------------+----------+
| # 1 | 2 | 6 (3+3) | no | 2 |
| # 2 | 3 | 4 | yes | 6 |
| # 3 | 2 | 4 | yes | 3 |
| # 4 | 2 | 4 | yes | 4 |
+----------+----------+-----------+--------------+----------+
所以我试图找到一种方法允许在我的应用程序的前端进行 OR 操作,然后在后端服务器上转换条件,然后后端服务器将与 Intrinio(财务数据 API ).我尝试使用的端点(以节省 api 通话积分)仅允许使用 AND 运算符,但我希望有某种解决方法。
这是我尝试使用的端点:http://docs.intrinio.com/#securities-search-screener
这只是我要发送到我的服务器进行翻译的示例条件:
open_price > 10 && (current_volume > 1000000 || current_volume > average_volume)
P.S open_price、current_volume 和 average_volume 都是 Intrinio 生态系统中使用的标签
我可能还应该提到他们没有 NOT
我恳求你们在评论之前先看看link...
根据 DeMorgan's laws,a && b
等价于 !(!a || !b)
你可以把and
想成
"
a
andb
are bothtrue
"
或等效
"Neither
a
norb
arefalse
"
先判断average_volume和1000000哪个大然后根据结果选择条件判断:
if(average_volume <= 1000000)
//use this condition: open_price > 10 && current_volume > 1000000
else
//use this condition: open_price > 10 && current_volume > average_volume
一般情况下,你不能。
在此API中,您只能否定原子条件,将~gt~
更改为~lte~
等,e。 G。将 open_price~gt~10
更改为 open_price~lte~10
.
但是你不能否定这个 API 中的非原子条件,特别是你不能使用德摩根定律。
只有3n(+1)个变量的n个布尔函数,可以使用合取和原子否定来表达。 n个变量的布尔函数总数为22ⁿ。顺便说一句,所有这些都可以使用合取和非原子否定来表达。因此,存在无法使用合取和原子否定表达的布尔函数。
您应该发出两个或更多请求,然后在 API 客户端上合并结果。 有几种方法可以做到这一点,它们在请求数量、检索记录总数(某些记录可能被检索多次)以及所需的 API 通话信用(等于数量)方面有所不同条件)。
假设原始数据如下所示(让我们跳过 open_price
属性)。
{
{
"identifier": "A-OK",
"current_volume": 1000002, "average_volume": 1000001
},
{
"identifier": "B-OK",
"current_volume": 1000001, "average_volume": 999999
},
{
"identifier": "D-OK",
"current_volume": 999999, "average_volume": 999998
},
{
"identifier": "E-OK",
"current_volume": 1000001, "average_volume": 1000002
},
{
"identifier": "G-NO",
"current_volume": 999999, "average_volume": 1000001
},
{
"identifier": "H-NO",
"current_volume": 999998, "average_volume": 999999
}
}
您需要检索标识符为 A-OK
、B-OK
、D-OK
、E-OK
.
方法 1(两个请求,结果集不相交)
current_volume~gt~1000000
current_volume~gt~average_volume
如您所见,我们只是在客户端执行析取,而不是在服务器...
方法 2(三个请求,结果集不相交)
current_volume~gt~1000000,current_volume~gt~average_volume
current_volume~gt~1000000,current_volume~lte~average_volume
current_volume~lte~1000000,current_volume~gt~average_volume
在这种方法中,我们依赖于这个事实:A||B
等于 (A && B) ^^ (A && !B) ^^ (!A && B)
。
方法 3(两个请求,结果集不相交)
current_volume~gt~1000000
current_volume~lte~1000000,current_volume~gt~average_volume
在这种方法中,我们依赖于这个事实:A||B
等于 A ^^ (!A && B)
。
方法 4(两个请求,结果集不相交)
在您的特定情况下,存在一种依赖于实数顺序关系的传递性的方法。
average_volume~gt~1000000,current_volume~gt~1000000
average_volume~lte~1000000,current_volume~gt~average_volume
但是,这种方法在 API 话费方面并没有带来多少利润。
比较
+----------+----------+-----------+--------------+----------+
| Approach | Number of| Records | Resultsets | Total |
| | requests | retrieved | disjointness | credits |
+----------+----------+-----------+--------------+----------+
| # 1 | 2 | 6 (3+3) | no | 2 |
| # 2 | 3 | 4 | yes | 6 |
| # 3 | 2 | 4 | yes | 3 |
| # 4 | 2 | 4 | yes | 4 |
+----------+----------+-----------+--------------+----------+