Search code examples
gephitinkerpop3datastax-enterprise-graph

Specify an edgeLabel in graphML that tinkerpop can understand


I have been struggling to load a graphml in to Tinkerpop3.

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

While loading, I want the the edges to have a label.

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

The above code always prints the labels as edge for all the edges in the graphml. My graphml snippets.

<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>

And the key definition

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

I am use DSE 5.1.3's java driver and tinkerpop 3.2.5 is used via a transitive dependency and used Gephi to author the graphml.


Solution

  • By default, your edge label will be recognized if you do define the key as:

    <key id="labelE" for="edge" attr.name="labelE" attr.type="string" /> 
    

    The important part being that the attr.name is defaulted to "labelE". See the IO Reference documentation for GraphML here. Note that the default can be changed when you instantiate the GraphMLReader.Builder object by setting the edgeLabelKey value on the builder itself.