code: def validate_and_format_dataset(dataset):
      """Checks that the dataset is valid and format it
  
      Raise:
          DatasetFormatError: When the dataset format is wrong
      """
      from snips_nlu_parsers import get_all_languages
  
      if isinstance(dataset, Dataset):
          dataset = dataset.json
  
      # Make this function idempotent
      if dataset.get(VALIDATED, False):
          return dataset
      dataset = deepcopy(dataset)
      dataset = json.loads(json.dumps(dataset))
      validate_type(dataset, dict, object_label="dataset")
      mandatory_keys = [INTENTS, ENTITIES, LANGUAGE]
      for key in mandatory_keys:
          validate_key(dataset, key, object_label="dataset")
      validate_type(dataset[ENTITIES], dict, object_label="entities")
      validate_type(dataset[INTENTS], dict, object_label="intents")
      language = dataset[LANGUAGE]
      validate_type(language, str, object_label="language")
      if language not in get_all_languages():
          raise DatasetFormatError("Unknown language: '%s'" % language)
  
      dataset[INTENTS] = {
          intent_name: intent_data
          for intent_name, intent_data in sorted(
              iteritems(dataset[INTENTS])
          )
      }
      for intent in itervalues(dataset[INTENTS]):
          _validate_and_format_intent(intent, dataset[ENTITIES])
  
      utterance_entities_values = extract_utterance_entities(dataset)
      builtin_entity_parser = BuiltinEntityParser.build(dataset=dataset)
  
      dataset[ENTITIES] = {
          intent_name: entity_data
          for intent_name, entity_data in sorted(
              iteritems(dataset[ENTITIES])
          )
      }
  
      for entity_name, entity in iteritems(dataset[ENTITIES]):
          uterrance_entities = utterance_entities_values[entity_name]
          if is_builtin_entity(entity_name):
              dataset[ENTITIES][
                  entity_name
              ] = _validate_and_format_builtin_entity(
                  entity, uterrance_entities
              )
          else:
              dataset[ENTITIES][
                  entity_name
              ] = _validate_and_format_custom_entity(
                  entity,
                  uterrance_entities,
                  language,
                  builtin_entity_parser,
              )
      dataset[VALIDATED] = True
      return dataset
  
file_path: snips-nlu/snips_nlu/dataset/validation.py
imports: from __future__ import division, unicode_literals
  import json
  from builtins import str
  from collections import Counter
  from copy import deepcopy
  from future.utils import iteritems, itervalues
  from snips_nlu.common.dataset_utils import validate_key, validate_keys, validate_type
  from snips_nlu.constants import AUTOMATICALLY_EXTENSIBLE, CAPITALIZE, DATA, ENTITIES, ENTITY, INTENTS, LANGUAGE, MATCHING_STRICTNESS, SLOT_NAME, SYNONYMS, TEXT, USE_SYNONYMS, UTTERANCES, VALIDATED, VALUE, LICENSE_INFO
  from snips_nlu.dataset import extract_utterance_entities, Dataset
  from snips_nlu.entity_parser.builtin_entity_parser import BuiltinEntityParser, is_builtin_entity
  from snips_nlu.exceptions import DatasetFormatError
  from snips_nlu.preprocessing import tokenize_light
  from snips_nlu.string_variations import get_string_variations
label_desc: Use image node_id 1 for calling a global function with example usage: validate_and_format_dataset(dataset) and returns: dataset, dataset