Class: TeRex::Format::BasicFile
- Inherits:
-
Object
- Object
- TeRex::Format::BasicFile
- Defined in:
- lib/format/basic_file.rb
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#sentences ⇒ Object
readonly
Returns the value of attribute sentences.
Instance Method Summary collapse
-
#initialize(file_path, klass) ⇒ BasicFile
constructor
A new instance of BasicFile.
-
#scanner ⇒ Object
Each line of file with Array object, strip it, split by whitespace, map it, split words by ‘/’ to separate POS tags, join by whitespace.
Constructor Details
#initialize(file_path, klass) ⇒ BasicFile
Returns a new instance of BasicFile.
7 8 9 10 |
# File 'lib/format/basic_file.rb', line 7 def initialize(file_path, klass) @path = file_path @category = klass end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category.
5 6 7 |
# File 'lib/format/basic_file.rb', line 5 def category @category end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/format/basic_file.rb', line 5 def path @path end |
#sentences ⇒ Object (readonly)
Returns the value of attribute sentences.
5 6 7 |
# File 'lib/format/basic_file.rb', line 5 def sentences @sentences end |
Instance Method Details
#scanner ⇒ Object
Each line of file with Array object, strip it, split by whitespace, map it, split words by ‘/’ to separate POS tags, join by whitespace
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/format/basic_file.rb', line 16 def scanner @sentences ||= File.open(@path) do |file| file.each_line.each_with_object([]) do |line, acc| stripped_line = line.strip unless stripped_line.nil? || stripped_line.empty? acc << line.split(' ').map {|word| word}.join(' ') end end end end |