Class: Corpus
- Inherits:
-
Object
- Object
- Corpus
- Defined in:
- lib/ruby_nlp/corpus.rb
Instance Method Summary collapse
- #bigrams ⇒ Object
- #files ⇒ Object
-
#initialize(glob, klass) ⇒ Corpus
constructor
A new instance of Corpus.
- #ngrams(n) ⇒ Object
- #sentences ⇒ Object
- #trigrams ⇒ Object
- #unigrams ⇒ Object
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
#bigrams ⇒ Object
31 32 33 |
# File 'lib/ruby_nlp/corpus.rb', line 31 def bigrams ngrams(2) end |
#files ⇒ Object
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 |
#sentences ⇒ Object
15 16 17 18 19 |
# File 'lib/ruby_nlp/corpus.rb', line 15 def sentences files.map do |file| file.sentences end.flatten end |
#trigrams ⇒ Object
35 36 37 |
# File 'lib/ruby_nlp/corpus.rb', line 35 def trigrams ngrams(3) end |
#unigrams ⇒ Object
27 28 29 |
# File 'lib/ruby_nlp/corpus.rb', line 27 def unigrams ngrams(1) end |