def get_table_parent_format(table, table_page_title, table_section_title,
                            table_section_text):
  """Convert table to format required by PARENT."""
  table_parent_array = []

  # Table values.
  for row in table:
    for cell in row:
      if cell["is_header"]:
        attribute = "header"
      else:
        attribute = "cell"
      value = cell["value"].strip()
      if value:
        value = value.replace("|", "-")
        entry = "%s|||%s" % (attribute, value)
        table_parent_array.append(entry)

  # Page title.
  if table_page_title:
    table_page_title = table_page_title.replace("|", "-")
    entry = "%s|||%s" % ("page_title", table_page_title)
    table_parent_array.append(entry)

  # Section title.
  if table_section_title:
    table_section_title = table_section_title.replace("|", "-")
    entry = "%s|||%s" % ("section_title", table_section_title)
    table_parent_array.append(entry)

  # Section text.
  if table_section_text:
    table_section_text = table_section_text.replace("|", "-")
    entry = "%s|||%s" % ("section_text", table_section_text)
    table_parent_array.append(entry)

  table_parent_str = "\t".join(table_parent_array)
  return table_parent_str
Convert table to format required by PARENT.
language/totto/table_to_text_utils.py