【问题标题】:Correct Way to Read GraphML files with Gremlin using Groovy使用 Groovy 使用 Gremlin 读取 GraphML 文件的正确方法
【发布时间】:2016-06-19 05:43:22
【问题描述】:

我正在尝试读取 GraphML 文件并将其与 Gremlin 遍历一起使用。我正在使用与此页面上相同的代码:

http://tinkerpop.apache.org/docs/3.1.1-incubating/reference/

我使用 writeGraph 编写示例图,然后使用 readGraph 将其读回。图上的 toString() 调用使它 似乎正确读取了图形(每个都有 6 个节点和 6 个顶点),但随后仅应用 Gremlin 遍历 为 TinkerFactory 图生成输出,而不是读入的输出。

代码

@Grab('org.apache.tinkerpop:tinkergraph-gremlin:3.1.1-incubating')
@Grab('org.apache.tinkerpop:gremlin-core:3.1.1-incubating')

import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.io.IoCore;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;

final Graph graph = TinkerFactory.createModern();
graph.io(IoCore.graphml()).writeGraph("test.xml");
final Graph newGraph = TinkerGraph.open();
newGraph.io(IoCore.graphml()).readGraph("test.xml");

def g = graph.traversal();
def n = newGraph.traversal();

println("Graph")
println(g.toString())
g.V(1).out().values('name').sideEffect{println it}.iterate()

println("newGraph")
println(n.toString())
n.V(1).out().values('name').sideEffect{println it}.iterate()

println("DONE")

输出

Graph
graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
lop
vadas
josh
newGraph
graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
DONE

代码似乎与 GraphSON 和 Gyro 输出一起使用。

【问题讨论】:

    标签: groovy gremlin


    【解决方案1】:

    这是来自 Gremlin-Users 邮件列表的related post。当您阅读newGraph 时,ID 被视为String。您可以通过像这样配置 vertexIdManager 来更改此行为:

    def conf = new org.apache.commons.configuration.BaseConfiguration();
    conf.setProperty("gremlin.tinkergraph.vertexIdManager","LONG");
    final Graph newGraph = TinkerGraph.open(conf);
    newGraph.io(IoCore.graphml()).readGraph(dest);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多