class_docstr: Data Processor for SGD dialogues.
  
  More information at https://arxiv.org/abs/1909.05855
  
  ***Downloading the dataset***
      #   git clone https://github.com/google-research-datasets/dstc8-schema-guided-dialogue.git
  
  ***Data format***
  SGD data comes with a JSON schema file and dialogue files for each dataset split. 
  
  In the following we will show an example for a service entry in the schema file.
  * service_name
  * description
  * slots
      * name
      * description
      * is_categorical
      * possible values
  * intents
      * name
      * description
      * required_slots (not used)
      * is_transactional (not used)
      * optional_slots (not used)
      * result_slots (not used)
  
  
  In the following we will show an example for a dialogue. 
  * dialogue_id
  * services
  * turns
      * frames
          * actions
              * act
              * slot
              * values
          * service
          * slots
              * exclusive_end
              * slot
              * start
          * state
              * active_intent
              * requeste_slots
              * slot_values 
      * speaker - [USER, SYSTEM]
      * utterance
docstr: Creates an example for each frame in the user turn.
  Args:
      turn_id: turn number
      system_utterance: last system utterance
      user_utterance: lst user utterance
      system_frames: all system utterances and slot - slot value pairs
      user_frames: all user utterances and slot - slot value pairs
      prev_states: slot - slot value pairs from the previous turns
      schemas: schema for all services of all datasets
      subsample: whether to balance postive and negative samples in the dataset
  Returns:
      examples: a list of `InputExample`s.
      prev_states: updated dialogue state e.g. {'Restaurants_1': {'city': ['San Jose'], 'cuisine': ['American']}}
docstr_tok: ["Creates","an","example","for","each","frame","in","the","user","turn",".","Args",":","turn_id",":","turn","number","system_utterance",":","last","system","utterance","user_utterance",":","lst","user","utterance","system_frames",":","all","system","utterances","and","slot","-","slot","value","pairs","user_frames",":","all","user","utterances","and","slot","-","slot","value","pairs","prev_states",":","slot","-","slot","value","pairs","from","the","previous","turns","schemas",":","schema","for","all","services","of","all","datasets","subsample",":","whether","to","balance","postive","and","negative","samples","in","the","dataset","Returns",":","examples",":","a","list","of","`","InputExample","`","s",".","prev_states",":","updated","dialogue","state","e.g",".","{","'Restaurants_1","'",":","{","'city","'",":","[","'San","Jose","'","]",",","'cuisine","'",":","[","'American","'","]","}","}"]
code: def _create_examples_from_turn(
      self,
      turn_id: int,
      system_utterance: str,
      user_utterance: str,
      system_frames: dict,
      user_frames: dict,
      prev_states: dict,
      schemas: object,
      subsample: bool,
  ):
      """
      Creates an example for each frame in the user turn.
      Args:
          turn_id: turn number
          system_utterance: last system utterance
          user_utterance: lst user utterance
          system_frames: all system utterances and slot - slot value pairs
          user_frames: all user utterances and slot - slot value pairs
          prev_states: slot - slot value pairs from the previous turns
          schemas: schema for all services of all datasets
          subsample: whether to balance postive and negative samples in the dataset
      Returns:
          examples: a list of `InputExample`s.
          prev_states: updated dialogue state e.g. {'Restaurants_1': {'city': ['San Jose'], 'cuisine': ['American']}}
      """
      system_user_utterance = system_utterance + " " + user_utterance
      states = {}
  
      examples = []
      slot_carryover_values = collections.defaultdict(list)
  
      for service, user_frame in user_frames.items():
          state = user_frame["state"]["slot_values"]
          state_update = self._get_state_update(
              state, prev_states.get(service, {})
          )
          states[service] = state
          system_frame = system_frames.get(service, None)
          dataset_split, dialog_id, turn_id_ = turn_id.split("-")
          dialog_id_1, dialog_id_2 = dialog_id.split("_")
          example_id = f"{turn_id}-{service}"
          example_id_num = [
              int(dialog_id_1),
              int(dialog_id_2),
              int(turn_id_),
              schemas.get_service_id(service),
          ]
          intent = user_frames[service]["state"]["active_intent"]
          all_possible_slots = schemas.get_service_schema(service).slots
          categorical_slots = schemas.get_service_schema(
              service
          ).categorical_slots
          one_example = {
              "example_id": example_id,
              "example_id_num": example_id_num,
              "utterance": user_utterance,
              "system_utterance": system_utterance,
              "system_slots": {
                  slot["slot"]: slot for slot in system_frame["slots"]
              }
              if system_frame is not None
              else None,
              "system_actions": system_frame["actions"]
              if system_frame is not None
              else None,
              "labels": {
                  "service": service,
                  "intent": self.preprocess_intent(
                      intent, schemas, service
                  ),
                  "slots": {slot: state[slot] for slot in state_update},
              },
              "label_positions": {
                  "slots": {
                      slot["slot"]: slot
                      for slot in user_frames[service]["slots"]
                  }
              },
              "possible_labels": {
                  "service": schemas.services,
                  "intent": [
                      self.preprocess_intent(intent, schemas, service)
                      for intent in schemas.get_service_schema(
                          service
                      ).intents
                  ],
                  "slots": {
                      slot: schemas.get_service_schema(
                          service
                      ).get_categorical_slot_values(slot)
                      if slot in categorical_slots
                      else []
                      for slot in all_possible_slots
                  },
              },
              "description": {
                  "service": schemas.get_service_schema(
                      service
                  ).description,
                  "intent": schemas.get_service_schema(
                      service
                  ).intent_descriptions[intent],
                  "slots": {
                      slot: schemas.get_service_schema(
                          service
                      ).slot_descriptions[slot]
                      for slot in state_update
                  },
              },
          }
  
          examples.append(DialogueInputExample(one_example))
  
          if service not in prev_states and int(turn_id_) > 0:
              for slot_name, values in state_update.items():
                  for value in values:
                      slot_carryover_values[value].append(
                          (service, slot_name)
                      )
              for (
                  prev_service,
                  prev_slot_value_list,
              ) in prev_states.items():
                  if prev_service == service:
                      continue
                  if prev_service in state:
                      prev_slot_value_list = state[prev_service]
                  for (
                      prev_slot_name,
                      prev_values,
                  ) in prev_slot_value_list.items():
                      for prev_value in prev_values:
                          slot_carryover_values[prev_value].append(
                              (prev_service, prev_slot_name)
                          )
  
      return examples, states, slot_carryover_values
  
imports: import collections
  import json
  import os
  import pickle
  import re
  from typing import List
  from nemo.collections.nlp.data.dialogue.data_processor.data_processor import DialogueDataProcessor
  from nemo.collections.nlp.data.dialogue.input_example.input_example import DialogueInputExample
  from nemo.collections.nlp.data.dialogue.sgd.schema import Schema
  from nemo.utils import logging
  from nemo.utils.get_rank import is_global_rank_zero
label_desc: Use image node_id 14 for calling the DialogueSGDDataProcessor obj's underlying member method code with example usage: obj._create_examples_from_turn(turn_id, system_utterance, user_utterance, system_frames, user_frames, prev_states, schemas, subsample) and returns: examples,  states,  slot_carryover_values