tree-renderer.h
Go to the documentation of this file.
1 // tree/tree-renderer.h
2 
3 // Copyright 2012 Vassil Panayotov
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
20 #ifndef KALDI_TREE_TREE_RENDERER_H_
21 #define KALDI_TREE_TREE_RENDERER_H_
22 
23 #include "base/kaldi-common.h"
24 #include "tree/event-map.h"
25 #include "util/common-utils.h"
26 #include "fst/fstlib.h"
27 
28 namespace kaldi {
29 
30 // Parses a decision tree file and outputs its description in GraphViz format
31 class TreeRenderer {
32  public:
33  const static int32 kEdgeWidth; // normal width of the edges and state contours
34  const static int32 kEdgeWidthQuery; // edge and state width when in query
35  const static std::string kEdgeColor; // normal color for states and edges
36  const static std::string kEdgeColorQuery; // edge and state color when in query
37 
38  TreeRenderer(std::istream &is, bool binary, std::ostream &os,
39  fst::SymbolTable &phone_syms, bool use_tooltips)
40  : phone_syms_(phone_syms), is_(is), out_(os), binary_(binary),
41  N_(-1), use_tooltips_(use_tooltips), next_id_(0) {}
42 
43  // Renders the tree and if the "query" parameter is not NULL
44  // a distinctly colored trace corresponding to the event.
45  void Render(const EventType *query);
46 
47  private:
48  // Looks-up the next token from the stream and invokes
49  // the appropriate render method to visualize it
50  void RenderSubTree(const EventType *query, int32 id);
51 
52  // Renders a leaf node (constant event map)
53  void RenderConstant(const EventType *query, int32 id);
54 
55  // Renders a split event map node and the edges to the nodes
56  // representing YES and NO sets
57  void RenderSplit(const EventType *query, int32 id);
58 
59  // Renders a table event map node and the edges to its (non-null) children
60  void RenderTable(const EventType *query, int32 id);
61 
62  // Makes a comma-separated string from the elements of a set of identifiers
63  // If the identifiers represent phones, their symbolic representations are used
64  std::string MakeEdgeLabel(const EventKeyType &key,
65  const ConstIntegerSet<EventValueType> &intset);
66 
67  // Writes the GraphViz representation of a non-leaf node to the out stream
68  // A question about a phone from the context window or about pdf-class
69  // is used as a label.
70  void RenderNonLeaf(int32 id, const EventKeyType &key, bool in_query);
71 
72  fst::SymbolTable &phone_syms_; // phone symbols to be used as edge labels
73  std::istream &is_; // the stream from which the tree is read
74  std::ostream &out_; // the GraphViz representation is written to this stream
75  bool binary_; // is the input stream binary?
76  int32 N_, P_; // context-width and central position
77  bool use_tooltips_; // use tooltips(useful in e.g. SVG) instead of labels
78  int32 next_id_; // the first unused GraphViz node ID
79 };
80 
81 } // namespace kaldi
82 
83 #endif // KALDI_TREE_TREE_RENDERER_H_
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
fst::SymbolTable & phone_syms_
Definition: tree-renderer.h:72
TreeRenderer(std::istream &is, bool binary, std::ostream &os, fst::SymbolTable &phone_syms, bool use_tooltips)
Definition: tree-renderer.h:38
kaldi::int32 int32
void RenderSplit(const EventType *query, int32 id)
std::ostream & out_
Definition: tree-renderer.h:74
std::vector< std::pair< EventKeyType, EventValueType > > EventType
Definition: event-map.h:58
int32 EventKeyType
Things of type EventKeyType can take any value.
Definition: event-map.h:45
std::istream & is_
Definition: tree-renderer.h:73
void RenderConstant(const EventType *query, int32 id)
static const int32 kEdgeWidth
Definition: tree-renderer.h:33
void RenderNonLeaf(int32 id, const EventKeyType &key, bool in_query)
void RenderSubTree(const EventType *query, int32 id)
std::string MakeEdgeLabel(const EventKeyType &key, const ConstIntegerSet< EventValueType > &intset)
static const std::string kEdgeColorQuery
Definition: tree-renderer.h:36
static const int32 kEdgeWidthQuery
Definition: tree-renderer.h:34
void RenderTable(const EventType *query, int32 id)
static const std::string kEdgeColor
Definition: tree-renderer.h:35
void Render(const EventType *query)