- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Gremlin-Python 客户端通过 janusgraph 后端查询 Gremlin 服务器。
运行以下查询:
graph = Graph()
g = graph.traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','g'))
sg = g.E().subgraph('a').cap('a').next()
查询返回一个包含边和顶点列表的子图。
我在服务器上配置了以下序列化器
serializers:
- { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
- { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0, config: { serializeResultToString: true }}
- { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
Does anyone know how to configure gremlin-server and a sample code to return a fully populated subgraph?
根据 Stephen 的反馈更新了测试用例
# DB: Janusgraph with Opensource Cassandra storage backend
# Data: v[41427160]--reports_to-->v[36712472]--reports_to-->v[147841048]
# Objective: get subgraph detached to python client with all properties of the vertex and edges
(py365)$ pip list | grep gremlinpython
gremlinpython 3.3.4
(py365)$ python
Python 3.6.5 (default, Apr 25 2018, 14:26:36)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from gremlin_python.driver import client
>>> from gremlin_python.driver.serializer import GraphSONSerializersV3d0
>>> session = client.Client('ws://localhost:8182/gremlin', 'g', message_serializer=GraphSONSerializersV3d0())
>>> query_parameters = {"vids": [41427160, 36712472]}
>>> query = "g.V(vids).outE('reports_to').subgraph('1').otherV().cap('1').next()"
>>> results = session.submit(query, query_parameters)
>>> for r in results:
... r_vertices = r[0]['@value'].get('vertices')
... r_edges = r[0]['@value'].get('edges')
... print(r)
... print(r_vertices)
... print(r_edges)
...
[{'@type': 'tinker:graph', '@value': {'vertices': [v[41427160], v[147841048], v[36712472]], 'edges': [e[{'@type': 'janusgraph:RelationIdentifier', '@value': {'relationId': '21y8ez-onxeg-f11-luviw'}}][41427160-reports_to->36712472], e[{'@type': 'janusgraph:RelationIdentifier', '@value': {'relationId': '225dz7-luviw-f11-2g0qvs'}}][36712472-reports_to->147841048]]}}]
[v[41427160], v[147841048], v[36712472]]
[e[{'@type': 'janusgraph:RelationIdentifier', '@value': {'relationId': '21y8ez-onxeg-f11-luviw'}}][41427160-reports_to->36712472], e[{'@type': 'janusgraph:RelationIdentifier', '@value': {'relationId': '225dz7-luviw-f11-2g0qvs'}}][36712472-reports_to->147841048]]
>>>
Is it true that gremlinpython is lightweight that, even when using script based approach, only necessary elements(id and label) are detached as "reference elements" part of the graphson?
最佳答案
您无法使用 Gremlin Python(或与此相关的任何其他语言变体)将 subgraph()
步骤的结果作为 Graph
完全返回。问题是 Gremlin Python 是 Gremlin 的轻量级实现,因此没有图形数据结构实例来反序列化返回的数据。
此时,唯一的解决方法是简单地返回构成图形的数据,然后您必须将该数据存储到 Python 中类似图形的东西中。所以也许你会这样做:
g.E().project('edgeId','label','inId','outId').
by(id).
by(label).
by(inV().id()).
by(outV().id())
这将以 Map
的形式返回子图结构所需的最少数据,然后您可以在 Python 中对这些数据执行某些操作。
我认为不太推荐的另一个选项是使用 Python 提交脚本,而不是使用基于字节码的请求。使用脚本,您将获得子图的 GraphSON 表示,然后您可以根据需要将其解析为 Python 中的某些数据结构。这是您需要发送的等效脚本:
gremlin> graph = g.E().hasLabel('knows').subgraph('sg').cap('sg').next()
==>tinkergraph[vertices:3 edges:2]
gremlin> mapper = GraphSONMapper.build().addRegistry(TinkerIoRegistryV3d0.instance())create().createMapper()
==>org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper@f6de586
gremlin> mapper.writeValueAsString(graph)
==>{"@type":"tinker:graph","@value":{"vertices":[{"@type":"g:Vertex","@value":{"id":{"@type":"g:Int32","@value":1},"label":"person","properties":{"name":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":0},"value":"marko","label":"name"}}],"age":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":1},"value":{"@type":"g:Int32","@value":29},"label":"age"}}]}}},{"@type":"g:Vertex","@value":{"id":{"@type":"g:Int32","@value":2},"label":"person","properties":{"name":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":2},"value":"vadas","label":"name"}}],"age":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":3},"value":{"@type":"g:Int32","@value":27},"label":"age"}}]}}},{"@type":"g:Vertex","@value":{"id":{"@type":"g:Int32","@value":4},"label":"person","properties":{"name":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":6},"value":"josh","label":"name"}}],"age":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":7},"value":{"@type":"g:Int32","@value":32},"label":"age"}}]}}}],"edges":[{"@type":"g:Edge","@value":{"id":{"@type":"g:Int32","@value":7},"label":"knows","inVLabel":"person","outVLabel":"person","inV":{"@type":"g:Int32","@value":2},"outV":{"@type":"g:Int32","@value":1},"properties":{"weight":{"@type":"g:Property","@value":{"key":"weight","value":{"@type":"g:Double","@value":0.5}}}}}},{"@type":"g:Edge","@value":{"id":{"@type":"g:Int32","@value":8},"label":"knows","inVLabel":"person","outVLabel":"person","inV":{"@type":"g:Int32","@value":4},"outV":{"@type":"g:Int32","@value":1},"properties":{"weight":{"@type":"g:Property","@value":{"key":"weight","value":{"@type":"g:Double","@value":1.0}}}}}}]}}
我们将在未来版本的 TinkerPop 中重新考虑子图化如何适用于不同的语言变体,但目前我们只有这些解决方案。
关于Gremlin-Python : Returning a fully populated subgraph,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54045859/
我在 MongoDb 上有具有以下结构的文档, 我正在将 Mongoose 版本 ^4.8.1 与我的 Node 应用程序一起使用。我为上述文档创建了 3 个模式模型,如下所示, Event.js v
选择查询在 waterline-postgresql 的 .populate() 中不起作用。 Model.find(query).populate(assoc.alias,{select:['fie
我正在创建三个下拉菜单,它工作得很好,但我希望第二个下拉列表出现在第一个的选择上,第三个出现在第二个的选择上如何如果有人可以指导我或给我一个例子,我将不胜感激 PS:第二个下拉列表或表有一个来自第一个
我正在尝试使用 Show 模型中的数据填充()我的 User 模型中的所有订阅。我已经尝试过 .populate('subscriptions.show') 但它对结果没有任何作用。 如果我将订阅设置
我有一个集合,它有一个引用另一个集合的 objectId 的属性。 placeSchema = mongoose.Schema({ name: String, category: [{
我有一个像这样的 Mongoose 模式: var Address = { doorNo:String, city:String, state:String, coun
我有以下带有选择多个属性的下拉菜单,我需要将它们转换为普通下拉菜单,保持其功能: 从此: 对此: 以下是带有绑定(bind)的选择下拉列表: 下拉列表最初是从 foreach
我在 Kotlin 上使用 MongoDB 和 Spring,我希望我的应用程序在启动时填充 MongoDB 集合。 (并在每次启动时清洁它) 我的问题是,如果我正在填充的某些数据有问题,我该如何一一
org.apache.commons.beanutils.BeanUtils: BeanUtils.populate(Object bean, Map properties); Populate th
目前,我正在尝试使用一副纸牌填充 ArrayList,通过使用 for 循环来获取每张纸牌。它并没有完全按照我的预期工作,我希望有人能为我指明正确的方向。 我看到以下错误: System.Argume
我正在使用 MongooseDeepPopulate项目的包。我有 SchemaA、SchemaB、SchemaC、SchemaD。我的 SchemaD、SchemaC 连接到 SchemaB,而 S
我正在尝试更好地掌握 Express.js,并尝试创建一个简单的博客网站。 我的用户模型很简单:用户名、显示名称和一系列帖子。 const userSchema = new Schema({
我尝试了几种不同的方法,但我就是无法让 Mongoose 将 Users 信息填充到 Items 集合中。 文件:users.js var mongoose = require( 'mongoose'
我正在为 Spring Batch 作业编写集成测试。我想在每次测试之前使用存储库填充器将测试数据加载到内存数据库中。 到目前为止,我找到的示例似乎表明存储库填充器只会在上下文初始化时填充一次。这对我
这个问题已经有答案了: Get multiple elements by Id (15 个回答) 已关闭 8 年前。 我的网站中有 2 个下拉菜单,一个适用于用户使用手机时,另一个适用于用户使用桌面时
我正在使用 swift 构建一个 iPhone 应用程序,并且我有一个矩形横幅广告,我正试图展示它。我已经为 iAds 正确设置了我的 Dev 帐户,但广告没有填充到应用程序中。我得到了一个测试广告,
我想用指定的用户查询图像表,但我的代码不起作用。 Image.find().populate('user', { id : '1' }).sort({ updatedAt: 'desc' }).exe
所以我有我的改革对象,我想在验证之前解析我的字符串数据,以便能够使用干式验证 需要(:我的字段)。填充(GT?:0) 为了做到这一点,我使用 populator 属性:membership_fee,填
我有一个程序已经运行良好几个月了。今天早上我一直在尝试在服务器上安装 Postfix,突然网站上出现错误。这是回溯 mod_wsgi (pid=11948): Target WSGI script '
我使用函数.populate() 来获取按类别 分组的equipements,所以我的模型是这样的 var mongoose = require('../config/db'); var Equipe
我是一名优秀的程序员,十分优秀!