Class: BrownCorpusFile

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_nlp/corpus_files/brown.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ BrownCorpusFile

Returns a new instance of BrownCorpusFile.



2
3
4
# File 'lib/ruby_nlp/corpus_files/brown.rb', line 2

def initialize(path)
  @path = path
end

Instance Method Details

#sentencesObject



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/ruby_nlp/corpus_files/brown.rb', line 6

def sentences
  @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 do |word|
          word.split('/').first
        end.join(' ')
      end
    end
  end
end