Class: VnTagger::Tagger

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

Constant Summary collapse

ROOT_PATH =
File.expand_path('../../..', __FILE__)
COMMAND =
'java -jar vn.hus.nlp.tagger-4.2.0.jar'
INPUT =
File.join(ROOT_PATH, 'input.txt')
OUTPUT =
File.join(ROOT_PATH, 'output.xml')

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Tagger

Returns a new instance of Tagger.



11
12
13
# File 'lib/vn_tagger/tagger.rb', line 11

def initialize(text)
  @text = normalize(text)
end

Class Method Details

.tag(text) ⇒ Object



34
35
36
37
38
# File 'lib/vn_tagger/tagger.rb', line 34

def self.tag(text)
  tagger = new(text)
  tagger.tag
  tagger.result
end

Instance Method Details

#resultObject



30
31
32
# File 'lib/vn_tagger/tagger.rb', line 30

def result
  @result ||= Document.new(xml_result)
end

#tagObject



15
16
17
18
# File 'lib/vn_tagger/tagger.rb', line 15

def tag
  write_to_file
  @success = system("cd #{ROOT_PATH}; #{COMMAND} -i #{INPUT} -o #{OUTPUT}")
end

#uncached_xml_resultObject



24
25
26
27
28
# File 'lib/vn_tagger/tagger.rb', line 24

def uncached_xml_result
  xml_document = is_success? ? read_xml_document : blank_xml_document
  delete_output
  xml_document
end

#xml_resultObject



20
21
22
# File 'lib/vn_tagger/tagger.rb', line 20

def xml_result
  @xml_result ||= uncached_xml_result
end