class Tagmemics::Word
Public Class Methods
adjective_confidence(str)
click to toggle source
UPDATE PARAMETERS
# File lib/tagmemics/word/confidence.rb, line 23 def adjective_confidence(str) wordnet_prob = WordNetMethods.wordnet_probability(str, 'adjective') * 6 # lneighbor_adjective = 0 * 2 # rneighbor_verb = 0 * 2 subtotal = wordnet_prob subtotal / 10.0 end
adverb_confidence(str)
click to toggle source
# File lib/tagmemics/word/confidence.rb, line 41 def adverb_confidence(str) end
article_confidence(str)
click to toggle source
# File lib/tagmemics/word/confidence.rb, line 48 def article_confidence(str) part_of_speech?(Tagmemics::WordSet::ARTICLES, str) ? 1.0 : 0.0 end
confidence_levels(word)
click to toggle source
Because WordNet only tracks verbs, nouns, adverbs and adjectives, confidence levels can only be updated for those values. The other words
such as pronouns, prepositions, and conjunctions are based off of list in config folder. Their score is pass or fail and is calculated as 0 or 1.0.
# File lib/tagmemics/word.rb, line 22 def confidence_levels(word) word = word.downcase known_hsh = determine_known_words(word) wordnet_hsh = determine_wordnet_words(word) hsh = everything_nil(known_hsh) ? wordnet_hsh : known_hsh delete_nogos(hsh) end
conjunction_confidence(str)
click to toggle source
# File lib/tagmemics/word/confidence.rb, line 60 def conjunction_confidence(str) part_of_speech?(Tagmemics::WordSet::CONJUNCTIONS, str) ? 1.0 : 0.0 end
delete_nogos(hsh)
click to toggle source
# File lib/tagmemics/word.rb, line 45 def delete_nogos(hsh) hsh.delete_if { |_k, v| v == 0.0 || v.nil? } end
determine_known_words(word)
click to toggle source
# File lib/tagmemics/word.rb, line 31 def determine_known_words(word) { :article => article_confidence(word), :preposition => preposition_confidence(word), :pronoun => pronoun_confidence(word), :conjunction => conjunction_confidence(word), :linking_verb => linking_verb_confidence(word) } end
determine_wordnet_words(word)
click to toggle source
# File lib/tagmemics/word.rb, line 49 def determine_wordnet_words(word) { :noun => WordNetMethods.wordnet_probability(word, 'noun'), :verb => WordNetMethods.wordnet_probability(word, 'verb'), :adjective => WordNetMethods.wordnet_probability(word, 'adjective'), :adverb => WordNetMethods.wordnet_probability(word, 'adverb') } end
everything_nil(hsh)
click to toggle source
# File lib/tagmemics/word.rb, line 41 def everything_nil(hsh) (hsh.select { |_k, v| v != 0.0 && !v.nil? }.empty?) end
linking_verb_confidence(str)
click to toggle source
# File lib/tagmemics/word/confidence.rb, line 44 def linking_verb_confidence(str) part_of_speech?(Tagmemics::WordSet::LINKING_VERBS, str) ? 1.0 : 0.0 end
new(word)
click to toggle source
# File lib/tagmemics/word.rb, line 9 def initialize(word) @str = word puts "examining: #{word}" @tagmemic_confidence = Word.confidence_levels(word) end
noun_confidence(arr, index)
click to toggle source
FIXME: need to scan left, not hard coded index. Add up each category and derive percentage.
# File lib/tagmemics/word/confidence.rb, line 6 def noun_confidence(arr, index) str = arr[index] wordnet_prob = (WordNetMethods.possibilities(str)['noun'] / 1) * 6 left_neighbor_article = article_confidence(arr[index - 2]) * 2 subtotal = wordnet_prob + left_neighbor_article subtotal / 10.0 end
part_of_speech?(constant, str, positive = false)
click to toggle source
# File lib/tagmemics/word/confidence.rb, line 32 def part_of_speech?(constant, str, positive = false) arr = [] constant.each do |word| positive = true if word.downcase == str.downcase break if positive end positive end
preposition_confidence(str)
click to toggle source
# File lib/tagmemics/word/confidence.rb, line 52 def preposition_confidence(str) part_of_speech?(Tagmemics::WordSet::PREPOSITIONS, str) ? 1.0 : 0.0 end
pronoun_confidence(str)
click to toggle source
# File lib/tagmemics/word/confidence.rb, line 56 def pronoun_confidence(str) part_of_speech?(Tagmemics::WordSet::PRONOUNS, str) ? 1.0 : 0.0 end
verb_confidence(str)
click to toggle source
# File lib/tagmemics/word/confidence.rb, line 15 def verb_confidence(str) wordnet_prob = WordNetMethods.wordnet_probability(str, 'verb') * 6 subtotal = wordnet_prob subtotal / 10.0 end