Skip to content

Commit

Permalink
incorporate matrix LBH into experimental pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
breandan committed Jan 18, 2025
1 parent 972fe9c commit ab94c40
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,7 @@ open class FSA constructor(open val Q: TSA, open val init: Set<Σᐩ>, open val
fun LED(cfg: CFG, brokeToks: Σᐩ): Int =
(1 until (2 * MAX_RADIUS)).firstOrNull { FSA.nonemptyLevInt(brokeToks, cfg, it) } ?: (2 * MAX_RADIUS)

fun intersectPTree(brokenStr: Σᐩ, cfg: CFG, radius: Int): PTree? {
// 1) Build the Levenshtein automaton (acyclic)
val levFSA = makeLevFSA(brokenStr, radius)

fun intersectPTree(brokenStr: Σᐩ, cfg: CFG, radius: Int, levFSA: FSA = makeLevFSA(brokenStr, radius)): PTree? {
val nStates = levFSA.numStates
val startIdx = cfg.bindex[START_SYMBOL]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class PTree constructor(val root: String = ".ε", val branches: List<Π2A<PTree>

// TODO: Use weighted choice mechanism
val shuffledBranches by lazy { branches.shuffled().sortedBy { "ε" !in it.first.root + it.second.root } }
val totalProds by lazy {
if (branches.isEmpty()) 1
else branches.map { (l, r) -> l.totalTrees + r.totalTrees }.reduce { acc, it -> acc + it }
}
val totalTreesStr by lazy { totalTrees.toString() }
val totalTrees: BigInteger by lazy {
if (branches.isEmpty()) BigInteger.ONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ fun PTree.sampleWithPCFG(
.asStream()
}

fun PTree.sampleDirectlyWR(
cores: Int = NUM_CORES,
stoppingCriterion: () -> Boolean = { true }
): Stream<String> =
(0..<cores).toList().parallelStream().flatMap { i ->
sampleWRGD()
.map { it.removeEpsilon() }
.takeWhile { stoppingCriterion() }
.distinct()
.asStream()
}

fun PTree.sampleDirectlyWOR(
cores: Int = NUM_CORES,
stoppingCriterion: () -> Boolean = { true }
Expand Down

0 comments on commit ab94c40

Please sign in to comment.