def __call__(self, doc):
        """Apply the pipeline component on a Doc object and modify it if matches
        are found. Return the Doc, so it can be processed by the next component
        in the pipeline, if available.
        """
        matches = self.matcher(doc)
        spans = []  # keep the spans for later so we can merge them afterwards
        for _, start, end in matches:
            # Generate Span representing the entity & set label
            entity = Span(doc, start, end, label=self.label)
            spans.append(entity)
            # Set custom attribute on each token of the entity
            # Can be extended with other data returned by the API, like
            # currencies, country code, flag, calling code etc.
            for token in entity:
                token._.set("is_country", True)
                token._.set("country_capital", self.countries[entity.text]["capital"])
                token._.set("country_latlng", self.countries[entity.text]["latlng"])
                token._.set("country_flag", self.countries[entity.text]["flag"])
            # Overwrite doc.ents and add entity – be careful not to replace!
            doc.ents = list(doc.ents) + [entity]
        for span in spans:
            # Iterate over all spans and merge them into one token. This is done
            # after setting the entities – otherwise, it would cause mismatched
            # indices!
            span.merge()
        return doc
def __call__ ( self , doc ) : matches = self . matcher ( doc ) spans = [ ] for _ , start , end in matches : entity = Span ( doc , start , end , label = self . label ) spans . append ( entity ) for token in entity : token . _ . set ( "is_country" , True ) token . _ . set ( "country_capital" , self . countries [ entity . text ] [ "capital" ] ) token . _ . set ( "country_latlng" , self . countries [ entity . text ] [ "latlng" ] ) token . _ . set ( "country_flag" , self . countries [ entity . text ] [ "flag" ] ) doc . ents = list ( doc . ents ) + [ entity ] for span in spans : span . merge ( ) return doc
Apply the pipeline component on a Doc object and modify it if matches
        are found. Return the Doc, so it can be processed by the next component
        in the pipeline, if available.