python - 如何使用 gremlin 和 python 在海王星中进行组合布尔运算?
问题描述
我正在尝试做一个查询,我有多个布尔运算要完成,但不知道该怎么做。
查询类似于(A and B) or (C and D)
我第一次尝试
g.V()\
.has("attra", P.lte(20))\
.has("attrb", P.gte(10))\
.or_()\
.has("attrc", P.lte(20))\
.has("attrd", P.gte(10))
但事实证明,or_()
在查询中的or
ed 之后的任何内容都不是我想要的。因为我还有其他复杂的布尔逻辑。
我也试过
g.V()\
.or_(
has("attra", P.lte(20)).and().has("attrb", P.gte(10)),
has("attrc", P.lte(20)).and().has("attrd", P.gte(10))
)
但它说has
没有定义。你是这样做的吗?这甚至在哪里定义?
非常感谢您的帮助
编辑:我的文件中有以下导入
from __future__ import print_function
from gremlin_python.structure.graph import Graph
from gremlin_python.process.strategies import *
from gremlin_python.process.traversal import *
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
from gremlin_python.process.graph_traversal import __ as AnonymousTraversal
解决方案
我找到了has
定义的地方。
在这里能找到它
from gremlin_python.process.graph_traversal import __ as AnonymousTraversal
所以我们就这样做
has = AnonymousTraversal.has
并像这样查询
g.V()\
.or_(
has("attra", P.lte(20)).and().has("attrb", P.gte(10)),
has("attrc", P.lte(20)).and().has("attrd", P.gte(10))
)
推荐阅读
- sql-server - 如何从 Group By 中的复杂子查询中获取值?
- python - 如何在 Python 中展平嵌套的 Json 文件?
- php - 在 Woocommerce 3 中替换外部运输服务的付款方式标题
- excel - 带有 Application.GetSaveAsFilename 或 Application.Dialogs(xlDialogPrinterSetup) 的 excel vba 错误
- windows - RabbitMQ 安装 - 启用插件后避免服务重启
- arrays - Swift - 如果字符串为零。不要将其添加到数组中
- jcr - jackrabbit - 调用 javac 时出错。需要完整的 JDK(不仅仅是 JRE)
- gridview - Xamarin Forms 按钮在 Grid 内变平
- python - 如何使用 Python 更改文本并按下提交按钮?
- php - Laravel 5.6 - 在降价中使用 @foreach