Class: Convert

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

Overview

require “find_noun/table.rb”

Instance Method Summary collapse

Constructor Details

#initializeConvert

Returns a new instance of Convert.



10
11
12
13
14
# File 'lib/find_noun.rb', line 10

def initialize 
  @tagger = EngTagger.new
#   @table = Terminal::Table.new :headings => ['Type', 'Length','Word']
#   @table.align_column(0,:right)
end

Instance Method Details

#format(data) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/find_noun.rb', line 38

def format(data)
  
  data.each do |key, value|
    if value.length == 0 
    puts "No #{key} in your sentence"
    else
    puts "Type : #{key}"
    puts "Count: #{value.length}"
    puts "Word : #{value.join(',')}"
    puts "--------------------"
        
    end
  end
end

#process(str) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/find_noun.rb', line 16

def process(str)
  # Convert input to lowercase.
  sentence = []
  str = str.upcase

  # Extract nouns, prefixing each with one of the
  # above adjectives into sentences of 2 words.
  tagged_str = @tagger.add_tags(str)
  verbs = @tagger.get_verbs(tagged_str).keys
  nouns = @tagger.get_nouns(tagged_str).keys
  adjectives = @tagger.get_adjectives(tagged_str).keys

  nouns.join(' ')
  verbs.join(' ')
  adjectives.join(' ')
  # binding.pry
  # sentence << nouns
  # sentence << verbs
  data = {'Nouns': nouns, 'Verbs': verbs, 'Adjectives': adjectives}
  format(data)
end