def __call__(self, doc):
matches = list(self.matcher(doc)) + list(self.phrase_matcher(doc))<EOL>matches = set(<EOL>[(m_id, start, end) for m_id, start, end in matches if start != end]<EOL>)<EOL>get_sort_key = lambda m: (m[<NUM_LIT:2>] - m[<NUM_LIT:1>], m[<NUM_LIT:1>])<EOL>matches = sorted(matches, key=get_sort_key, reverse=True)<EOL>entities = list(doc.ents)<EOL>new_entities = []<EOL>seen_tokens = set()<EOL>for match_id, start, end in matches:<EOL><INDENT>if any(t.ent_type for t in doc[start:end]) and not self.overwrite:<EOL><INDENT>continue<EOL><DEDENT>if start not in seen_tokens and end - <NUM_LIT:1> not in seen_tokens:<EOL><INDENT>new_entities.append(Span(doc, start, end, label=match_id))<EOL>entities = [<EOL>e for e in entities if not (e.start < end and e.end > start)<EOL>]<EOL>seen_tokens.update(range(start, end))<EOL><DEDENT><DEDENT>doc.ents = entities + new_entities<EOL>return doc<EOL>
Find matches in document and add them as entities.

        doc (Doc): The Doc object in the pipeline.
        RETURNS (Doc): The Doc with added entities, if available.

        DOCS: https://spacy.io/api/entityruler#call