code: def add_token(token_list, word, token):
      """
      Add a token to a proto request.
  
      CoreNLP tokens have components of both word and token from stanza.
  
      We pass along "after" but not "before", and the "after" is limited
      to whether or not there is a space after the token
      """
      if token is None and isinstance(word.id, int):
          raise AssertionError(
              "Only expected word w/o token for 'extra' words"
          )
  
      query_token = token_list.add()
      query_token.word = word.text
      query_token.value = word.text
      if word.lemma is not None:
          query_token.lemma = word.lemma
      if word.xpos is not None:
          query_token.pos = word.xpos
      if word.upos is not None:
          query_token.coarseTag = word.upos
      if word.feats and word.feats != "_":
          for feature in word.feats.split("|"):
              key, value = feature.split("=", maxsplit=1)
              query_token.conllUFeatures.key.append(key)
              query_token.conllUFeatures.value.append(value)
      if token is not None:
          if token.ner is not None:
              query_token.ner = token.ner
          if token is not None and len(token.id) > 1:
              query_token.mwtText = token.text
              query_token.isMWT = True
              query_token.isFirstMWT = token.id[0] == word.id
          if token.id[-1] != word.id:
              # if we are not the last word of an MWT token
              # we are absolutely not followed by space
              pass
          else:
              space_after = misc_to_space_after(token.misc)
              if space_after == " ":
                  # in some treebanks, the word might have more interesting
                  # space after annotations than the token
                  space_after = misc_to_space_after(word.misc)
              query_token.after = space_after
  
          query_token.index = word.id
      else:
          # presumably empty words won't really be written this way,
          # but we can still keep track of it
          query_token.after = misc_to_space_after(word.misc)
  
          query_token.index = word.id[0]
          query_token.emptyIndex = word.id[1]
  
      if word.misc and word.misc != "_":
          query_token.conllUMisc = word.misc
      if token is not None and token.misc and token.misc != "_":
          query_token.mwtMisc = token.misc
  
imports: from collections import deque
  import subprocess
  from stanza.models.common.utils import misc_to_space_after
  from stanza.models.constituency.parse_tree import Tree
  from stanza.protobuf import DependencyGraph, FlattenedParseTree
  from stanza.server.client import resolve_classpath
label_desc: Use image node_id 5 for calling a global function with example usage: add_token(token_list, word, token) without return types