File size: 1,158 Bytes
b514fe8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3

"""
Data Scientist.: Dr.Eddy Giusepe Chirinos Isidro
"""
import spacy
import logging

# Configurando o logging
logging.basicConfig(level=logging.INFO)

class EntityRecognizer:
    """
    Classe para reconhecimento de entidades usando a biblioteca Spacy.
    """
    def __init__(self):
        """
        Inicializa a classe com o texto a ser analisado.
        """
        self.nlp = spacy.load('pt_core_news_sm')

    def recognize(self, text):
        """
        Reconhece as entidades no texto.
        """
        doc = self.nlp(text)

        entities ={}
        # Verifica se existem entidades no texto
        if doc.ents:
            logging.info('Entidades encontradas:')
            for ent in doc.ents:
                entities[ent.text] = ent.label_
               
        else:
            logging.info('Nenhuma entidade encontrada.')
            print("O texto não contém Entidades 🤗!")

        return entities


if __name__ == "__main__":
    # Exemplo de uso:
    recognizer = EntityRecognizer()
    text = 'A Karina é cientista de dados!'
    entidades =  recognizer.recognize(text)
    print(entidades)