Class: Markovian::Chain::Compiler
- Inherits:
-
Object
- Object
- Markovian::Chain::Compiler
- Defined in:
- lib/markovian/chain/compiler.rb
Instance Attribute Summary collapse
-
#chain ⇒ Object
readonly
Pass in a text, and optionally an existing Markov chain to add data to.
Instance Method Summary collapse
- #build_chain(texts) ⇒ Object
- #incorporate_text_into_chain(text) ⇒ Object
-
#initialize(starter_chain = Chain.new) ⇒ Compiler
constructor
A new instance of Compiler.
Constructor Details
#initialize(starter_chain = Chain.new) ⇒ Compiler
Returns a new instance of Compiler.
27 28 29 |
# File 'lib/markovian/chain/compiler.rb', line 27 def initialize(starter_chain = Chain.new) @chain = starter_chain end |
Instance Attribute Details
#chain ⇒ 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 corpus.
26 27 28 |
# File 'lib/markovian/chain/compiler.rb', line 26 def chain @chain end |
Instance Method Details
#build_chain(texts) ⇒ Object
31 32 33 34 |
# File 'lib/markovian/chain/compiler.rb', line 31 def build_chain(texts) texts.each {|t| incorporate_text_into_chain(t)} chain end |
#incorporate_text_into_chain(text) ⇒ Object
36 37 38 39 |
# File 'lib/markovian/chain/compiler.rb', line 36 def incorporate_text_into_chain(text) add_text_to_chain(split_into_components(text), chain) chain end |