From 001f90a634310d4ac7099d973f88d604dd68ee7a Mon Sep 17 00:00:00 2001 From: Giorgio Azzinnaro Date: Thu, 5 May 2022 21:12:03 +0200 Subject: [PATCH] feat: custom order --- src/main/kotlin/com/github/borgoat/markovaldo/MarkovChain.kt | 3 +-- src/main/kotlin/com/github/borgoat/markovaldo/Token.kt | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/com/github/borgoat/markovaldo/MarkovChain.kt b/src/main/kotlin/com/github/borgoat/markovaldo/MarkovChain.kt index 32a7fa1..813c231 100644 --- a/src/main/kotlin/com/github/borgoat/markovaldo/MarkovChain.kt +++ b/src/main/kotlin/com/github/borgoat/markovaldo/MarkovChain.kt @@ -19,8 +19,7 @@ class MarkovChain( fun nextToken(tokenSequence: List): Token? = edges[tokenSequence.takeLast(order)]?.next() - class Builder(val scanner: Scanner = Scanner()) { - var order = 3 + class Builder(val scanner: Scanner = Scanner(), val order: Int = 3) { val probs = mutableMapOf, MutableMap>() fun add(text: CharSequence) { diff --git a/src/main/kotlin/com/github/borgoat/markovaldo/Token.kt b/src/main/kotlin/com/github/borgoat/markovaldo/Token.kt index 5597755..4dd68ad 100644 --- a/src/main/kotlin/com/github/borgoat/markovaldo/Token.kt +++ b/src/main/kotlin/com/github/borgoat/markovaldo/Token.kt @@ -7,8 +7,8 @@ data class StringToken(val string: String) : Token() { val skipSpaceBefore = noSpaceBefore.matches(string) companion object { - private val noSpaceAfter = "^([\"]+|\\-\\-)\$".toRegex() - private val noSpaceBefore = "^[\\.!?,:\\-]+\$".toRegex() + private val noSpaceAfter = "^([\"\']+|\\-\\-)\$".toRegex() + private val noSpaceBefore = "^[\"\'\\.!?,:\\-]+\$".toRegex() } }