Skip to content

Commit

Permalink
adding centrality example
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Jan 29, 2012
1 parent b67bd6e commit b48cf0a
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions examples/greatest.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require 'rubygems'
require 'neography'

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

game = create_great('The 1958 NFL Championship Game')
brando = create_great('Marlon Brando')
alex = create_great('Alexander the Great')
circus = create_great('The Ringling Bros. and Barnum and Bailey')
beatles = create_great('The Beatles')
ali = create_great('Muhammad Ali')
bread = create_great('Sliced Bread')
gatsby = create_great('The Great Gatsby')

greats = [game,brando,alex,circus,beatles,ali,bread,gatsby]

def as_great(great, other_greats)
other_greats.each do |og|
great.outgoing(:as_great) << og
end
end

greats.each do |g|
ogs = greats.select{|v| v != g }.sample(1 + rand(5))
as_great(g, ogs)
end

def the_greatest
neo = Neography::Rest.new
neo.execute_script("m = [:];
c = 0;
g.
V.
out.
groupCount(m).
loop(2){c++ < 1000}.iterate();
m.sort{a,b -> b.value <=> a.value}.keySet().name[0];")
end

puts "The greatest is #{the_greatest}"

0 comments on commit b48cf0a

Please sign in to comment.