【问题标题】:View Neptune Graph Schema using Jupyter notebook使用 Jupyter notebook 查看 Neptune Graph Schema
【发布时间】:2020-07-03 04:36:37
【问题描述】:
有没有办法使用 Jupyter Notebook 查看 Neptune 集群中的图表架构?
就像您在使用 SQL 的 RDS 中执行“select * from tablename limit 10”一样,有没有办法通过 Jupyter Notebook 了解图形数据?
【问题讨论】:
标签:
gremlin
amazon-sagemaker
amazon-neptune
gremlinpython
graph-notebook
【解决方案1】:
这取决于您的图表有多大以及它的性能如何,但您可以使用下面的示例来了解您拥有的节点和边的类型。根据您使用的标签,我假设您使用的是 Gremlin:
g.V().groupCount().by(label)
g.E().groupCount().by(label)
如果您有一个非常大的图表,请尝试在 groupCount 步骤之前添加类似 limit(100000) 的内容。
如果您使用的是 Python 之类的编程语言(安装了 gremlin python),那么您需要在查询中添加 next() 终端步骤,如下所示:
g.V().groupCount().by(label).next()
g.E().groupCount().by(label).next()
找到标签和标签的分布后,您可以使用其中之一来探索一些属性。假设有一个名为“人”的标签。
g.V().hasLabel('person').limit(10).valueMap().toList()
请记住,对于 Gremlin 属性图,具有相同标签的顶点可能不一定具有所有相同的属性,因此最好查看多个顶点以了解这一点。
【解决方案2】:
如果您想可视化您的图表,即。想要查看给定根节点下的所有子节点,那么您可以在 jupyter 笔记本单元格中使用下面的 gremlin 查询。
%%gremlin -p v,e
g.V({label},{property},{value})
.repeat(outE().inV()).until(outE().count().is(0)).path()
.by(valueMap({propertiesList})).by(label)
改变
- {label} : 顶点标签
- {property}:要过滤的顶点属性
- {value} : 道具的价值
- {propertiesList}:要在图中显示的顶点属性列表