Files
VKR_2026/modules/NER.py
2026-04-23 20:39:47 +05:00

25 lines
791 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 1 модуль - Распознавание именованных сущностей (NER)
import spacy
class NER:
"""
Класс для выделения именованных сущностей из текста с помощью библиотеки spaCy.
"""
def __init__(self):
self.nlp = spacy.load('ru_core_news_lg')
def extract_entities(self, text):
"""
Выделение именованных сущностей из текста.
Использование: text (<текст>)
Возвращает set сущностей без повторения
"""
doc = self.nlp(text)
entities = set()
for ent in doc.ents:
entities.add(ent.text)
return entities