Class: JnbClassifier::Document
- Inherits:
-
Object
- Object
- JnbClassifier::Document
- Defined in:
- lib/jnb_classifier.rb
Overview
associate label to the frequency of words in the document
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
Instance Method Summary collapse
- #create_attributes(file_name) ⇒ Object
-
#initialize(label, file_name) ⇒ Document
constructor
A new instance of Document.
Constructor Details
#initialize(label, file_name) ⇒ Document
Returns a new instance of Document.
63 64 65 66 |
# File 'lib/jnb_classifier.rb', line 63 def initialize(label, file_name) @label = label # String @attributes = create_attributes(file_name) # Hash end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
61 62 63 |
# File 'lib/jnb_classifier.rb', line 61 def attributes @attributes end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
60 61 62 |
# File 'lib/jnb_classifier.rb', line 60 def label @label end |
Instance Method Details
#create_attributes(file_name) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/jnb_classifier.rb', line 68 def create_attributes(file_name) attributes = Hash.new(0) File.open(file_name) {|f| doc = f.read nm = Natto::MeCab.new nm.parse(doc) do |n| attributes[n.surface] += 1 if n.feature.match(/名詞/) end } attributes end |