Skip to content

Commit

Permalink
fix reference grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
breandan committed Jan 14, 2025
1 parent 74863b3 commit ddee905
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ open class FSA constructor(open val Q: TSA, open val init: Set<Σᐩ>, open val
break
}

return levFSA.finalIdxs.any { f -> dp[0][f][cfg.bindex[START_SYMBOL]] }
return levFSA.finalIdxs.any { f -> dp[0][f][cfg.bindex[START_SYMBOL]].also { if (it) println("Found: ${levFSA.stateLst[0]} ${levFSA.stateLst[f]}") } }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ val <G: IGraph<G, E, V>, E: IEdge<G, E, V>, V: IVertex<G, E, V>> IGraph<G, E, V>
val backward: Map<V, Set<V>> = reversed().let { it.vertices.associateWith { v -> it.transitiveClosure(setOf(v)) } }

// For every pair (p, q), collect all vertices r that lie on some path p ->* r ->* q
vertices.flatMap { p -> vertices.map { q -> Pair(Pair(p, q), (forward[p]!! intersect backward[q]!!)) } }.filter { it.second.isNotEmpty() }.toMap()
vertices.flatMap { p -> vertices.map { q -> Pair(Pair(p, q), (forward[p]!! intersect backward[q]!!)) } }
.filter { it.second.isNotEmpty() }.toMap()
}

val <G: IGraph<G, E, V>, E: IEdge<G, E, V>, V: IVertex<G, E, V>> IGraph<G, E, V>.degMap: Map<V, Int> by cache { vertices.associateWith { it.neighbors.size } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,15 +473,15 @@ class BarHillelTest {
val led = Grammars.dyck.LED(str)
println("Language edit distance: $led")

measureTimedValue { FSA.levIntersect(str, vanillaS2PCFG, led) }
measureTimedValue { FSA.levIntersect(str, Grammars.dyck, led) }
.also { println("${it.value} / ${it.duration}") }
.also { assertTrue(it.value) }

measureTimedValue { FSA.levIntersect(str, vanillaS2PCFG, led + 1) }
measureTimedValue { FSA.levIntersect(str, Grammars.dyck, led + 1) }
.also { println("${it.value} / ${it.duration}") }
.also { assertTrue(it.value) }

measureTimedValue { FSA.levIntersect(str, vanillaS2PCFG, led - 1) }
measureTimedValue { FSA.levIntersect(str, Grammars.dyck, led - 1) }
.also { println("${it.value} / ${it.duration}") }
.also { assertFalse(it.value) }
}
Expand Down

0 comments on commit ddee905

Please sign in to comment.