Class: Corpus

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

Instance Method Summary collapse

Constructor Details

#initialize(glob, klass) ⇒ Corpus



4
5
6
7
# File 'lib/ruby_nlp/corpus.rb', line 4

def initialize(glob, klass)
  @glob = glob
  @klass = klass
end

Instance Method Details

#bigramsObject



31
32
33
# File 'lib/ruby_nlp/corpus.rb', line 31

def bigrams
  ngrams(2)
end

#filesObject



9
10
11
12
13
# File 'lib/ruby_nlp/corpus.rb', line 9

def files
  @files ||= Dir[@glob].map do |file|
    @klass.new(file)
  end
end

#ngrams(n) ⇒ Object



21
22
23
24
25
# File 'lib/ruby_nlp/corpus.rb', line 21

def ngrams(n)
  sentences.map do |sentence|
    Ngram.new(sentence).ngrams(n)
  end.flatten(1)
end

#sentencesObject



15
16
17
18
19
# File 'lib/ruby_nlp/corpus.rb', line 15

def sentences
  files.map do |file|
    file.sentences
  end.flatten
end

#trigramsObject



35
36
37
# File 'lib/ruby_nlp/corpus.rb', line 35

def trigrams
  ngrams(3)
end

#unigramsObject



27
28
29
# File 'lib/ruby_nlp/corpus.rb', line 27

def unigrams
  ngrams(1)
end