lib/megahal/megahal.rb
# This is classic Markovian generation; using a model, start with a context
# and continue until we hit a <fence> symbol. The only addition here is that
# we roll the dice several times, and prefer generations that elicit a
# keyword.
This is classic Markovian generation; using a model, start with a context
and continue until we hit a  symbol. The only addition here is that
we roll the dice several times, and prefer generations that elicit a
keyword.
This is classic Markovian generation ; using a model start with a context and continue until we hit a symbol . The only addition here is that we roll the dice several times and prefer generations that elicit a keyword .
def _random_walk(model, static_context, keyword_symbols)
    context = static_context.dup
    results = []
    id = @brain[context.dup] ||= @brain.length
    return [] if model.count(id) == 0
    local_keywords = keyword_symbols.dup
    loop do
      symbol = 0
      10.times do
        id = @brain[context.dup] ||= @brain.length
        limit = rand(model.count(id)) + 1
        symbol = model.select(id, limit)
        if local_keywords.include?(symbol)
          local_keywords.delete(symbol)
          break
        end
      end
      return [] if symbol == 0
      break if symbol == 1
      results << symbol
      context << symbol
      context.shift
    end
    results
  end
def _random_walk ( model , static_context , keyword_symbols ) context = static_context . dup results = [ ] id = @brain [ context . dup ] ||= @brain . length return [ ] if model . count ( id ) == 0 local_keywords = keyword_symbols . dup loop do symbol = 0 10 . times do id = @brain [ context . dup ] ||= @brain . length limit = rand ( model . count ( id ) ) + 1 symbol = model . select ( id , limit ) if local_keywords . include? ( symbol ) local_keywords . delete ( symbol ) break end end return [ ] if symbol == 0 break if symbol == 1 results << symbol context << symbol context . shift end results end
This is classic Markovian generation; using a model, start with a context
and continue until we hit a <fence> symbol.
This is classic Markovian generation ; using a model start with a context and continue until we hit a <fence > symbol .
model
static_context
keyword_symbols