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

Exercise

Matching with extended syntax in spaCy

Rule-based information extraction is essential for any NLP pipeline. The Matcher class allows patterns to be more expressive by allowing some operators inside the curly brackets. These operators are for extended comparison and look similar to Python's in, not in and comparison operators. In this exercise, you will practice with spaCy's matching functionality, Matcher, to find matches for given terms from an example text.

Matcher class is already imported from spacy.matcher library. You will use a Doc container of an example text in this exercise by calling doc. A pre-loaded spaCy model is also accessible at nlp.

Instructions

100 XP
  • Define a matcher object using Matcher and nlp.
  • Use the IN operator to define a pattern to match tiny squares and tiny mouthful.
  • Use this pattern to find matches for doc.
  • Print start and end token indices and text span of the matches.