Class: NlpToolz::PosTags

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

Constant Summary collapse

FileInputStream =

load java classes

Rjb::import('java.io.FileInputStream')
POSModel =
Rjb::import('opennlp.tools.postag.POSModel')
POSTaggerME =
Rjb::import('opennlp.tools.postag.POSTaggerME')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, lang = nil) ⇒ PosTags

Returns a new instance of PosTags.



20
21
22
23
24
25
# File 'lib/nlp_toolz/pos_tags.rb', line 20

def initialize(input, lang = nil)
  @input = input
  @lang = lang || NlpToolz::Language.get_language(input)
  @model_name = "#{@lang}-pos-maxent.bin"
  get_model
end

Instance Attribute Details

#inputObject

Returns the value of attribute input.



18
19
20
# File 'lib/nlp_toolz/pos_tags.rb', line 18

def input
  @input
end

#langObject

Returns the value of attribute lang.



18
19
20
# File 'lib/nlp_toolz/pos_tags.rb', line 18

def lang
  @lang
end

#modelObject

Returns the value of attribute model.



18
19
20
# File 'lib/nlp_toolz/pos_tags.rb', line 18

def model
  @model
end

#model_nameObject

Returns the value of attribute model_name.



18
19
20
# File 'lib/nlp_toolz/pos_tags.rb', line 18

def model_name
  @model_name
end

#tokenizedObject

Returns the value of attribute tokenized.



18
19
20
# File 'lib/nlp_toolz/pos_tags.rb', line 18

def tokenized
  @tokenized
end

Instance Method Details

#get_pos_tagsObject



27
28
29
30
31
# File 'lib/nlp_toolz/pos_tags.rb', line 27

def get_pos_tags
  if self.has_model?
    @tokenized = tokenize_it @tagger.tag(@input.clean_up)
  end
end

#has_model?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/nlp_toolz/pos_tags.rb', line 41

def has_model?
  @model
end

#tagsObject



37
38
39
# File 'lib/nlp_toolz/pos_tags.rb', line 37

def tags
  @tokenized[:tags]
end

#tokensObject



33
34
35
# File 'lib/nlp_toolz/pos_tags.rb', line 33

def tokens
  @tokenized[:tokens]
end