Skip to content

Commit 41af508

Browse files
committed
add all holes afsa constructor
1 parent 44e489b commit 41af508

File tree

1 file changed

+17
-0
lines changed
  • src/commonMain/kotlin/ai/hypergraph/kaliningraph/parsing

1 file changed

+17
-0
lines changed

src/commonMain/kotlin/ai/hypergraph/kaliningraph/parsing/Levenshtein.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,23 @@ fun Σᐩ.unpackCoordinates() =
5858
substringAfter('_').split('/')
5959
.let { (i, j) -> i.toInt() to j.toInt() }
6060

61+
fun makeAllHolesFSA(len: Int): FSA {
62+
require(len >= 0) { "len must be non-negative" }
63+
64+
// States: q_0/0, q_1/0, ..., q_len/0
65+
// Arcs: q_{i-1}/0 --[!=]_-> q_i/0 for i = 1..len
66+
val arcs: TSA = (1..len).map { i -> "q_${i - 1}/0" to "[!=]_" to "q_${i}/0" }.toSet()
67+
68+
val initial = setOf("q_0/0")
69+
val finals = setOf("q_${len}/0")
70+
71+
return AFSA(arcs, initial, finals).also {
72+
it.height = 0 // single row
73+
it.width = len // number of columns
74+
it.levString = List(len) { "_" } // template metadata (all holes)
75+
}
76+
}
77+
6178
fun makeExactLevCFL(
6279
str: List<Σᐩ>,
6380
radius: Int, // Levenshtein distance

0 commit comments

Comments
 (0)