Skip to content

Commit

Permalink
use conventional FSA rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
breandan committed Apr 30, 2024
1 parent c231fed commit d5cb019
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ interface IGraph<G, E, V>: IGF<G, E, V>, Set<V>, Encodable
graph ["concentrate"="false","rankdir"="LR","bgcolor"="transparent","margin"="0.0","compound"="true","nslimit"="20"]
${
vertices.joinToString("\n") {
""""${it.id.htmlify()}" ["color"="black","fontcolor"="black","fontname"="JetBrains Mono","fontsize"="15","penwidth"="2.0","shape"="Mrecord"${if(it in highlight)""","fillcolor"=lightgray,"style"=filled""" else ""}]""" }
""""${it.id.htmlify()}" ["shape"="Mrecord","color"="black","fontcolor"="black","fontname"="JetBrains Mono","fontsize"="15","penwidth"="2.0"${if(it in highlight)""","fillcolor"=lightgray,"style"=filled""" else ""}]""" }
}
${edgList.joinToString("\n") { (v, e) ->
val (src, tgt) = v.id.htmlify() to e.target.id.htmlify()
""""$src" -> "$tgt" ["color"="${ if (v is LGVertex && v.occupied) "red" else "black" }","arrowhead"="normal","penwidth"="2.0","label"="${(e as? LabeledEdge)?.label ?: ""}"]""" }
""""$src" -> "$tgt" ["color"="${ if (v is LGVertex && v.occupied) "red" else "black" }","fontname"="JetBrains Mono","arrowhead"="normal","penwidth"="2.0","label"="${(e as? LabeledEdge)?.label ?: ""}"]""" }
}
}
""".trimIndent()
Expand Down
18 changes: 14 additions & 4 deletions src/jvmTest/kotlin/ai/hypergraph/kaliningraph/automata/WFSATest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Grammars
import Grammars.shortS2PParikhMap
import ai.hypergraph.kaliningraph.graphs.LabeledGraph
import ai.hypergraph.kaliningraph.parsing.*
import ai.hypergraph.kaliningraph.visualization.alsoCopy
import ai.hypergraph.kaliningraph.visualization.*
import net.jhoogland.jautomata.*
import net.jhoogland.jautomata.Automaton
import net.jhoogland.jautomata.operations.*
Expand Down Expand Up @@ -44,14 +44,24 @@ class WFSATest {
transitionsOut(state).forEach {
val label = label(it) + "/" + transitionWeight(it).toString().take(4)
val next = this@toDot.to(it)
state.hashCode().toString()[label] = next.hashCode().toString()
val initws = initialWeight(state)
val finalws = finalWeight(state)
val initwn = initialWeight(next)
val finalwn = finalWeight(next)
(state.hashCode().toString() + "#$initws/$finalws")[label] = next.hashCode().toString() + "#$initwn/$finalwn"
if (next !in processed) {
processed.add(next)
stateQueue.add(next)
}
}
}
}.toDot().replace("Mrecord\"", "Mrecord\", label=\"\"")
}.toDot()
// States are typically unlabeled in FSA diagrams
.replace("Mrecord\"", "Mrecord\", label=\"\"")
// Final states are suffixed with /1.0 and drawn as double circles
.replace("/1.0\" [\"shape\"=\"Mrecord\"", "/1.0\" [\"shape\"=\"doublecircle\"")
.replace("Mrecord", "circle") // FSA states should be circular
.replace("null", "ε") // null label = ε-transition

/*
./gradlew jvmTest --tests "ai.hypergraph.kaliningraph.automata.WFSATest.testLBHRepair"
Expand All @@ -75,7 +85,7 @@ class WFSATest {
addTransition(s1, s2, a.root, 1.0)
}
}
)?.also { println("\n" + Operations.determinizeER(it).toDot().alsoCopy() + "\n") }
)?.also { println("\n" + it.toDot().alsoCopy() + "\n") }
.also { println("Total: ${Automata.transitions(it).size} arcs, ${Automata.states(it).size}") }
.let { Automata.bestStrings(it, 1000).map { it.label.joinToString(" ") }.toSet() }
}.also {
Expand Down

0 comments on commit d5cb019

Please sign in to comment.