title: Truecasing - SpaCy
body: <p>Intent is to capitalize based on POS tags, which I could achieve with the help of the below link.</p>
  
  <p><a href="https://stackoverflow.com/questions/7706696/how-can-i-best-determine-the-correct-capitalization-for-a-word">How can I best determine the correct capitalization for a word?</a></p>
  
  <p>Trying to achieve similar results using spacy?</p>
  
  <pre><code>def truecase(doc):
      truecased_sents = [] # list of truecased sentences
      tagged_sent = token.tag_([word.lower() for token in doc])
      normalized_sent = [w.capitalize() if t in ["NN","NNS"] else w for (w,t) in tagged_sent]
      normalized_sent[0] = normalized_sent[0].capitalize()
      string = re.sub(" (?=[\.,'!?:;])", "", ' '.join(normalized_sent))
      return string
  </code></pre>
  
  <p>it throws out this error</p>
  
  <pre><code>  tagged_sent = token.tag_([word.lower() for token in doc])
  NameError: global name 'token' is not defined
  </code></pre>
  
  <p>how to declare token as global and solve this issue. Is my approach correct?</p>