Spaces:
No application file
No application file
Commit ·
364d102
1
Parent(s): 81c39c3
script que contém a Class para NER
Browse files
modules/entity_recognition.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Data Scientist.: PhD.Eddy Giusepe Chirinos Isidro
|
| 3 |
+
|
| 4 |
+
entity_recognition.py
|
| 5 |
+
=====================
|
| 6 |
+
Objetivo: Este script é um módulo que serve para o Reconhecimento
|
| 7 |
+
de Entidades Nomeadas (NER) através do uso de um modelo
|
| 8 |
+
pré-treinado do spaCy. Isto é construido numa classe do
|
| 9 |
+
Python.
|
| 10 |
+
|
| 11 |
+
Versão: 1.0.0
|
| 12 |
+
Data: 23/06/2023
|
| 13 |
+
Autor: Dr.Eddy Giusepe
|
| 14 |
+
"""
|
| 15 |
+
import spacy
|
| 16 |
+
|
| 17 |
+
class EntityRecognizer:
|
| 18 |
+
"""Está classe realiza a extração de Entidades Nomeadas."""
|
| 19 |
+
def __init__(self):
|
| 20 |
+
self.nlp = spacy.load("pt_core_news_lg") # pt_core_news_sm
|
| 21 |
+
|
| 22 |
+
def recognize_entities(self, text):
|
| 23 |
+
doc = self.nlp(text)
|
| 24 |
+
entities = []
|
| 25 |
+
|
| 26 |
+
for ent in doc.ents:
|
| 27 |
+
entities.append({
|
| 28 |
+
'text': ent.text,
|
| 29 |
+
'label': ent.label_
|
| 30 |
+
})
|
| 31 |
+
|
| 32 |
+
return entities
|