code: def tag_ner(lang, input_text, output_type=list):
      """Run NER for chosen language."""
  
      _check_latest_data(lang)
  
      assert (
          lang in NER_DICT.keys()
      ), "Invalid language. Choose from: {}".format(
          ", ".join(NER_DICT.keys())
      )
      types = [str, list]
      assert type(input_text) in types, "Input must be: {}.".format(
          ", ".join(types)
      )
      assert output_type in types, "Output must be a {}.".format(
          ", ".join(types)
      )
  
      if type(input_text) == str:
          punkt = PunktLanguageVars()
          tokens = punkt.word_tokenize(input_text)
          new_tokens = []
          for word in tokens:
              if word.endswith("."):
                  new_tokens.append(word[:-1])
                  new_tokens.append(".")
              else:
                  new_tokens.append(word)
          input_text = new_tokens
  
      ner_file_path = os.path.expanduser(NER_DICT[lang])
      with open(ner_file_path) as file_open:
          ner_str = file_open.read()
      ner_list = ner_str.split("\n")
  
      ner_tuple_list = []
      for count, word_token in enumerate(input_text):
          match = False
          for ner_word in ner_list:
              # the replacer slows things down, but is necessary
              if word_token == ner_word:
                  ner_tuple = (word_token, "Entity")
                  ner_tuple_list.append(ner_tuple)
                  match = True
                  break
          if not match:
              ner_tuple_list.append((word_token,))
  
      if output_type is str:
          string = ""
          for tup in ner_tuple_list:
              start_space = " "
              final_space = ""
              # this is some mediocre string reconstitution
              # maybe not worth the effort
              if tup[0] in [",", ".", ";", ":", "?", "!"]:
                  start_space = ""
              if len(tup) == 2:
                  string += (
                      start_space + tup[0] + "/" + tup[1] + final_space
                  )
              else:
                  string += start_space + tup[0] + final_space
          return string
  
      return ner_tuple_list
  
file_path: cltk/src/cltk/tag/ner.py
imports: import importlib.machinery
  import os
  from nltk.tokenize.punkt import PunktLanguageVars
  from cltk.data.fetch import FetchCorpus
  from cltk.tokenizers.word import PunktWordTokenizer
  from cltk.utils import CLTK_DATA_DIR
label_desc: Use image node_id 2 for calling a global function with example usage: tag_ner(lang, input_text, output_type) and returns: ner_tuple_list, string