Exercise

Lexical attributes

In this example, you'll use spaCy's Doc and Token objects, and lexical attributes to find percentages in a text. You'll be looking for two subsequent tokens: a number and a percent sign. The English nlp object has already been created.

Instructions

100 XP
  • Use the like_num token attribute to check whether a token in the doc resembles a number.
  • Get the token following the current token in the document. The index of the next token in the doc is token.i + 1.
  • Check whether the next token's text attribute is a percent sign "%".