Session Ready
Exercise

Extracting countries and relationships

In the previous exercise, you wrote a script using spaCy's PhraseMatcher to find country names in text. Let's use that country matcher on a longer text, analyze the syntax and update the document's entities with the matched countries. The nlp object has already been created.

The text is available as the variable text, the PhraseMatcher with the country patterns as the variable matcher. The Span class has already been imported.

Instructions 1/2
undefined XP
  • 1
  • 2
  • Iterate over the matches and create a Span with the label "GPE" (geopolitical entity).
  • Overwrite the entities in doc.ents and add the matched span.