code: def to_dict(self, index=0):
          
          index += 1
          rep = {}
          rep["index"] = index
          rep["leaf"] = len(self.children) == 0
          rep["depth"] = self.udepth
          rep["scoreDistr"] = [0.0] * len(LabeledTree.SCORE_MAPPING)
          # dirac distribution at correct label
          if self.label is not None:
              rep["scoreDistr"][self.label] = 1.0
              mapping = LabeledTree.SCORE_MAPPING[:]
              rep["rating"] = mapping[self.label] - min(mapping)
          # if you are using this method for printing predictions
          # from a model, the the dot product with the model's output
          # distribution should be taken with this list:
          rep["numChildren"] = len(self.children)
          text = self.text if self.text != None else ""
          seen_tokens = 0
          witnessed_pixels = 0
          for i, child in enumerate(self.children):
              if i > 0:
                  text += " "
              child_key = "child%d" % (i)
              (rep[child_key], index) = child.to_dict(index)
              text += rep[child_key]["text"]
              seen_tokens += rep[child_key]["tokens"]
              witnessed_pixels += rep[child_key]["pixels"]
  
          rep["text"] = text
          rep["tokens"] = 1 if (self.text != None and len(self.text) > 0) else seen_tokens
          rep["pixels"] = witnessed_pixels + 3 if len(self.children) > 0 else text_size(self.text)
          return (rep, index)
docs: Dict format for use in Javascript / Jason Chuang's display technology.