(self)
return entities
Get named entities from the spaCy model for each text in the request dataframe.
Get named entities from the spaCy model for each text in the request dataframe.
Get named entities from the spaCy model for each text in the request dataframe .
def _entity_tagger(self):
        """
        Get named entities from the spaCy model for each text in the request dataframe.
        """

        # If this is a custom model, set the path to the directory
        if self.custom:
            self.model = self.path + self.model + "/"

        # Load the spaCy model
        try:
            nlp = spacy.load(self.model)
        except OSError:
            self.model = self.path + self.model + "/"
            nlp = spacy.load(self.model)
        
        # Create an empty list for storing named entities
        entities = []

        # Send each text to the model and save the named entities
        for i in range(len(self.request_df)):
            key = self.request_df.loc[i, 'key']
            doc = nlp(self.request_df.loc[i, 'text'])

            # Obtain entities, start and end characters, labels and descriptions    
            for ent in doc.ents:
                entities.append([key, ent.text, ent.start_char, ent.end_char, ent.label_, spacy.explain(ent.label_)])

        # Transform the entities list to a dataframe
        entities = pd.DataFrame(entities, columns=['key', 'entity', 'start', 'end', 'type', 'description'])
        
        return entities
def _entity_tagger ( self ) : # If this is a custom model, set the path to the directory if self . custom : self . model = self . path + self . model + "/" # Load the spaCy model try : nlp = spacy . load ( self . model ) except OSError : self . model = self . path + self . model + "/" nlp = spacy . load ( self . model ) # Create an empty list for storing named entities entities = [ ] # Send each text to the model and save the named entities for i in range ( len ( self . request_df ) ) : key = self . request_df . loc [ i , 'key' ] doc = nlp ( self . request_df . loc [ i , 'text' ] ) # Obtain entities, start and end characters, labels and descriptions     for ent in doc . ents : entities . append ( [ key , ent . text , ent . start_char , ent . end_char , ent . label_ , spacy . explain ( ent . label_ ) ] ) # Transform the entities list to a dataframe entities = pd . DataFrame ( entities , columns = [ 'key' , 'entity' , 'start' , 'end' , 'type' , 'description' ] ) return entities