docstr: Parses Google SGD episodes into TodStructuredEpisode.
docstr_tok: ["Parses","Google","SGD","episodes","into","TodStructuredEpisode","."]
code: def setup_episodes(self, fold):
      """
      Parses Google SGD episodes into TodStructuredEpisode.
      """
      schema_lookup, dialogues = self._load_data(fold)
      result = []
      for dialogue in dialogues:
          domains = {
              s.split("_")[0].strip() for s in dialogue["services"]
          }
          turns = dialogue["turns"]
          rounds = []
          for turn_id in range(0, len(turns), 2):
              user_turn = turns[turn_id]
              sys_turn = turns[turn_id + 1]
              api_call, api_results = self._get_api_call_and_results(
                  sys_turn
              )
              r = tod.TodStructuredRound(
                  user_utt=user_turn["utterance"],
                  api_call_machine=api_call,
                  api_resp_machine=api_results,
                  sys_utt=sys_turn["utterance"],
              )
              rounds.append(r)
          # Now that we've got the rounds, make the episode
          episode = tod.TodStructuredEpisode(
              domain=SerializationHelpers.inner_list_join(domains),
              api_schemas_machine=self._get_intent_groundinging(
                  schema_lookup, set(dialogue["services"])
              ),
              goal_calls_machine=self._get_all_service_calls(turns),
              rounds=rounds,
              delex=self.opt.get("delex"),
              extras={"dialogue_id": dialogue["dialogue_id"]},
          )
          result.append(episode)
      # check if the number of episodes should be limited and truncate as required
      return result
  
imports: import glob
  import json
  import os
  from typing import Any, Dict, List, Optional
  import parlai.tasks.google_sgd.build
  import parlai.core.tod.tod_core
  import parlai.core.tod.tod_agents
  from parlai.core.tod.tod_core import SerializationHelpers
  from parlai.core.message import Message
  from parlai.core.metrics import AverageMetric
  from parlai.core.params import ParlaiParser
  from parlai.core.opt import Opt
  from fuzzywuzzy import fuzz
  from parlai.utils.io import PathManager
label_desc: Use image node_id 9 for calling the GoogleSGDParser obj's underlying member method code with example usage: obj.setup_episodes(fold) and returns: result