I am trying to map ontology terms to a Neo4j data-structure.
To be precise I have a Term
class and 2 types of relationships (is_a
and part_of
).
I have following classes:
Term class:
@NodeEntity
public class Term {
@GraphId
private Long nodeId;
@Indexed(unique=true)
private String id;
private String name;
private String definition;
@RelatedToVia(type="is_a",direction=Direction.INCOMING)
private Set<Term2Term> is_a_children;
@RelatedToVia(type="is_a",direction=Direction.OUTGOING)
Set<Term2Term> is_a_parents;
@RelatedToVia(type="part_of",direction = Direction.INCOMING)
Set<Term2Term> part_of_children;
@RelatedToVia(type="part_of",direction = Direction.OUTGOING)
Set<Term2Term> part_of_parents;
}
Term2Term class:
@RelationshipEntity
public class Term2Term {
@GraphId
Long id;
@StartNode private Term child;
@EndNode private Term parent;
}
The mapping works fine and accessing the specific collections (i.e. is_a_children) works fine.
However I have a use case where I have to populate a NavigationTree
with the data. It should look something like this:
-Term 1
- Term 1.1 (is_a)
-Term 1.1.1 (part_of)
- Term 1.2 (part_of)
- Term 1.3 (is_a)
- Term 1.3.1 (part_of)
- Term 1.3.2. (is_a)
....
The NavigationalTree
has no notion of the different relationship types.
I need to combine the different relationship collections (i.e. is_a_children and part_of_children) to one collection and still keep the information about the type of relationship (in order to display it)
Of course I can create a getter which does a Sets.union
(guava) of the two sets, however this way I lose the information about the relationship type.
The only non-hackish way would be to use one generic relationship type instead of the two relationship types (is_a,part_of) in the graph database and add the type as a property to the relationship.
Is there any other way?
Update 1:
It seems that I have to use inheritence to solve it
Spring Data Neo4j - @RelationshipType issues
http://forum.springsource.org/showthread.php?124110-neo4j-Inheritance-with-RelationshipEntities&highlight=neo4j+inheritance+with+relationshipentities