Module: Tagmemics::WordNetMethods

Defined in:
lib/tagmemics/word/wordnet.rb

Class Method Summary collapse

Class Method Details

.combine_values(hsh) ⇒ Object



51
52
53
# File 'lib/tagmemics/word/wordnet.rb', line 51

def combine_values(hsh)
  hsh.values.reduce(:+)
end

.decimal_complete(hsh) ⇒ Object

TODO: Not using this. Delete?



65
66
67
68
69
# File 'lib/tagmemics/word/wordnet.rb', line 65

def decimal_complete(hsh)
  total = hsh.length
  complete = hsh.count { |_k, v| v } # not nil
  complete / total.to_f
end

.lexObject



7
8
9
# File 'lib/tagmemics/word/wordnet.rb', line 7

def lex
  WordNet::Lexicon.new
end

.most_likely_pos(probability_hsh) ⇒ Object

Most likely part of speech



36
37
38
39
40
# File 'lib/tagmemics/word/wordnet.rb', line 36

def most_likely_pos(probability_hsh)
  return unless probability_hsh.is_a? Hash
  max = probability_hsh.values.max
  probability_hsh.select { |_k, v| v == max }
end

.most_likely_probability(hsh) ⇒ Object

DELETE ME?



47
48
49
# File 'lib/tagmemics/word/wordnet.rb', line 47

def most_likely_probability(hsh)
  most_likely_pos(hsh).values.reduce(:+)
end

.parts_of_speech_frequency(word, arr = []) ⇒ Object



16
17
18
19
20
21
# File 'lib/tagmemics/word/wordnet.rb', line 16

def parts_of_speech_frequency(word, arr = [])
  word_definitions(word).each do |x|
    arr << x.part_of_speech
  end
  arr.frequency
end

.possibilities(word) ⇒ Object

returns hash of all possibilities for given dictionary word.



28
29
30
31
32
33
# File 'lib/tagmemics/word/wordnet.rb', line 28

def possibilities(word)
  hsh = parts_of_speech_frequency(word)
  denom = total_possibilities(word)

  hsh.each { |k, v| hsh[k] = v / denom.to_f }
end

.total_possibilities(word) ⇒ Object



23
24
25
# File 'lib/tagmemics/word/wordnet.rb', line 23

def total_possibilities(word)
  parts_of_speech_frequency(word).values.reduce(:+)
end

.word_definitions(word) ⇒ Object



11
12
13
14
# File 'lib/tagmemics/word/wordnet.rb', line 11

def word_definitions(word)
  word = word.to_sym
  lex.lookup_synsets(word)
end

.wordnet_probability(word, part_of_speech) ⇒ Object

Select highest probable part of speech and combine with any others with similiar name ie. Adjective and Adjective Satellite, they will be added together.



58
59
60
61
62
# File 'lib/tagmemics/word/wordnet.rb', line 58

def wordnet_probability(word, part_of_speech)
  hsh = possibilities(word)
  eligibles = hsh.select { |k, _v| k.split.include? part_of_speech }
  combine_values(eligibles) || 0.0 # return if probability is nil
end