Class: JnbClassifier::Document

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

Overview

associate label to the frequency of words in the document

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, doc) ⇒ Document

Returns a new instance of Document.



64
65
66
67
# File 'lib/jnb_classifier.rb', line 64

def initialize(label,doc)
  @label = label                               # String
  @attributes = create_attributes(doc)         # Hsah
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



62
63
64
# File 'lib/jnb_classifier.rb', line 62

def attributes
  @attributes
end

#labelObject (readonly)

Returns the value of attribute label.



61
62
63
# File 'lib/jnb_classifier.rb', line 61

def label
  @label
end

Instance Method Details

#create_attributes(doc) ⇒ Object



69
70
71
72
73
74
75
76
# File 'lib/jnb_classifier.rb', line 69

def create_attributes(doc)
  attributes = Hash.new(0)
  nm = Natto::MeCab.new
  nm.parse(doc) do |n|
	attributes[n.surface] += 1 if n.feature.match(/名詞/)
  end
  attributes
end