Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A Markov Chain Generator In Scala

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 src
Octocat-spinner-32 .gitignore
Octocat-spinner-32 README.mkd
Octocat-spinner-32 build.sbt
README.mkd

Scala-Markov

Some expirements in markov chains

Use

import scala.io.Source
import org.conbere.markov._

object Markov extends App {
  def main(args: Array[String]) = {
    // \2 and \3 are the ascii stop and start characters
    val stop = '\2'
    val start = '\3'

    // we'll use lists of length 2
    val chainLength = 2

    // build a markov chain from an input file where each line
    // consists of a planet name from Star Trek
    val m = Source.fromFile("./src/test/resources/planets.txt")
                  .getLines
                  // MarkovChainMap is a markov chain that stores the chain
                  // options in a Map[C,Int]. This map is working over Chars
                  .foldLeft(new MarkovChain[Char](start, stop))((acc, n) =>
                    acc.insert(n.toLowerCase.toList)
                  ))

    // Generate a new planet name based on the corpus with a maximum length
    // of 10
    println(m.generate(10))
  }
}

Something went wrong with that request. Please try again.