Class: TeRex::Format::BasicFile

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#categoryObject (readonly)

Returns the value of attribute category.



5
6
7
# File 'lib/format/basic_file.rb', line 5

def category
  @category
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/format/basic_file.rb', line 5

def path
  @path
end

#sentencesObject (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

#scannerObject

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