New We are sorting MAX channels into categories and territories. Read the news

Поиск и работа с именами собственными в текстах.



Пример кода на Python с использованием spaCy для выделения имен собственных.

import spacy

# Загрузка многоязычной модели для spaCy
nlp = spacy.load("xx_ent_wiki_sm")

# Текст для анализа
text = "Иван и Марья Ивановна были в парке. Петр и Ирина пошли в магазин."

# Применяем spaCy для анализа текста
doc = nlp(text)

# Выделяем имена собственные (на основе модели NER)
persons = []

for ent in doc.ents:
if ent.label_ == "PERSON":
persons.append(ent.text)

# Выводим имена собственные
print("Найденные имена собственные:", persons)

================
Поиск имен собственных с использованием pymorphy3

import pandas as pd
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.metrics.pairwise import cosine_similarity
import nltk
from nltk.corpus import stopwords
import pymorphy3
from wordcloud import WordCloud
import matplotlib.pyplot as plt

# Загрузка стоп-слов для русского языка
nltk.download('stopwords')
russian_stopwords = stopwords.words('russian')

# Чтение файла
with open(path_to_text_file, 'r', encoding='utf-8') as file:
text_data = file.readlines()

# Объединение текста в один большой текст для анализа
full_text = ' '.join(text_data)

# Создание экземпляра морфологического анализатора
morph = pymorphy3.MorphAnalyzer()

# Разделение текста на слова
words = full_text.split()

# Поиск имен собственных с использованием pymorphy3
proper_nouns = set()
for word in words:
parsed_word = morph.parse(word)[0]
if 'Name' in parsed_word.tag: # Проверка, является ли слово именем собственным
proper_nouns.add(word)

# Выводим найденные имена собственные таблицей
proper_nouns_df = pd.DataFrame(list(proper_nouns), columns=["Имена собственные"])
print("\nНайденные имена собственные:")
print(proper_nouns_df)
Views: 6
Open in MAX Report an inaccuracy

Report an inaccuracy

Describe what needs fixing. If you have a source, add a link.

You are leaving datool.ru

The link leads to an external website. datool.ru is not responsible for its content — check the address before entering passwords or payment details.

Redirecting in 10 s

Go