Skip to content

Commit

Permalink
use more efficient matrixLBH implementation for repair
Browse files Browse the repository at this point in the history
  • Loading branch information
breandan committed Jan 15, 2025
1 parent 0e6ddfb commit a800e06
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
15 changes: 15 additions & 0 deletions latex/bib/acmart.bib
Original file line number Diff line number Diff line change
Expand Up @@ -2340,4 +2340,19 @@ @article{floyd1967nondeterministic
pages={636--644},
year={1967},
publisher={ACM New York, NY, USA}
}

@Inbook{Grune2008,
author="Grune, Dick
and Jacobs, Ceriel J. H.",
title="Parsing as Intersection",
bookTitle="Parsing Techniques: A Practical Guide",
year="2008",
publisher="Springer New York",
address="New York, NY",
pages="425--442",
abstract="In 1961 Bar-Hillel, Perles and Shamir [219] proved that ``the intersection of a context-free language with a regular language is again a context-free language''. On the face of it, this means that when we take the set of strings that constitute a given CF language and remove from it all strings that do not occur in a given FS language, we get a set of strings for which a CF grammar exists. Actually, it means quite a bit more.",
isbn="978-0-387-68954-8",
doi="10.1007/978-0-387-68954-8_13",
url="https://doi.org/10.1007/978-0-387-68954-8_13"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ai.hypergraph.kaliningraph.automata
import ai.hypergraph.kaliningraph.*
import ai.hypergraph.kaliningraph.graphs.*
import ai.hypergraph.kaliningraph.parsing.*
import ai.hypergraph.kaliningraph.repair.MAX_RADIUS
import ai.hypergraph.kaliningraph.types.*
import kotlin.lazy
import kotlin.random.Random
Expand Down Expand Up @@ -161,6 +162,9 @@ open class FSA constructor(open val Q: TSA, open val init: Set<Σᐩ>, open val
return false
}

fun LED(cfg: CFG, brokeToks: Σᐩ): Int =
(1 until MAX_RADIUS).firstOrNull { FSA.nonemptyLevInt(brokeToks, cfg, it) } ?: MAX_RADIUS

fun intersectPTree(str: Σᐩ, cfg: CFG, radius: Int): PTree? {
// 1) Build the Levenshtein automaton (acyclic)
val levFSA = makeLevFSA(str, radius)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ fun CFG.dropVestigialProductions(


fun CFG.LED(brokeToks: Σᐩ): Int =
(1..MAX_RADIUS).firstOrNull {
(1 until MAX_RADIUS).firstOrNull {
try {
intersectLevFSA(fsa = makeLevFSA(brokeToks.tokenizeByWhitespace(), it)).isNotEmpty()
} catch (_: Exception) { println("Failed $it, increasing..."); false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ val <G: IGraph<G, E, V>, E: IEdge<G, E, V>, V: IVertex<G, E, V>> IGraph<G, E, V>

val cache = LRUCache<String, Any>()

// If you see a JS error get_first_irdx8n_k, it DEPTH is set incorrectly or something is funny with the stacktrace
object PlatformVars { var PLATFORM_CALLER_STACKTRACE_DEPTH: Int = 3 }
// This is somewhat of a hack and may break depending on the platform.
// We do this because Kotlin Common has poor reflection capabilities.
Expand Down

0 comments on commit a800e06

Please sign in to comment.