Category Archives: Gremlin

Slides from Chicago Graph Database April Meet-up

Thank you again to Groupon Engineering! They hosted our Graph Database Meet-up at their Headquarters.

Join us May 31st, 2012 for our next meet-up Add data from your existing Application into Neo4j.

Tagged , ,

Visualizing a set of Hiveplots with Neo4j


What should a graph look like and how can I tell two graphs apart?

Continue reading

Tagged , , , , , ,

JUNG in Neo4j – Part 2

A few weeks ago I showed you how to visualize a graph using the chord flare visualization and how to visualize a network using a force directed graph visualization from D3.js.

On Twitter Claire Willett from Riparian Data asked:
https://twitter.com/#!/RiparianData/status/169099913580396544

This post on Graphs Beyond the Hairball by Robert Kosara explains why some non-traditional graph visualizations may work better and links us to an article explaining what a Node Quilt is and how it’s useful. We’re going to just take the first step and build a Matrix representation of a graph. We will use one of the JUNG clustering algorithms to help us understand it.
Continue reading

Tagged , , , , ,

JUNG in Neo4j – Part 1

It’s nice to have an arsenal. In the world of graph databases, one such stock room is the Java Universal Network/Graph Framework(JUNG) which contains a cache of algorithms from graph theory, data mining, and social network analysis, such as routines for clustering, decomposition, optimization, random graph generation, statistical analysis, and calculation of network distances, flows, and importance measures (centrality, PageRank, HITS, etc.).

We can use JUNG via the Blueprints ouplementation and access it via Gremlin. It doesn’t come pre-packaged with Neo4j, but Michael Hunger playing the role of “Tank” and was able to load up our stock room with a few key strokes.
Continue reading

Tagged , , , , ,

Max Flow with Gremlin and Transactions

The maximum flow problem was formulated by T.E. Harris as follows:

Consider a rail network connecting two cities by way of a number of intermediate cities, where each link of the network has a number assigned to it representing its capacity. Assuming a steady state condition, a nd a maximal flow from one given city to the other.

Back in the mid 1950s the US Military had an interest in finding out how much capacity the Soviet railway network had to move cargo from the Western Soviet Union to Eastern Europe. This lead to the Maximum Flow problem and the Ford–Fulkerson algorithm to solve it.
Continue reading

Tagged , , , , ,

Who is the Greatest?

I done wrestled with an alligator, I done tussled with a whale, only last week I murdered a rock, injured a stone, hospitalized a brick. I’m so mean I make medicine sick.

He floats like a butterfly and stings like a bee, but is Muhammad Ali truly the greatest? Greater than the Beatles? Greater than Alexander? Greater than Sliced Bread? Let’s find out.

We begin by requiring neography and creating a function to help us create the greats.

require 'rubygems'
require 'neography'

def create_great(name)
  Neography::Node.create("name" => name)
end

There are a ton of greats out there, but we’ll keep it simple and create just 8 of the greatest greats.
Continue reading

Tagged , , , , ,

Neo4j on Heroku – Part Two

We are picking up where we left off on Neo4j on Heroku –Part One so make sure you’ve read it or you’ll be a little lost. So far, we have cloned the Neoflix project, set up our Heroku application and added the Neo4j add-on to our application. We are now ready to populate our graph.

UPDATE: Learn a better way to create the graph in part 3 of my Neo4j on Heroku series.

Bring up two browser windows. On one you’ll go to your Neo4j instance running on Heroku,

$ heroku config
NEO4J_URL      => http://xxxxxxxx:yyyyyyyy@70825a524.hosted.neo4j.org:7014

and on the other you’ll go to the create_graph route of your app. So if you named your app neoflix, you’d go to neoflix dot herokuapp dot com/create_graph.

This will run the create_graph method and you’ll see nodes and relationships being created on the Neo4j Dashboard. It’s just over a million relationships, so it will take a few minutes. There are faster ways to load data into Neo4j (wait for part three of this series), but this will work in our case.
Continue reading

Tagged ,

Neo4j on Heroku – Part One

On his blog Marko A. Rodriguez showed us how to make A Graph-Based Movie Recommender Engine with Gremlin and Neo4j.

In this two part series, we are going to take his work from the Gremlin shell and put it on the web using the Heroku Neo4j add-on and altering the Neovigator project for our use case. Heroku has a great article on how to get an example Neo4j application up and running on their Dev Center and Michael Hunger shows you how to add JRuby extensions and provides sample code using the Neo4j.rb Gem by Andreas Ronge.

We are going to follow their recipe, but we are going to add a little spice. Instead of creating a small 2 node, 1 relationship graph, I am going to show you how to leverage the power of Gremlin and Groovy to build a much larger graph from a set of files.

Let’s start by cloning the Neoflix Sinatra application, and instead of installing and starting Neo4j locally, we are going to create a Heroku application, and add Neo4j.

git clone git@github.com:maxdemarzi/neoflix.git
cd neoflix
bundle install
heroku apps:create neoflix --stack cedar
heroku addons:add neo4j
git push heroku master

Continue reading

Tagged

Gremlin with Neography

Gremlin is a domain specific language for traversing property graphs. Neo4j is one of the databases that can speak the gremlin language, and as promised I’ll show you how you can use it to implement friend recommendations as well as degrees of separation.

We can send any gremlin script to Neo4j via the REST API and neography using the execute_script command. Let’s implement suggestions_for so it sends a gremlin script to the server:

def suggestions_for(node)
  node_id = node["self"].split('/').last.to_i
  @neo.execute_script("g.v(node_id).
                         in('friends').
                         in('friends').
                         dedup.
                         filter{it != g.v(node_id)}.
                         name", {:node_id => node_id})
end

puts "Johnathan should become friends with #{suggestions_for(johnathan).join(', ')}"

# RESULT
# Johnathan should become friends with Mary, Phil

Continue reading

Tagged , , , ,