code: def parsePrimitiveCategory(chunks, primitives, families, var):
      """
      Parse a primitive category
  
      If the primitive is the special category 'var', replace it with the
      correct `CCGVar`.
      """
      if chunks[0] == "var":
          if chunks[1] is None:
              if var is None:
                  var = CCGVar()
              return (var, var)
  
      catstr = chunks[0]
      if catstr in families:
          (cat, cvar) = families[catstr]
          if var is None:
              var = cvar
          else:
              cat = cat.substitute([(cvar, var)])
          return (cat, var)
  
      if catstr in primitives:
          subscrs = parseSubscripts(chunks[1])
          return (PrimitiveCategory(catstr, subscrs), var)
      raise AssertionError(
          "String '"
          + catstr
          + "' is neither a family nor primitive category."
      )
  
imports: import re
  from collections import defaultdict
  from nltk.ccg.api import CCGVar, Direction, FunctionalCategory, PrimitiveCategory
  from nltk.internals import deprecated
  from nltk.sem.logic import Expression
label_desc: Use image node_id 5 for calling a global function with example usage: parsePrimitiveCategory(chunks, primitives, families, var) and returns: cat,  var, PrimitiveCategory,  var, var,  var