Nasty.Rendering.Visualization (Nasty v0.3.0)
View SourceGenerates 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
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
@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 (TBtop-bottom,LRleft-right) (default:TB):show_pos_tags- Whether to show POS tags (default: true):show_spans- Whether to show position spans (default: false)
Functions
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 ..."
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": [...]}"