[TinkerPop] Multi-Label Support in Neo4jGraph

Skip to first unread message

Marko Rodriguez

Dec 19, 2014, 12:31:25 PM12/19/14
to gremli...@googlegroups.com

TinkerPop3 supports a single label for an Element: Vertex, Edge, or VertexProperty. In Neo4j, a Node can have an arbitrary number of labels, while a Relationship can only have one. In order deal with this mismatch, we introduced three Neo4jVertex specific methods:

public Set<String> labels()
public void removeLabel(final String label)
public void addLabel(final String label)

You can see how this works in practice by studying the following example:

Note that this is Gremlin I/O safe as there is no data loss when reading or writing to/from GraphML, GraphSON, Kryo, etc. If you export a Neo4jGraph with multi-labels on vertices to import it into, lets say, TinkerGraph, then the vertex label would be "person::organism" (simply a concatenation of the labels). 

An open question is: "what is the best delimiter?" Right now its "::". I was thinking of that we could make this user defined based on a configuration option --- but perhaps its adding too many degrees of freedom that may not be worth the testing/verification logic. Is "::" good for others? Note that Neo4j recommends that labels be camel cased (e.g. "SuperHuman"). Likewise, TinkerPop recommends the same. Perhaps the delimiter is a \s (space) or , (comma) with whitespace trim?

*** The code is currently in SNAPSHOT and will be released in TinkerPop 3.0.0.M7.


Willem Salembier

Jan 21, 2015, 5:56:09 PM1/21/15
to gremli...@googlegroups.com
Hi Marko,

Can you elaborate a bit on the choice for having only one label per vertex in Tinkerpop 3? Wouldn't it be a nice functionality to express inheritance using multi-labels e.g. Animal, Dog, Shepherd?
Or do you favor the approach of giving the most specific label and link to a meta-model expressing the relations, Like v[1] -- isa --> Shepher -- isa --> Dog -- isa --> Animal?
Or instead having the application keeping a register of all labels related to a base entity, eg Animal = Dog + Shepher

Reply all
Reply to author
0 new messages