In order to populate the graph database with relationships gleaned from Twitter status messages, we need to implement the GraphTupleProcessor
interface. The following code illustrates parsing the Twitter status message's JSON object and creating "user"
and "hashtag"
vertices with "mentions"
relationships.
TweetGraphTupleProcessor.java public class TweetGraphTupleProcessor implements GraphTupleProcessor { @Override public void process(Graph g, TridentTuple tuple, TridentCollector collector) { Long timestamp = tuple.getLong(0); JSONObject json = (JSONObject)tuple.get(1); Vertex user = findOrCreateUser(g, (String)json.get("user"), (String)json.get("name")); JSONArray hashtags = (JSONArray)json.get("hashtags"); for(int i = 0; i < hashtags.size(); i++){ Vertex v = findOrCreateVertex(g, "hashtag", ((String)hashtags.get(i)).toLowerCase()); createEdgeAtTime(g, user, v, "mentions", timestamp...