title: How to combine entity terms using Spacy EntityRuler NLP?
body: <p>I am working on using spacy for some NLP tasks, such as calculating entity frequency and PMI scores (relationship ranking between organization entities and lemmas). My corpus often has specific organizations with various permutations (e.g. Harman, HARMAN, Harman International...) that I want to always be recognized as one entity. This way, when counting frequencies they are all considered as one organization entity rather than separate, unique entities.</p>
  <p>I believe the spacy.pipeline.EntityRuler should be the way to edit and update the spacy module, but I am not getting the desired outcome. After running the below code, the entity list does not appear to get updated. I still am returning the various permutations of the organization as unique entities.</p>
  <p>I am not sure what I am doing wrong at this point, so any help is appreciated!</p>
  <p>Thank you.</p>
  <p>Code:</p>
  <pre><code>import spacy
  from spacy.pipeline import EntityRuler
  
  nlp = spacy.load('en_core_web_sm', disable = ['parser','tagger'])
  ruler = EntityRuler(nlp, overwrite_ents = True) #replace entities that may exist with the following
  patterns = [{&quot;label&quot;: &quot;ORG&quot;, &quot;pattern&quot;: [{&quot;TEXT&quot;:&quot;HARMAN&quot;}, {&quot;TEXT&quot;:&quot;International&quot;}], &quot;id&quot;: &quot;harman&quot;},
             {&quot;label&quot;: &quot;ORG&quot;, &quot;pattern&quot;: [{&quot;TEXT&quot;:&quot;HARMAN&quot;}], &quot;id&quot;: &quot;harman&quot;},
             {&quot;label&quot;: &quot;ORG&quot;, &quot;pattern&quot;: [{&quot;TEXT&quot;:&quot;Harman&quot;}], &quot;id&quot;: &quot;harman&quot;},
             {&quot;label&quot;: &quot;ORG&quot;, &quot;pattern&quot;: [{&quot;TEXT&quot;:&quot;Harman&quot;}, {&quot;TEXT&quot;:&quot;International&quot;}], &quot;id&quot;: &quot;harman&quot;}
             ] 
  ruler.add_patterns(patterns)
  nlp.add_pipe(ruler, before=&quot;ner&quot;)
  corpus_nlp = [nlp(corpus['Body'][i]) for i in corpus.index]
  
  corpus_nlp[49].ents
  </code></pre>
  <p><em>(Harman, Zinnov, HARMAN, the &quot;Leadership Zone)</em></p>