The goal
I have a simple enough task to accomplish: Set the weight of a specific edge property. Take this scenario as an example:
What I would like to do is update the value of weight
.
Additional Requirements
- If the edge does not exist, it should be created.
- There may only exist at most one edge of the same type between the two nodes (i.e., there can't be multiple "votes_for" edges of
type
"eat" between Joey and Pizza. - The task should be solved using the Java API of Titan (which includes Gremlin as part of TinkerPop 3).
What I know
I have the following information:
- The Vertex labeled "user"
- The edge label
votes_for
- The value of the edge property
type
(in this case, "eat") - The value of the property
name
of the vertex labeled "meal" (in this case "pizza"), and hence also its Vertex.
What I thought of
I figured I would need to do something like the following:
- Start at the Joey vertex
- Find all outgoing edges (which should be at most 1) labeled
votes_for
havingtype
"eat" and an outgoing vertex labeled "meal" havingname
"pizza". - Update the
weight
value of the edge.
This is what I've messed around with in code:
//vertex is Joey in this case
g.V(vertex.id())
.outE("votes_for")
.has("type", "eat")
//... how do I filter by .outV so that I can check for "pizza"?
.property(Cardinality.single, "weight", 0.99);
//... what do I do when the edge doesn't exist?
As commented in code there are still issues. Would explicitly specifying a Titan schema help? Are there any helper/utility methods I don't know of? Would it make more sense to have several vote_for
labels instead of one label + type
property, like vote_for_eat
?
Thanks for any help!