예제 #1
0
  protected void toDOTDefineEdges(Object tree, TreeAdaptor adaptor, StringTemplate treeST) {
    if (tree == null) {
      return;
    }
    int n = adaptor.getChildCount(tree);
    if (n == 0) {
      // must have already dumped as child from previous
      // invocation; do nothing
      return;
    }

    String parentName = "n" + getNodeNumber(tree);

    // for each child, do a parent -> child edge using unique node names
    String parentText = adaptor.getText(tree);
    for (int i = 0; i < n; i++) {
      Object child = adaptor.getChild(tree, i);
      String childText = adaptor.getText(child);
      String childName = "n" + getNodeNumber(child);
      StringTemplate edgeST = _edgeST.getInstanceOf();
      edgeST.setAttribute("parent", parentName);
      edgeST.setAttribute("child", childName);
      edgeST.setAttribute("parentText", fixString(parentText));
      edgeST.setAttribute("childText", fixString(childText));
      treeST.setAttribute("edges", edgeST);
      toDOTDefineEdges(child, adaptor, treeST);
    }
  }
예제 #2
0
  protected StringTemplate getNodeST(TreeAdaptor adaptor, Object t) {
    String text = adaptor.getText(t);
    StringTemplate nodeST = _nodeST.getInstanceOf();
    String uniqueName = "n" + getNodeNumber(t);
    nodeST.setAttribute("name", uniqueName);

    nodeST.setAttribute("text", fixString(text));
    return nodeST;
  }
예제 #3
0
 public StringTemplate toDOT(
     Object tree, TreeAdaptor adaptor, StringTemplate _treeST, StringTemplate _edgeST) {
   StringTemplate treeST = _treeST.getInstanceOf();
   nodeNumber = 0;
   toDOTDefineNodes(tree, adaptor, treeST);
   nodeNumber = 0;
   toDOTDefineEdges(tree, adaptor, treeST);
   /*
   if ( adaptor.getChildCount(tree)==0 ) {
             // single node, don't do edge.
             treeST.setAttribute("nodes", adaptor.getText(tree));
         }
         */
   return treeST;
 }