Module: RiDic

Defined in:
lib/ridic.rb,
lib/ridic/version.rb,
lib/ridic/dictionary.rb

Defined Under Namespace

Classes: Dictionary

Constant Summary collapse

VERSION =
"0.7.0"

Class Method Summary collapse

Class Method Details

.all_categories_in_document(document_text, result = []) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ridic.rb', line 29

def self.all_categories_in_document(document_text, result = [])
  sanitize(document_text).split(' ').each do |elem|
    word_res = word_match(elem) 
    if word_res == nil
      stem_res = stem_match(elem)
      result.push(stem_res) if stem_res != nil
    else
      result << word_res
    end
  end
  result
end

.category_distribution(document_text, category_number = 1, result = Hash.new(0)) ⇒ Object



47
48
49
50
51
# File 'lib/ridic.rb', line 47

def self.category_distribution(document_text, category_number = 1, result = Hash.new(0))
  first_categories = category_in_document(sanitize(document_text.upcase), category_number)
  first_categories.each {|elem| result[elem.first] += 1}
  sort_distribution(result)
end

.category_in_document(document_text, category_number, result = []) ⇒ Object



42
43
44
45
# File 'lib/ridic.rb', line 42

def self.category_in_document(document_text, category_number, result = [])
  all_categories_in_document(sanitize(document_text)).delete_if {|i| i == nil}.each {|elem| result << [elem[category_number - 1]]}
  result.delete_if {|i| i == [""]}
end

.stem_match(text_word) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ridic.rb', line 15

def self.stem_match(text_word)
  text_word.upcase!

  max_length = text_word.length
  max_length > 14 ? max_length = 14 : max_length

  max_length.downto(3) do |i|
    text_word = text_word[0...i]
    dictionary_2 = @stem_dictionary[text_word]
    (return dictionary_2) if dictionary_2 != nil
  end
  nil
end

.word_match(text_word) ⇒ Object



9
10
11
12
13
# File 'lib/ridic.rb', line 9

def self.word_match(text_word)
  text_word.upcase!
  dictionary_1 = @word_dictionary[text_word]
  dictionary_1 == nil ? @stem_dictionary[text_word] : dictionary_1
end