1. Learn
  2. /
  3. Courses
  4. /
  5. Natural Language Processing with spaCy

Connected

Exercise

Matching a single term in spaCy

RegEx patterns are not trivial to read, write and debug. But you are not at a loss, spaCy provides a readable and production-level alternative, the Matcher class. The Matcher class can match predefined rules to a sequence of tokens in a given Doc container. In this exercise, you will practice using Matcher to find a single word.

You can access the corresponding text in example_text and use nlp and doc to access an spaCy model and Doc container of example_text respectively.

Instructions

100 XP
  • Initialize a Matcher class.
  • Define a pattern to match lower cased witch in the example_text.
  • Add the patterns to the Matcher class and find matches.
  • Iterate through matches and print start and end token indices and span of the matched text.