Class: Markovian::Corpus::Compiler
- Inherits:
-
Object
- Object
- Markovian::Corpus::Compiler
- Defined in:
- lib/markovian/corpus/compiler.rb
Instance Attribute Summary collapse
-
#corpus ⇒ Object
readonly
Pass in a text, and optionally an existing Markov chain to add data to.
Instance Method Summary collapse
- #build_corpus(texts) ⇒ Object
- #incorporate_text_into_corpus(text) ⇒ Object
-
#initialize(starter_corpus = Corpus.new) ⇒ Compiler
constructor
A new instance of Compiler.
Constructor Details
Instance Attribute Details
#corpus ⇒ Object (readonly)
Pass in a text, and optionally an existing Markov chain to add data to. In many cases, you may be building a chain using a set of smaller texts instead of one large texts (dialog, for instance, or Twitter archives), and so may call this class repeatedly for elements of the parent corpus.
26 27 28 |
# File 'lib/markovian/corpus/compiler.rb', line 26 def corpus @corpus end |
Instance Method Details
#build_corpus(texts) ⇒ Object
31 32 33 34 |
# File 'lib/markovian/corpus/compiler.rb', line 31 def build_corpus(texts) texts.each {|t| incorporate_text_into_corpus(t)} corpus end |
#incorporate_text_into_corpus(text) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/markovian/corpus/compiler.rb', line 36 def incorporate_text_into_corpus(text) add_text_to_chain(split_into_components(text), forward_chain) # to assemble backward text, we just create a corpus with all the texts reversed # that allows us to see what words precede any given word add_text_to_chain(split_into_components(text).reverse, backward_chain) corpus end |