在 graphML 中指定一个 tinkerpop 可以理解的 edgeLabel

Specify an edgeLabel in graphML that tinkerpop can understand

我一直在努力将 graphml 加载到 Tinkerpop3。

Graph graphMLGraph = TinkerGraph.open();
graphMLGraph.io(IoCore.graphml()).readGraph(file.getAbsolutePath());

加载时,我希望边缘有标签。

graphTraversalSource.E().toStream().forEach(edge -> {
      System.out.println(edge.label());
    });

上面的代码总是将 graphml 中所有边的标签打印为 edge。我的 graphml 片段。

<edge id="1" source="1" target="3">
<data key="edgelabel">belongs-to</data>
<data key="weight">1.0</data>
</edge>
<edge id="2" source="1" target="4">
<data key="weight">1.0</data>
<data key="edgelabel">part-of</data>
</edge>

以及关键定义

<key attr.name="Edge Label" attr.type="string" for="edge" id="edgelabel"/>

我使用 DSE 5.1.3 的 java 驱动程序,tinkerpop 3.2.5 通过传递依赖使用,并使用 Gephi 编写 graphml。

默认情况下,如果您将键定义为:

,您的边缘标签将被识别
<key id="labelE" for="edge" attr.name="labelE" attr.type="string" /> 

重要的部分是 attr.name 默认为 "labelE"。请参阅 GraphML here 的 IO 参考文档。请注意,当您通过在构建器本身上设置 edgeLabelKey 值来实例化 GraphMLReader.Builder 对象时,可以更改默认值。