Tag Archives: ruby

Using Three.js with Neo4j

Last week we saw Sigma.js, and as promised here is a graph visualization with Three.js and Neo4j. Three.js is a lightweight 3D library, written by Mr. Doob and a small army of contributors.

The things you can do with Three.js are amazing, and my little demo here doesn’t give it justice, but nonetheless I’ll show you how to build it.
Continue reading

Tagged , , , , , ,

Using Sigma.js with Neo4j

I’ve done a few posts recently using D3.js and now I want to show you how to use two other great Javascript libraries to visualize your graphs. We’ll start with Sigma.js and soon I’ll do another post with Three.js.
Continue reading

Tagged , , , , , ,

Connections in Time

Some relationships change over time. Think about your friends from high school, college, work, the city you used to live in, the ones that liked you ex- better, etc. When exploring a social network it is important that we understand not only the strength of the relationship now, but over time. We can use communication between people as a measure.

I ran into a visualization that explored how multiple parties where connected by communications in multiple projects. We’re going to reuse it to explore how multiple people interact with each other. So let’s make a network of 50 friends and connect them to each other multiple times. Think of it as people writing on your facebook wall.
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 , , , , ,

Visualizing a Network with Cypher and D3.js

We’ve seen some pretty nice visualizations of nodes and their immediate neighbors, but we want to be able to visualize more. So we’re going to prepare a 200 node network, use Cypher to extract the data we want and visualize it with D3.js.
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 , , , , ,

Chicago Graph DB Meet-Up

We had our first Graph Database Meet-up in Chicago yesterday!

16 Graphistas came out to learn more about the craft and get an introduction to Neo4j. Ryan Briones from Groupon gave us a venue and helped host the event. No worries if you missed it, your next chance to learn more about Neo4j is coming up on Tuesday February 7th @ 6pm, when Prasanna Pendse will share his experiences with Neo4j at ChicagoRuby: Downtown.

Our next Chicago Graph DB meet-up is tentatively scheduled for February 29th @ 6 pm. This will be a hands-on meet-up. I’ll help you get started with either Neo4j on your laptop or in the cloud with Heroku. We’ll create a few graphs, learn some basic traversals and get comfortable with Neo4j. I’ll have a GitHub repository graph for us to play with and see how you are connected to Kevin Bacon (err I mean Linus Torvalds). He is the center of the GitHub universe right? Right? We’ll let’s find out.

The slides of our first meet-up are available below:

Tagged , , , , ,

Neo4j on Heroku – Part Three

This week we learned that leaving the create_graph method accessible to the world was a bad idea. So let’s go ahead and delete that route in Sinatra, and instead create a Rake Task for it.

In Rakefile:

require 'neography/tasks'
require './neoflix.rb'

namespace :neo4j do
  task :create do
    neo = Neography::Rest.new(ENV['NEO4J_URL'] || "http://localhost:7474")
    create_graph(neo)
  end
end

That’s much better. We can create our graph locally with
Continue reading

Tagged , , , ,

Graph Visualization and Neo4j

So far we’ve learned how to get Neo4j up and running with Neography, how to find friends of friends and degrees of separation with the Neo4j REST API and a little bit of the Gremlin and Cypher languages. However, all we’ve seen is text output. We haven’t really “seen” a graph yet, but that’s about to change.

Vouched holds a graph of skill specific recommendations people have made to each other and visualizes it. I extracted the visualization, and hosted it on github as neovigator. You can get your very own visualization up and running or take a look at this instance running on Heroku.

Continue reading

Tagged , , , , , ,

Cypher with Neography

Cypher is the query language of Neo4j, 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 cypher query to Neo4j via the REST API and neography using the execute_query command. Let’s implement suggestions_for so it sends a cypher query to the server:

def suggestions_for(node)
  node_id = node["self"].split('/').last.to_i
  @neo.execute_query("START me = node({node_id})
                      MATCH (me)-[:friends]->(friend)-[:friends]->(foaf)
                      RETURN foaf.name", {:node_id => node_id})["data"]
end

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

# RESULT
# Johnathan should become friends with Mary, Phil

Continue reading

Tagged , , ,