class_docstr: Writes training data into a file in a YAML format.
class_docstr_tok: ["Writes","training","data","into","a","file","in","a","YAML","format","."]
docstr: Prepares training examples  to be written to YAML.
  
  This can be any NLU training data (intent examples, lookup tables, etc.)
  
  Args:
      training_examples: Multiple training examples. Mappings in case additional
          values were specified for an example (e.g. metadata) or just the plain
          value.
      key_name: The top level key which the examples belong to (e.g. `intents`)
      key_examples: The sub key which the examples should be added to
          (e.g. `examples`).
      example_extraction_predicate: Function to extract example value (e.g. the
          the text for an intent example)
  
  Returns:
      NLU training data examples prepared for writing to YAML.
code: def process_training_examples_by_key(
      training_examples: Dict[Text, List[Union[Dict, Text]]],
      key_name: Text,
      key_examples: Text,
      example_extraction_predicate: Callable[[Dict[Text, Any]], Text],
  ) -> List[OrderedDict]:
      """Prepares training examples  to be written to YAML.
  
      This can be any NLU training data (intent examples, lookup tables, etc.)
  
      Args:
          training_examples: Multiple training examples. Mappings in case additional
              values were specified for an example (e.g. metadata) or just the plain
              value.
          key_name: The top level key which the examples belong to (e.g. `intents`)
          key_examples: The sub key which the examples should be added to
              (e.g. `examples`).
          example_extraction_predicate: Function to extract example value (e.g. the
              the text for an intent example)
  
      Returns:
          NLU training data examples prepared for writing to YAML.
      """
      intents = []
  
      for intent_name, examples in training_examples.items():
          (
              converted,
              intent_metadata,
          ) = RasaYAMLWriter._convert_training_examples(
              examples, example_extraction_predicate
          )
  
          intent: OrderedDict[Text, Any] = OrderedDict()
          intent[key_name] = intent_name
          if intent_metadata:
              intent[KEY_METADATA] = intent_metadata
  
          examples_have_metadata = any(
              KEY_METADATA in ex for ex in converted
          )
          example_texts_have_escape_chars = any(
              rasa.shared.nlu.training_data.util.has_string_escape_chars(
                  ex.get(KEY_INTENT_TEXT, "")
              )
              for ex in converted
          )
  
          if examples_have_metadata or example_texts_have_escape_chars:
              intent[
                  key_examples
              ] = RasaYAMLWriter._render_training_examples_as_objects(
                  converted
              )
          else:
              intent[
                  key_examples
              ] = RasaYAMLWriter._render_training_examples_as_text(
                  converted
              )
  
          intents.append(intent)
  
      return intents
  
imports: import logging
  from collections import OrderedDict
  from pathlib import Path
  from typing import Text, Any, List, Dict, Tuple, Union, Iterator, Optional, Callable
  import rasa.shared.data
  from rasa.shared.core.domain import Domain
  from rasa.shared.exceptions import YamlException
  from rasa.shared.utils import validation
  from ruamel.yaml import StringIO
  from ruamel.yaml.scalarstring import LiteralScalarString
  from rasa.shared.constants import DOCS_URL_TRAINING_DATA, LATEST_TRAINING_DATA_FORMAT_VERSION
  from rasa.shared.nlu.constants import METADATA_INTENT, METADATA_EXAMPLE
  from rasa.shared.nlu.training_data.formats.readerwriter import TrainingDataReader, TrainingDataWriter
  import rasa.shared.utils.io
  import rasa.shared.nlu.training_data.util
  from rasa.shared.nlu.training_data.training_data import TrainingData
  from rasa.shared.nlu.training_data.message import Message
label_desc: Use image node_id 8 for calling the RasaYAMLWriter obj's underlying member method code with example usage: obj.process_training_examples_by_key(training_examples, key_name, key_examples, example_extraction_predicate) and returns: intents