Class: CRFPP::Data
- Inherits:
-
Object
- Object
- CRFPP::Data
- Extended by:
- Forwardable
- Includes:
- Filelike, Enumerable
- Defined in:
- lib/crfpp/data.rb
Overview
A Data object represents test or training data.
Instance Attribute Summary collapse
-
#sentences ⇒ Object
readonly
Returns the value of attribute sentences.
Attributes included from Filelike
Instance Method Summary collapse
- #clear ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(path = nil) ⇒ Data
constructor
A new instance of Data.
- #new_sentence ⇒ Object
- #open ⇒ Object
- #push(feature) ⇒ Object (also: #<<)
- #to_s ⇒ Object
Methods included from Filelike
Constructor Details
#initialize(path = nil) ⇒ Data
Returns a new instance of Data.
17 18 19 20 |
# File 'lib/crfpp/data.rb', line 17 def initialize(path = nil) @path = path open end |
Instance Attribute Details
#sentences ⇒ Object (readonly)
Returns the value of attribute sentences.
13 14 15 |
# File 'lib/crfpp/data.rb', line 13 def sentences @sentences end |
Instance Method Details
#clear ⇒ Object
37 38 39 40 |
# File 'lib/crfpp/data.rb', line 37 def clear @sentences = [[]] self end |
#empty? ⇒ Boolean
53 54 55 |
# File 'lib/crfpp/data.rb', line 53 def empty? [@sentences].flatten(2).compact.empty? end |
#new_sentence ⇒ Object
57 58 59 60 |
# File 'lib/crfpp/data.rb', line 57 def new_sentence @sentences << [] self end |
#open ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/crfpp/data.rb', line 22 def open clear read.lines.each do |line| line.chomp! if line.strip.empty? new_sentence else push Token.parse(line) end end self end |
#push(feature) ⇒ Object Also known as: <<
46 47 48 49 |
# File 'lib/crfpp/data.rb', line 46 def push(feature) @sentences.last << feature self end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/crfpp/data.rb', line 42 def to_s empty? ? '' : zip([]).flatten.join("\n") end |