From ddee9051c4c30d43c92fac8524b15e580e2cbaad Mon Sep 17 00:00:00 2001 From: breandan Date: Mon, 13 Jan 2025 22:40:44 -0500 Subject: [PATCH] fix reference grammar --- .../kotlin/ai/hypergraph/kaliningraph/automata/FSA.kt | 2 +- .../kotlin/ai/hypergraph/kaliningraph/types/Graph.kt | 3 ++- .../ai/hypergraph/kaliningraph/parsing/BarHillelTest.kt | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/commonMain/kotlin/ai/hypergraph/kaliningraph/automata/FSA.kt b/src/commonMain/kotlin/ai/hypergraph/kaliningraph/automata/FSA.kt index a534e649..5081f916 100644 --- a/src/commonMain/kotlin/ai/hypergraph/kaliningraph/automata/FSA.kt +++ b/src/commonMain/kotlin/ai/hypergraph/kaliningraph/automata/FSA.kt @@ -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]}") } } } } diff --git a/src/commonMain/kotlin/ai/hypergraph/kaliningraph/types/Graph.kt b/src/commonMain/kotlin/ai/hypergraph/kaliningraph/types/Graph.kt index f83695ee..0d64ef80 100644 --- a/src/commonMain/kotlin/ai/hypergraph/kaliningraph/types/Graph.kt +++ b/src/commonMain/kotlin/ai/hypergraph/kaliningraph/types/Graph.kt @@ -255,7 +255,8 @@ val , E: IEdge, V: IVertex> IGraph val backward: Map> = 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 , E: IEdge, V: IVertex> IGraph.degMap: Map by cache { vertices.associateWith { it.neighbors.size } } diff --git a/src/commonTest/kotlin/ai/hypergraph/kaliningraph/parsing/BarHillelTest.kt b/src/commonTest/kotlin/ai/hypergraph/kaliningraph/parsing/BarHillelTest.kt index 6a0b4dab..7e6998b4 100644 --- a/src/commonTest/kotlin/ai/hypergraph/kaliningraph/parsing/BarHillelTest.kt +++ b/src/commonTest/kotlin/ai/hypergraph/kaliningraph/parsing/BarHillelTest.kt @@ -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) } }