Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,16 @@
|
|||
import scala.io.Source
|
||||
|
||||
if (argv.size != 2 ) error("Syntax: MarkovAlgorithm inputFile inputPattern")
|
||||
|
||||
val rulePattern = """(.*?)\s+->\s+(\.?)(.*)""".r
|
||||
val isComment = (_: String) matches "#.*|\\s*"
|
||||
val rules = Source fromPath args(0) getLines () filterNot isComment map (rulePattern unapplySeq _ get) toList;
|
||||
|
||||
def algorithm(input: String): String = rules find (input contains _.head) match {
|
||||
case Some(Seq(pattern, ".", replacement)) => input replaceFirst ("\\Q"+pattern+"\\E", replacement)
|
||||
case Some(Seq(pattern, "", replacement)) => algorithm(input replaceFirst ("\\Q"+pattern+"\\E", replacement))
|
||||
case None => input
|
||||
}
|
||||
|
||||
println(argv(1))
|
||||
println(algorithm(argv(1)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue