treeToDataFrames: Convert a tree to two dataframes.

View source: R/t2df.R

treeToDataFramesR Documentation

Convert a tree to two dataframes.

Description

Converts a derivation tree into a list of two data frames. With the R-package igraph the data frames can be plotted as a derivation tree.

Usage

treeToDataFrames(tree, G, verbose)

Arguments

tree

Derivation tree.

G

The context-free grammar.

verbose

If TRUE, print derivations on console. Default: FALSE.

Details

Works with complete and incomplete derivation trees.

Value

A named list with two data frames:

  1. The data frame $V of vertices with the columns $V$id (numerical identifier) and $V$name (symbol of the grammar G).

  2. The data frame $E of edges with the columns $E$from and $E$to$.

Examples

g<-compileBNF(booleanGrammar())
a<-randomDerivationTree(g$Start, g)
x<-treeToDataFrames(a, g, verbose=TRUE)
# library(igraph) 
# g1<-graph_from_data_frame(x$E, directed=TRUE, vertices=x$V)
# plot(g1, layout=layout_as_tree)


xegaDerivationTrees documentation built on April 16, 2025, 5:11 p.m.