From b48cf0a9e202fda94f66518d41c8345de8f42357 Mon Sep 17 00:00:00 2001 From: Max De Marzi Date: Sun, 29 Jan 2012 21:11:49 +0000 Subject: [PATCH] adding centrality example --- examples/greatest.rb | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 examples/greatest.rb diff --git a/examples/greatest.rb b/examples/greatest.rb new file mode 100644 index 0000000..ec8ef42 --- /dev/null +++ b/examples/greatest.rb @@ -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}" \ No newline at end of file