Skip to content

Commit

Permalink
collect pcfg triples
Browse files Browse the repository at this point in the history
  • Loading branch information
breandan committed Feb 20, 2024
1 parent 6f371c4 commit c8f0880
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ai.hypergraph.kaliningraph.parsing
import ai.hypergraph.kaliningraph.graphs.LGVertex
import ai.hypergraph.kaliningraph.graphs.LabeledGraph
import ai.hypergraph.kaliningraph.tensor.FreeMatrix
import ai.hypergraph.kaliningraph.types.Π3A

typealias TreeMatrix = FreeMatrix<Forest>
typealias Forest = Set<Tree>
Expand All @@ -27,6 +28,11 @@ class Tree constructor(
if (children.isEmpty()) "()"
else children.joinToString("", prefix = "(", postfix = ")") { it.structureEncode() }

fun triples(): List<Π3A<Σᐩ>> =
if (children.size != 2) listOf()
else listOf(Π3A(root, children[0].root, children[1].root)) +
children.flatMap { it.triples() }

fun toGraph(j: Σᐩ = "0"): LabeledGraph =
LabeledGraph { LGVertex(root, "$root.$j").let { it - it } } +
children.foldIndexed(
Expand Down

0 comments on commit c8f0880

Please sign in to comment.