class_docstr: Pretty-print a tree in text format, either as ASCII or Unicode.
  The tree can be a normal tree, or discontinuous.
  
  ``TreePrettyPrinter(tree, sentence=None, highlight=())``
  creates an object from which different visualizations can be created.
  
  :param tree: a Tree object.
  :param sentence: a list of words (strings). If `sentence` is given,
      `tree` must contain integers as leaves, which are taken as indices
      in `sentence`. Using this you can display a discontinuous tree.
  :param highlight: Optionally, a sequence of Tree objects in `tree` which
      should be highlighted. Has the effect of only applying colors to nodes
      in this sequence (nodes should be given as Tree objects, terminals as
      indices).
  
  >>> from nltk.tree import Tree
  >>> tree = Tree.fromstring('(S (NP Mary) (VP walks))')
  >>> print(TreePrettyPrinter(tree).text())
  ... # doctest: +NORMALIZE_WHITESPACE
        S
    ____|____
   NP        VP
   |         |
  Mary     walks
class_docstr_tok: ["Pretty-print","a","tree","in","text","format",",","either","as","ASCII","or","Unicode",".","The","tree","can","be","a","normal","tree",",","or","discontinuous",".","``","TreePrettyPrinter","(","tree",",","sentence=None",",","highlight=","(",")",")","``","creates","an","object","from","which","different","visualizations","can","be","created",".",":","param","tree",":","a","Tree","object",".",":","param","sentence",":","a","list","of","words","(","strings",")",".","If","`","sentence","`","is","given",",","`","tree","`","must","contain","integers","as","leaves",",","which","are","taken","as","indices","in","`","sentence","`",".","Using","this","you","can","display","a","discontinuous","tree",".",":","param","highlight",":","Optionally",",","a","sequence","of","Tree","objects","in","`","tree","`","which","should","be","highlighted",".","Has","the","effect","of","only","applying","colors","to","nodes","in","this","sequence","(","nodes","should","be","given","as","Tree","objects",",","terminals","as","indices",")",".",">",">",">","from","nltk.tree","import","Tree",">",">",">","tree","=","Tree.fromstring","(","'","(","S","(","NP","Mary",")","(","VP","walks",")",")","'",")",">",">",">","print","(","TreePrettyPrinter","(","tree",")",".text","(",")",")","...","#","doctest",":","+NORMALIZE_WHITESPACE","S","____|____","NP","VP","|","|","Mary","walks"]
docstr: :return: ASCII art for a discontinuous tree.
  
  :param unicodelines: whether to use Unicode line drawing characters
      instead of plain (7-bit) ASCII.
  :param html: whether to wrap output in html code (default plain text).
  :param ansi: whether to produce colors with ANSI escape sequences
      (only effective when html==False).
  :param leafcolor, nodecolor: specify colors of leaves and phrasal
      nodes; effective when either html or ansi is True.
  :param abbreviate: if True, abbreviate labels longer than 5 characters.
      If integer, abbreviate labels longer than `abbr` characters.
  :param maxwidth: maximum number of characters before a label starts to
      wrap; pass None to disable.
docstr_tok: [":","return",":","ASCII","art","for","a","discontinuous","tree",".",":","param","unicodelines",":","whether","to","use","Unicode","line","drawing","characters","instead","of","plain","(","7-bit",")","ASCII",".",":","param","html",":","whether","to","wrap","output","in","html","code","(","default","plain","text",")",".",":","param","ansi",":","whether","to","produce","colors","with","ANSI","escape","sequences","(","only","effective","when","html==False",")",".",":","param","leafcolor",",","nodecolor",":","specify","colors","of","leaves","and","phrasal","nodes",";","effective","when","either","html","or","ansi","is","True",".",":","param","abbreviate",":","if","True",",","abbreviate","labels","longer","than","5","characters",".","If","integer",",","abbreviate","labels","longer","than","`","abbr","`","characters",".",":","param","maxwidth",":","maximum","number","of","characters","before","a","label","starts","to","wrap",";","pass","None","to","disable","."]
code: def text(
      self,
      nodedist=1,
      unicodelines=False,
      html=False,
      ansi=False,
      nodecolor="blue",
      leafcolor="red",
      funccolor="green",
      abbreviate=None,
      maxwidth=16,
  ):
      """
      :return: ASCII art for a discontinuous tree.
  
      :param unicodelines: whether to use Unicode line drawing characters
          instead of plain (7-bit) ASCII.
      :param html: whether to wrap output in html code (default plain text).
      :param ansi: whether to produce colors with ANSI escape sequences
          (only effective when html==False).
      :param leafcolor, nodecolor: specify colors of leaves and phrasal
          nodes; effective when either html or ansi is True.
      :param abbreviate: if True, abbreviate labels longer than 5 characters.
          If integer, abbreviate labels longer than `abbr` characters.
      :param maxwidth: maximum number of characters before a label starts to
          wrap; pass None to disable.
      """
      if abbreviate == True:
          abbreviate = 5
      if unicodelines:
          horzline = "\u2500"
          leftcorner = "\u250c"
          rightcorner = "\u2510"
          vertline = " \u2502 "
          tee = horzline + "\u252C" + horzline
          bottom = horzline + "\u2534" + horzline
          cross = horzline + "\u253c" + horzline
          ellipsis = "\u2026"
      else:
          horzline = "_"
          leftcorner = rightcorner = " "
          vertline = " | "
          tee = 3 * horzline
          cross = bottom = "_|_"
          ellipsis = "."
  
      def crosscell(cur, x=vertline):
          """Overwrite center of this cell with a vertical branch."""
          splitl = len(cur) - len(cur) // 2 - len(x) // 2 - 1
          lst = list(cur)
          lst[splitl : splitl + len(x)] = list(x)
          return "".join(lst)
  
      result = []
      matrix = defaultdict(dict)
      maxnodewith = defaultdict(lambda: 3)
      maxnodeheight = defaultdict(lambda: 1)
      maxcol = 0
      minchildcol = {}
      maxchildcol = {}
      childcols = defaultdict(set)
      labels = {}
      wrapre = re.compile(
          "(.{%d,%d}\\b\\W*|.{%d})" % (maxwidth - 4, maxwidth, maxwidth)
      )
      # collect labels and coordinates
      for a in self.nodes:
          row, column = self.coords[a]
          matrix[row][column] = a
          maxcol = max(maxcol, column)
          label = (
              self.nodes[a].label()
              if isinstance(self.nodes[a], Tree)
              else self.nodes[a]
          )
          if abbreviate and len(label) > abbreviate:
              label = label[:abbreviate] + ellipsis
          if maxwidth and len(label) > maxwidth:
              label = wrapre.sub(r"\1\n", label).strip()
          label = label.split("\n")
          maxnodeheight[row] = max(maxnodeheight[row], len(label))
          maxnodewith[column] = max(
              maxnodewith[column], max(map(len, label))
          )
          labels[a] = label
          if a not in self.edges:
              continue  # e.g., root
          parent = self.edges[a]
          childcols[parent].add((row, column))
          minchildcol[parent] = min(
              minchildcol.get(parent, column), column
          )
          maxchildcol[parent] = max(
              maxchildcol.get(parent, column), column
          )
      # bottom up level order traversal
      for row in sorted(matrix, reverse=True):
          noderows = [
              ["".center(maxnodewith[col]) for col in range(maxcol + 1)]
              for _ in range(maxnodeheight[row])
          ]
          branchrow = [
              "".center(maxnodewith[col]) for col in range(maxcol + 1)
          ]
          for col in matrix[row]:
              n = matrix[row][col]
              node = self.nodes[n]
              text = labels[n]
              if isinstance(node, Tree):
                  # draw horizontal branch towards children for this node
                  if (
                      n in minchildcol
                      and minchildcol[n] < maxchildcol[n]
                  ):
                      i, j = minchildcol[n], maxchildcol[n]
                      a, b = (maxnodewith[i] + 1) // 2 - 1, maxnodewith[
                          j
                      ] // 2
                      branchrow[i] = ((" " * a) + leftcorner).ljust(
                          maxnodewith[i], horzline
                      )
                      branchrow[j] = (rightcorner + (" " * b)).rjust(
                          maxnodewith[j], horzline
                      )
                      for i in range(
                          minchildcol[n] + 1, maxchildcol[n]
                      ):
                          if i == col and any(
                              a == i for _, a in childcols[n]
                          ):
                              line = cross
                          elif i == col:
                              line = bottom
                          elif any(a == i for _, a in childcols[n]):
                              line = tee
                          else:
                              line = horzline
                          branchrow[i] = line.center(
                              maxnodewith[i], horzline
                          )
                  else:  # if n and n in minchildcol:
                      branchrow[col] = crosscell(branchrow[col])
              text = [a.center(maxnodewith[col]) for a in text]
              color = nodecolor if isinstance(node, Tree) else leafcolor
              if isinstance(node, Tree) and node.label().startswith(
                  "-"
              ):
                  color = funccolor
              if html:
                  text = [escape(a, quote=False) for a in text]
                  if n in self.highlight:
                      text = [
                          f"<font color={color}>{a}</font>"
                          for a in text
                      ]
              elif ansi and n in self.highlight:
                  text = [
                      "\x1b[%d;1m%s\x1b[0m" % (ANSICOLOR[color], a)
                      for a in text
                  ]
              for x in range(maxnodeheight[row]):
                  # draw vertical lines in partially filled multiline node
                  # labels, but only if it's not a frontier node.
                  noderows[x][col] = (
                      text[x]
                      if x < len(text)
                      else (vertline if childcols[n] else " ").center(
                          maxnodewith[col], " "
                      )
                  )
          # for each column, if there is a node below us which has a parent
          # above us, draw a vertical branch in that column.
          if row != max(matrix):
              for n, (childrow, col) in self.coords.items():
                  if (
                      n > 0
                      and self.coords[self.edges[n]][0] < row < childrow
                  ):
                      branchrow[col] = crosscell(branchrow[col])
                      if col not in matrix[row]:
                          for noderow in noderows:
                              noderow[col] = crosscell(noderow[col])
              branchrow = [
                  a + ((a[-1] if a[-1] != " " else b[0]) * nodedist)
                  for a, b in zip(branchrow, branchrow[1:] + [" "])
              ]
              result.append("".join(branchrow))
          result.extend(
              (" " * nodedist).join(noderow)
              for noderow in reversed(noderows)
          )
      return "\n".join(reversed(result)) + "\n"
  
file_path: nltk/nltk/tree/prettyprinter.py
imports: import re
  from collections import defaultdict
  from operator import itemgetter
  from nltk.tree.tree import Tree
  from nltk.util import OrderedDict
label_desc: Use image node_id 5 for calling the TreePrettyPrinter obj's underlying member method code with example usage: obj.text(nodedist, unicodelines, html, ansi, nodecolor, leafcolor, funccolor, abbreviate, maxwidth) and returns: unknown, str