Class: StyleScanner::Tagger

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_text) ⇒ Tagger

Returns a new instance of Tagger.



6
7
8
# File 'lib/style_scanner/tagger.rb', line 6

def initialize(input_text)
  @input_text = input_text
end

Instance Attribute Details

#input_textObject (readonly)

Returns the value of attribute input_text.



4
5
6
# File 'lib/style_scanner/tagger.rb', line 4

def input_text
  @input_text
end

Class Method Details

.parts_of_speech_taggerObject

load once since there is a high initialization cost



19
20
21
# File 'lib/style_scanner/tagger.rb', line 19

def parts_of_speech_tagger
  @eng_tagger ||= EngTagger.new
end

Instance Method Details

#tagged_wordsObject



10
11
12
13
14
15
# File 'lib/style_scanner/tagger.rb', line 10

def tagged_words 
  @tagged_words ||= Tagger.parts_of_speech_tagger.
    add_tags(input_text).
    scan(/\<(?<tag>\w+)>(?<text>[^(<\)]+)</).
    map {|tag, word| TaggedWord.new(tag,word)}
end