From 5f18bb69801be1109626ca6ec40fd2982b4a2dd5 Mon Sep 17 00:00:00 2001 From: breandan Date: Thu, 31 Oct 2024 00:36:37 -0400 Subject: [PATCH] fix multitoken edit detector --- .../kotlin/ai/hypergraph/kaliningraph/parsing/Levenshtein.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commonMain/kotlin/ai/hypergraph/kaliningraph/parsing/Levenshtein.kt b/src/commonMain/kotlin/ai/hypergraph/kaliningraph/parsing/Levenshtein.kt index 0d203c1d..827f4a24 100644 --- a/src/commonMain/kotlin/ai/hypergraph/kaliningraph/parsing/Levenshtein.kt +++ b/src/commonMain/kotlin/ai/hypergraph/kaliningraph/parsing/Levenshtein.kt @@ -244,7 +244,7 @@ fun CFG.hasSingleEditRepair(tokens: List, range: IntRange): Boolean = val rangeSub = (maxOf(0, range.first) until minOf(tokens.size, range.last + 1)) val rangeIns = (maxOf(0, range.first) until minOf(tokens.size + 1, range.last + 2)) rangeSub.any { i -> toCheck.mapIndexed { j, t -> if (j == i) "_" else t } in language } // Check substitutions - && rangeIns.any { (toCheck.take(it) + "_" + toCheck.drop(it)) in language } // Check insertions + || rangeIns.any { (toCheck.take(it) + "_" + toCheck.drop(it)) in language } // Check insertions } // Tries to shrink a multi-edit range until it has a single edit repair