Created
January 7, 2016 22:25
-
-
Save brylor/61aa3e2f9ceaaabf6bf0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ruby_nlp/ngram' | |
class Corpus | |
def initialize(glob, klass) | |
@glob = glob | |
@klass = klass | |
end | |
def files | |
@files ||= Dir[@glob].map do |file| | |
@klass.new(file) | |
end | |
end | |
def pos | |
puts 'some unigram pos' | |
end | |
def sentences | |
files.map do |file| | |
file.sentences | |
end.flatten | |
end | |
def ngrams(n) | |
sentences.map do |sentence| | |
Ngram.new(sentence).ngrams(n) | |
end.flatten(1) | |
end | |
def unigrams | |
ngrams(1) | |
end | |
def bigrams | |
ngrams(2) | |
end | |
def trigrams | |
ngrams(3) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment