Class: VnTagger::Document

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml_document) ⇒ Document

Returns a new instance of Document.



7
8
9
# File 'lib/vn_tagger/document.rb', line 7

def initialize(xml_document)
  @xml_document = xml_document
end

Instance Attribute Details

#xml_documentObject (readonly)

Returns the value of attribute xml_document.



5
6
7
# File 'lib/vn_tagger/document.rb', line 5

def xml_document
  @xml_document
end

Instance Method Details

#filter_by_tag(tag = 'Proper noun') ⇒ Object



21
22
23
# File 'lib/vn_tagger/document.rb', line 21

def filter_by_tag(tag = 'Proper noun')
  words.select { |word| word.is_tag?(tag) }
end

#proper_noun_wordsObject



25
26
27
# File 'lib/vn_tagger/document.rb', line 25

def proper_noun_words
  filter_by_tag('Proper noun').map(&:text)
end

#uncached_wordsObject



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

def uncached_words
  xml_document.xpath('//w').map do |element|
    Word.new(element.attr('pos'), element.text)
  end
end

#wordsObject



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

def words
  @words ||= uncached_words
end