Indexing time and URI’s in jo4neo

January 6th, 2010 § 0

Graphs in and of themselves are not self indexing like relational databases, however, you can construct indexes via strong relationships between the nodes of interest.  The pattern I’ll be discussing in this post maps time (year, month, day, hour) into a graph format as nodes and edges.  Once time, or some subset, is represented as a graph we can then associate events or moment intervals as nodes related to a particular hour of a particular day, month and year.  ( This post is based on a full example here.)

Modeling a year

A year has an integer value and inverse relationship to months. Its easily created given a Java Calendar instance. Inverse relations are passive, and driven by the object on the other end. Generally speaking I find that it is easier to manage relationships from the singular end (declare that a child has a particular parent).

public class Year extends Base {
	@neo(inverse="hasYear") public Collection months;
	@neo(index=true) public int value;

	public Year() {}

	public Year(Calendar cal) {
		value = cal.get(Calendar.YEAR);
	} ...

Month, day and hour follow a similar pattern. We could keep going, however, an hour seems like a good place to stop. In the example code, hour nodes are sparse. They are only created by necessity, and that meaning an event occurred during that hour. So we need an event class. The example focuses on tweets, so in addition we’ll make a Tweet class that extends event:

public class Event extends Base {
	@neo public String content;
	@neo public Date time;
	@neo public String title;
	@neo public Hour hour;
}

public class Tweet extends Event {
	@neo public URI from;
}

Notice that the only thing added to the basic event was a URI of the tweet author.

URI’s are special

On the internet URI’s are special. They are effectively a type of currency within WEB 2.0. We trade them, collect them, talk about them, and tweet them. And in many online communities people are URI’s. jo4neo treats URI’s as nodes, and there can only be one node per unique URI. This will allow us to ask for any given twitter, which tweets have they made recently. One such twitter is http://twitter.com/communicating.   Here’s an example of one of @communicating’s tweets in the graph:

“In 2010 data rules, companies to watch = #80Legs & #InfoChimps (Amazon will acquir). Systems to watch = #Pellet (MS should acquire) & #Neo4j”

Good tweet.  80legs (right here in my home state of Texas) does look interesting, and there’s neo4j, last but  not least.  By centering on the URI node, we can quickly see all the other tweets posted by @communicating:

I’ll cover the method used to populate the graph in a later post.  If you can’t wait just dig into the code at http://code.google.com/p/jo4neo/source/browse/#svn/trunk/patterns/time.

Tagged: , ,

§ Leave a Reply

What's this?

You are currently reading Indexing time and URI’s in jo4neo at The Web Semantic.

meta