Nasty.Rendering.Visualization (Nasty v0.3.0)

View Source

Generates visual representations of AST structures.

Exports AST to DOT format for rendering with Graphviz tools. Supports parse trees, dependency graphs, and entity graphs.

Examples

# Generate parse tree
iex> dot = Nasty.Rendering.Visualization.to_dot(document, type: :parse_tree)
iex> File.write("tree.dot", dot)
iex> System.cmd("dot", ["-Tpng", "tree.dot", "-o", "tree.png"])

# Generate dependency graph
iex> dot = Nasty.Rendering.Visualization.to_dot(sentence, type: :dependencies)
iex> File.write("deps.dot", dot)

DOT Format

The DOT format is used by Graphviz to render graphs. See: https://graphviz.org/doc/info/lang.html

Summary

Types

Visualization options.

Functions

Converts an AST node to DOT format for Graphviz.

Converts an AST node to JSON format for d3.js or other visualization tools.

Types

options()

@type options() :: [
  type: :parse_tree | :dependencies | :entities,
  format: :dot | :json,
  rankdir: String.t(),
  show_pos_tags: boolean(),
  show_spans: boolean()
]

Visualization options.

  • :type - Type of visualization (:parse_tree, :dependencies, :entities)
  • :format - Output format (:dot, :json) (default: :dot)
  • :rankdir - Graph direction (TB top-bottom, LR left-right) (default: TB)
  • :show_pos_tags - Whether to show POS tags (default: true)
  • :show_spans - Whether to show position spans (default: false)

Functions

to_dot(node, opts \\ [])

@spec to_dot(term(), options()) :: String.t()

Converts an AST node to DOT format for Graphviz.

Examples

iex> Nasty.Rendering.Visualization.to_dot(document)
"digraph AST {\n  rankdir=TB;\n  ..."

iex> Nasty.Rendering.Visualization.to_dot(sentence, type: :dependencies)
"digraph Dependencies {\n  ..."

to_json(node, opts \\ [])

@spec to_json(term(), options()) :: String.t()

Converts an AST node to JSON format for d3.js or other visualization tools.

Examples

iex> Nasty.Rendering.Visualization.to_json(document)
"{"type": "Document", "language": "en", "children": [...]}"