6 GOOGLE_SEARCH_URL = "http://www.google.com/xhtml/search?hl=en&q=%s"
8 def google_hits(*stuff)
12 url = GOOGLE_SEARCH_URL % URI::escape(keys.join(" "))
13 xml = Net::HTTP::get(URI.parse(url))
14 have = xml.match(/Results .*? of about (.*?)\. <br\/>/)
16 return have[1].gsub(',','').to_i
27 next unless w = chomp.intern rescue nil
28 next if singole.include?(w)
30 risultati[w] = google_hits(w) unless risultati.has_key?(w)
31 # puts "%s => %d" % [w, risultati[w]]
34 puts "Fine ricerca parole"
36 # TODO nel costruire l'Array di coppie
37 # assumiamo che per Google sia la stessa cosa cercare
38 # A B e B A, cosa che potrebbe non essere vera ...
50 risultati[ar] = google_hits(*ar) unless risultati.has_key?(ar)
51 # puts "(%s, %s) => #{risultati[ar]}" % ar
54 puts "Fine ricerca coppie"
56 risultati.each { |chiave, valore|
57 # Salta questa chiave se non è un vettore
58 next unless chiave.kind_of? Array
59 # _chiave_ è una coppia, [x, y], _valore_ è pxy
60 # Vogliamo sputare fuori x, y, px, py, pxy.
61 # Costruiamo un nuovo vettore i cui primi due
62 # elementi sono [x, y]
64 # Aggiungiamo px e py, ovvero risultati[_]
65 # per ciascun elemento di _chiave_
71 # Ora out è [x, y, px, py, pxy]; lo vogliamo sputare fuori
72 # separando gli elementi con una virgola: