hits

A poor man’s implementation of Jon Kleinberg’s Hyperlink-Induced Topic Search (HITS) (also known as Hubs and authorities). See en.wikipedia.org/wiki/HITS_algorithm

require ‘rubygems’ require ‘hits’

# create a graph graph = Hits::Graph.new

# add some edges to the graph with weights graph.add_edge(:bsbodden, :objo, 1.0) graph.add_edge(:bsbodden, :nusairat, 2.0) graph.add_edge(:bsbodden, :looselytyped, 3.0) graph.add_edge(:bsbodden, :neal4d, 1.5) graph.add_edge(:objo, :nusairat, 2.5) graph.add_edge(:objo, :bsbodden, 1.0) graph.add_edge(:neal4d, :bsbodden, 1.15) graph.add_edge(:nusairat, :bsbodden, 4.5)

# textual display of the graph puts “graph ==> #graph”

# create a HITS for the graph hits = Hits::Hits.new(graph)

# show the vertexes incoming and outgoing links (inlinks and outlinks) graph.each_vertex { |v| puts “in links for #v ==> #graphgraph.in_links(v), out links for #v ==> #graphgraph.out_links(v)”}

# compute HITS with the default number of iterations hits.compute_hits

# print the top HUBS and AUTHORITIES puts “=== TOP HUBS ===” hits.top_hub_scores.each do |hub|

puts "hub #{hub}"

end

puts “=== TOP AUTHORITIES ===” hits.top_authority_scores.each do |authority|

puts "authority #{authority}"

end