Skip to content

Commit

Permalink
feat: custom order
Browse files Browse the repository at this point in the history
  • Loading branch information
borgoat committed May 5, 2022
1 parent 4c49b71 commit 001f90a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/main/kotlin/com/github/borgoat/markovaldo/MarkovChain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class MarkovChain(

fun nextToken(tokenSequence: List<Token>): 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<List<Token>, MutableMap<Token, AtomicLong>>()

fun add(text: CharSequence) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/github/borgoat/markovaldo/Token.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down

0 comments on commit 001f90a

Please sign in to comment.