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



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

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

Instance Method Details

#resultObject



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

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

#xml_resultObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/vn_tagger/tagger.rb', line 20

def xml_result
  @xml_result ||= if @success
                    file = File.open(OUTPUT)
                    xml_document = Nokogiri::XML(file)
                    file.close
                    xml_document
                  else
                    Nokogiri::XML('')
                  end
end