在IPython Notebook中检索或存储AWS Neptune ML中的Gremlin查询结果



我有一个存储在AWS Neptune上的图形数据库,我需要在Jupyter IPython笔记本中使用gremlin进行查询。我正在将Neptune ML提供的图神经网络功能应用于链接预测任务。具体来说,我想预测"type_x"的哪些节点与保存在变量"id_variable"中的变量有关。

我的查询是这样的:

%%gremlin
g.with("Neptune#ml.endpoint","${endpoint}").
V(${id_variable}).
project('name', 'related to').
by('name').
by( out('RELATED_TO').with("Neptune#ml.prediction").
hasLabel('TYPE_X').values('name') ).
order(local).by(keys, desc)

返回以下输出:

{'name': 'AANAT', 'related to': 'WDR7'}
{'name': 'ACACA', 'related to': 'BTN1A1'}
{'name': 'ACTA1', 'related to': 'MDH'}
{'name': 'ALAS1', 'related to': 'WDR7'}
{'name': 'ALAS2', 'related to': 'TAC3'}
{'name': 'ALDH2', 'related to': 'SOCS2'}
{'name': 'ALDOA', 'related to': 'PRKAB2'}
{'name': 'AKR1B1', 'related to': 'ODF2L'}
{'name': 'ALOX15', 'related to': 'BMP15'}

我的问题是这个输出显示为嵌入在笔记本单元格的输出中;但是,我想将其分配给变量或将其存储到文件中,例如JSON。事实上,我不能用%%gremlin单元格魔法进行变量赋值,到目前为止,我还没有找到任何将输出写入文件的方法。

请注意,我无法通过gremlin_python库在正常的.py脚本中运行此查询,因为它似乎不支持Neptune的ML功能(特别是,它在.with("Neptune#ml.endpoint","${endpoint}")语法上抛出错误)。

欢迎任何建议!

提前谢谢你。

你试过吗——store-to(或-s) param -指定用于存储查询结果的变量名。

?
%%gremlin --store-to results
g.with("Neptune#ml.endpoint","${endpoint}").
V(${id_variable}).
project('name', 'related to').
by('name').
by( out('RELATED_TO').with("Neptune#ml.prediction").
hasLabel('TYPE_X').values('name') ).
order(local).by(keys, desc)

并检查下一个单元格

中的结果变量

最新更新