code: def process_jarvis_datasets(
      infold,
      outfold,
      modes=["train", "test", "dev"],
      do_lower_case=False,
      ignore_prev_intent=False,
  ):
      """
      Process and convert Jarvis datasets into NeMo's BIO format
      Args:
          infold: location for input fold of data
          outfold: location for output fold of data
          modes: dataset splits to process
          do_lowercase: whether to lowercase the input utterances
          ignore_prev_intent: whether to include intent from previous turn in predicting intent of current turn
      """
      dataset_name = "jarvis"
      if if_exist(outfold, ["dict.intents.csv", "dict.slots.csv"]):
          logging.info(
              DATABASE_EXISTS_TMP.format(dataset_name, outfold)
          )
          return outfold
  
      logging.info(
          f"Processing {dataset_name} dataset and storing at {outfold}"
      )
  
      os.makedirs(outfold, exist_ok=True)
  
      outfiles = {}
      intents_list = {}
      slots_list = {}
      slots_list_all = {}
  
      outfiles["dict_intents"] = open(
          f"{outfold}/dict.intents.csv", "w", encoding="utf-8"
      )
      outfiles["dict_slots"] = open(
          f"{outfold}/dict.slots.csv", "w", encoding="utf-8"
      )
  
      outfiles["dict_slots"].write("O\n")
      slots_list["O"] = 0
      slots_list_all["O"] = 0
  
      for mode in modes:
          if if_exist(outfold, [f"{mode}.tsv"]):
              logging.info(
                  MODE_EXISTS_TMP.format(
                      mode, dataset_name, outfold, mode
                  )
              )
              continue
  
          if not if_exist(infold, [f"{mode}.tsv"]):
              logging.info(
                  f"{mode} mode of {dataset_name}"
                  f" is skipped as it was not found."
              )
              continue
  
          outfiles[mode] = open(
              os.path.join(outfold, mode + ".tsv"),
              "w",
              encoding="utf-8",
          )
          outfiles[mode].write("sentence\tlabel\n")
          outfiles[mode + "_slots"] = open(
              f"{outfold}/{mode}_slots.tsv", "w", encoding="utf-8"
          )
  
          queries = open(
              f"{infold}/{mode}.tsv", "r", encoding="utf-8"
          ).readlines()
  
          for i, query in enumerate(queries):
              line_splits = query.strip().split("\t")
              if len(line_splits) == 3:
                  intent_str, slot_tags_str, sentence = line_splits
              else:
                  intent_str, sentence = line_splits
                  slot_tags_str = ""
  
              if intent_str not in intents_list:
                  intents_list[intent_str] = len(intents_list)
                  outfiles["dict_intents"].write(f"{intent_str}\n")
  
              if ignore_prev_intent:
                  start_token = 2
              else:
                  start_token = 1
  
              if do_lower_case:
                  sentence = sentence.lower()
              sentence_cld = " ".join(
                  sentence.strip().split()[start_token:-1]
              )
              outfiles[mode].write(
                  f"{sentence_cld}\t"
                  f"{str(intents_list[intent_str])}\n"
              )
  
              slot_tags_list = []
              if slot_tags_str.strip():
                  slot_tags = slot_tags_str.strip().split(",")
                  for st in slot_tags:
                      if not st.strip():
                          continue
                      [start_i, end_i, slot_name] = st.strip().split(
                          ":"
                      )
                      slot_tags_list.append(
                          [int(start_i), int(end_i), slot_name]
                      )
                      if slot_name not in slots_list:
                          slots_list[slot_name] = len(slots_list)
                          slots_list_all[f"B-{slot_name}"] = len(
                              slots_list_all
                          )
                          slots_list_all[f"I-{slot_name}"] = len(
                              slots_list_all
                          )
                          outfiles["dict_slots"].write(
                              f"B-{slot_name}\n"
                          )
                          outfiles["dict_slots"].write(
                              f"I-{slot_name}\n"
                          )
  
              slot_tags_list.sort(key=lambda x: x[0])
              slots = []
              processed_index = 0
              for tag_start, tag_end, tag_str in slot_tags_list:
                  if tag_start > processed_index:
                      words_list = (
                          sentence[processed_index:tag_start]
                          .strip()
                          .split()
                      )
                      slots.extend(
                          [str(slots_list_all["O"])] * len(words_list)
                      )
                  words_list = (
                      sentence[tag_start:tag_end].strip().split()
                  )
                  slots.append(str(slots_list_all[f"B-{tag_str}"]))
                  slots.extend(
                      [str(slots_list_all[f"I-{tag_str}"])]
                      * (len(words_list) - 1)
                  )
                  processed_index = tag_end
  
              if processed_index < len(sentence):
                  words_list = (
                      sentence[processed_index:].strip().split()
                  )
                  slots.extend(
                      [str(slots_list_all["O"])] * len(words_list)
                  )
  
              slots = slots[1:-1]
              slot = " ".join(slots)
              outfiles[mode + "_slots"].write(slot + "\n")
  
          outfiles[mode + "_slots"].close()
          outfiles[mode].close()
  
      outfiles["dict_slots"].close()
      outfiles["dict_intents"].close()
  
      return outfold
  
file_path: NeMo/scripts/dataset_processing/nlp/intent_and_slot/import_datasets.py
imports: import argparse
  import os
  import shutil
  from os.path import exists
  from assistant_utils import process_assistant
  from nemo.collections.nlp.data.data_utils.data_preprocessing import DATABASE_EXISTS_TMP, MODE_EXISTS_TMP, create_dataset, get_dataset, get_vocab, if_exist
  from nemo.utils import logging
label_desc: Use image node_id 4 for calling a global function with example usage: process_jarvis_datasets(infold, outfold, modes, do_lower_case, ignore_prev_intent) and returns: outfold, outfold