title: Longest match only with Spacy Phrasematcher
body: <p>I have created a <a href="https://spacy.io/api/phrasematcher" rel="nofollow noreferrer">Spacy Phrasematcher</a> to match names in a document, following the <a href="https://spacy.io/usage/rule-based-matching#phrasematcher" rel="nofollow noreferrer">tutorial</a>. I want to use the resulting matches as additional training data in order to train a Spacy NER model.
  My patterns, however, contain both full names (e.g. 'Barack Obama') and last names ('Obama') separately.</p>
  
  <p>Hence, in a sentence that contains 'Barack Obama', both patterns match, resulting in overlapping matches. This overlap, however, triggers an exception when I try to use the data for training, e.g.:</p>
  
  <pre><code>ValueError: [E103] Trying to set conflicting doc.ents: '(19, 33, 'PERSON')' and '(29, 33, 'PERSON')'. A token can only be part of one entity, so make sure the entities you're setting don't overlap.
  </code></pre>
  
  <p>I've been considering to filter out overlapping matches before using the data for training, but this seems like a very inefficient approach, resulting in a significant increase in processing time for large data.</p>
  
  <p>Is there a way to set up a <code>PhraseMatcher</code> so that it only matches the longest match for overlapping matches?</p>