class_docstr: The Treebank detokenizer uses the reverse regex operations corresponding to
  the Treebank tokenizer's regexes.
  
  Note:
  
  - There're additional assumption mades when undoing the padding of ``[;@#$%&]``
    punctuation symbols that isn't presupposed in the TreebankTokenizer.
  - There're additional regexes added in reversing the parentheses tokenization,
     such as the ``r'([\]\)\}\>])\s([:;,.])'``, which removes the additional right
     padding added to the closing parentheses precedding ``[:;,.]``.
  - It's not possible to return the original whitespaces as they were because
    there wasn't explicit records of where `'\n'`, `'\t'` or `'\s'` were removed at
    the text.split() operation.
  
  >>> from nltk.tokenize.treebank import TreebankWordTokenizer, TreebankWordDetokenizer
  >>> s = '''Good muffins cost $3.88\nin New York.  Please buy me\ntwo of them.\nThanks.'''
  >>> d = TreebankWordDetokenizer()
  >>> t = TreebankWordTokenizer()
  >>> toks = t.tokenize(s)
  >>> d.detokenize(toks)
  'Good muffins cost $3.88 in New York. Please buy me two of them. Thanks.'
  
  The MXPOST parentheses substitution can be undone using the ``convert_parentheses``
  parameter:
  
  >>> s = '''Good muffins cost $3.88\nin New (York).  Please (buy) me\ntwo of them.\n(Thanks).'''
  >>> expected_tokens = ['Good', 'muffins', 'cost', '$', '3.88', 'in',
  ... 'New', '-LRB-', 'York', '-RRB-', '.', 'Please', '-LRB-', 'buy',
  ... '-RRB-', 'me', 'two', 'of', 'them.', '-LRB-', 'Thanks', '-RRB-', '.']
  >>> expected_tokens == t.tokenize(s, convert_parentheses=True)
  True
  >>> expected_detoken = 'Good muffins cost $3.88 in New (York). Please (buy) me two of them. (Thanks).'
  >>> expected_detoken == d.detokenize(t.tokenize(s, convert_parentheses=True), convert_parentheses=True)
  True
  
  During tokenization it's safe to add more spaces but during detokenization,
  simply undoing the padding doesn't really help.
  
  - During tokenization, left and right pad is added to ``[!?]``, when
    detokenizing, only left shift the ``[!?]`` is needed.
    Thus ``(re.compile(r'\s([?!])'), r'\g<1>')``.
  
  - During tokenization ``[:,]`` are left and right padded but when detokenizing,
    only left shift is necessary and we keep right pad after comma/colon
    if the string after is a non-digit.
    Thus ``(re.compile(r'\s([:,])\s([^\d])'), r'\1 \2')``.
  
  >>> from nltk.tokenize.treebank import TreebankWordDetokenizer
  >>> toks = ['hello', ',', 'i', 'ca', "n't", 'feel', 'my', 'feet', '!', 'Help', '!', '!']
  >>> twd = TreebankWordDetokenizer()
  >>> twd.detokenize(toks)
  "hello, i can't feel my feet! Help!!"
  
  >>> toks = ['hello', ',', 'i', "can't", 'feel', ';', 'my', 'feet', '!',
  ... 'Help', '!', '!', 'He', 'said', ':', 'Help', ',', 'help', '?', '!']
  >>> twd.detokenize(toks)
  "hello, i can't feel; my feet! Help!! He said: Help, help?!"
docstr: Treebank detokenizer, created by undoing the regexes from
  the TreebankWordTokenizer.tokenize.
  
  :param tokens: A list of strings, i.e. tokenized text.
  :type tokens: List[str]
  :param convert_parentheses: if True, replace PTB symbols with parentheses,
      e.g. `-LRB-` to `(`. Defaults to False.
  :type convert_parentheses: bool, optional
  :return: str
docstr_tok: ["Treebank","detokenizer",",","created","by","undoing","the","regexes","from","the","TreebankWordTokenizer.tokenize",".",":","param","tokens",":","A","list","of","strings",",","i.e",".","tokenized","text",".",":","type","tokens",":","List","[","str","]",":","param","convert_parentheses",":","if","True",",","replace","PTB","symbols","with","parentheses",",","e.g",".","`","-LRB-","`","to","`","(","`",".","Defaults","to","False",".",":","type","convert_parentheses",":","bool",",","optional",":","return",":","str"]
code: def tokenize(
      self, tokens: List[str], convert_parentheses: bool = False
  ) -> str:
      """
      Treebank detokenizer, created by undoing the regexes from
      the TreebankWordTokenizer.tokenize.
  
      :param tokens: A list of strings, i.e. tokenized text.
      :type tokens: List[str]
      :param convert_parentheses: if True, replace PTB symbols with parentheses,
          e.g. `-LRB-` to `(`. Defaults to False.
      :type convert_parentheses: bool, optional
      :return: str
      """
      text = " ".join(tokens)
  
      # Add extra space to make things easier
      text = " " + text + " "
  
      # Reverse the contractions regexes.
      # Note: CONTRACTIONS4 are not used in tokenization.
      for regexp in self.CONTRACTIONS3:
          text = regexp.sub(r"\1\2", text)
      for regexp in self.CONTRACTIONS2:
          text = regexp.sub(r"\1\2", text)
  
      # Reverse the regexes applied for ending quotes.
      for regexp, substitution in self.ENDING_QUOTES:
          text = regexp.sub(substitution, text)
  
      # Undo the space padding.
      text = text.strip()
  
      # Reverse the padding on double dashes.
      regexp, substitution = self.DOUBLE_DASHES
      text = regexp.sub(substitution, text)
  
      if convert_parentheses:
          for regexp, substitution in self.CONVERT_PARENTHESES:
              text = regexp.sub(substitution, text)
  
      # Reverse the padding regexes applied for parenthesis/brackets.
      for regexp, substitution in self.PARENS_BRACKETS:
          text = regexp.sub(substitution, text)
  
      # Reverse the regexes applied for punctuations.
      for regexp, substitution in self.PUNCTUATION:
          text = regexp.sub(substitution, text)
  
      # Reverse the regexes applied for starting quotes.
      for regexp, substitution in self.STARTING_QUOTES:
          text = regexp.sub(substitution, text)
  
      return text.strip()
  
file_path: nltk/nltk/tokenize/treebank.py
imports: import re
  import warnings
  from typing import Iterator, List, Tuple
  from nltk.tokenize.api import TokenizerI
  from nltk.tokenize.destructive import MacIntyreContractions
  from nltk.tokenize.util import align_tokens
label_desc: Use image node_id 1 for calling the TreebankWordDetokenizer obj's underlying member method code with example usage: obj.tokenize(tokens, convert_parentheses) and returns: text