Class: Bronto::Thesaurus

Inherits:
Object
  • Object
show all
Defined in:
lib/bronto/thesaurus.rb

Instance Method Summary collapse

Instance Method Details

#lookup(word) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bronto/thesaurus.rb', line 8

def lookup(word)
  query = word.downcase
  synonyms = get_synonyms query
  return nil if synonyms.nil? # check out early if nothing is found

  hash = {}

  if synonyms
    synonyms.each do |synonym|
      hash[synonym.last] = {syn: [] } unless hash.member?(synonym.last)
      hash[synonym.last][:syn] << synonym.first
    end
  end
  
  hash.keys.each do |key1|
    val1 = hash[key1]
    val1.sort! if val1.respond_to? :sort!
    
    val1.keys.each do |key2|
      val2 = hash[key1][key2]
      val2.sort! if val2.respond_to? :sort! 
    end
  end

  hash
end