ΠΠ°ΡΠ° ΡΠ°Π±ΠΎΡΡ ΡΡΠ»ΠΎΠ²Π½Π°Ρ. Π½ΡΠΆΠ½ΠΎ ΠΎΠ±ΡΠ΅Π΄ΠΈΠ½ΠΈΡΡ 2 ΠΊΠΎΠ΄Π° Π² ΠΎΠ΄ΠΈΠ½. ΠΠΎΡΠ°Π±ΠΎΡΠΊΠ° ΡΡΡΠ΅ΡΡΠ²ΡΡΡΠ΅Π³ΠΎ ΠΏΡΠΎΠ΄ΡΠΊΡΠ°. ΠΠ΅ΠΎΠ±Ρ
ΠΎΠ΄ΠΈΠΌΠΎ Π²ΡΠΏΠΎΠ»Π½ΠΈΡΡ Π»Π΅ΠΌΠΌΠ°ΡΠΈΠ·Π°ΡΠΈΡ ΡΡΡΡΠΊΠΎΠ³ΠΎ ΡΠ΅ΠΊΡΡΠ°. ΠΠ΄Π½Π°ΠΊΠΎ pymorphy2 Π±ΠΎΠ»ΡΡΠ΅ Π½Π΅ ΠΏΠΎΠ΄Π΄Π΅ΡΠΆΠΈΠ²Π°Π΅ΡΡΡ Π΄Π»Ρ python 3.11. ΠΡΡΡ “ΠΊΠΎΡΡΡΠ»Ρ“, Ρ ΠΏΠΎΠΌΠΎΡΡΡ ΠΊΠΎΡΠΎΡΠΎΠ³ΠΎ ΠΌΠΎΠΆΠ½ΠΎ Π²ΡΠΏΠΎΠ»Π½ΠΈΡΡ Π»Π΅ΠΌΠΌΠ°ΡΠΈΠ·Π°ΡΠΈΡ ΡΠ΅ΠΊΡΡΠ°. ΠΠ³ΠΎ Π½Π΅ΠΎΠ±Ρ
ΠΎΠ΄ΠΈΠΌΠΎ Π²ΡΡΠ°Π²ΠΈΡΡ Π² ΡΠΆΠ΅ ΡΡΡΠ΅ΡΡΠ²ΡΡΡΠΈΠΉ ΠΊΠΎΠ΄, Π΅ΡΠ»ΠΈ ΡΡΠΎ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ. ΠΠΎΠ΄: import nltk import sys import string from nltk.tokenize import word_tokenize from nltk.corpus import stopwords from nltk.stem import WordNetLemmatizer from textblob import TextBlob from PyQt5.QtWidgets import* class NLTK_Calculator(QMainWindow): def __init__(self): self.text=““ super().__init__() self.init_ui() def init_ui(self): self.setWindowTitle('Text analysis') self.setGeometry(200,200,1000,500) self.open_button=QPushButton(“Open“,self) self.open_button.setGeometry(10,10,150,30) self.open_button.clicked.connect(self.open_file) self.calculate_informativeness_button1=QPushButton(“ΠΠ½ΡΠΎΡΠΌΠ°ΡΠΈΠ²Π½ΠΎΡΡΡ“,self) self.calculate_informativeness_button1.setGeometry(10,110,360,30) self.calculate_informativeness_button1.clicked.connect(self.display_informativeness1) last_button_y = 210 result_label_height = 30 result_label_y = last_button_y + result_label_height + 60 self.result_label = QLabel(““, self) self.result_label.setGeometry(60, result_label_y, 600, result_label_height) def preprocess_text_for_informativeness1(self, text): words = word_tokenize(text) stop_words = set(stopwords.words('russian')) words1 = [w.lower() for w in words if w.isalpha() and w.lower() not in stop_words] return words1 def calculate_informativeness1(self, text): words = word_tokenize(text) words1=[w.lower() for w in words if w.isalpha()] filtered_words = self.preprocess_text_for_informativeness1(text) informativeness1 = len(filtered_words) / len(words1) if len(words1) > 0 else 0 return informativeness1 def display_informativeness1(self): show_informativeness1 = self.calculate_informativeness1(self.text) self.result_label.setText(f“Informativeness1: {show_informativeness1:.8f}“) def open_file(self): file_path,_=QFileDialog.getOpenFileName(self,“Choose file“,““,“*.txt“) if file_path: with open(file_path,'r',encoding='utf-8',errors='ignore')as file: self.text=file.read() if __name__==“__main__“: app=QApplication(sys.argv) window=NLTK_Calculator() window.show() sys.exit(app.exec_()) ΠΠΎΡΡΡΠ»Ρ: def pymorphy2_311_hotfix(): from inspect import getfullargspec from pymorphy2.units.base import BaseAnalyzerUnit def _get_param_names_311(klass): if klass.__init__ is object.__init__: return [] args = getfullargspec(klass.__init__).args return sorted(args[1:]) setattr(BaseAnalyzerUnit, '_get_param_names', _get_param_names_311) pymorphy2_311_hotfix() # ΠΡΠ·ΡΠ²Π°Π΅ΠΌ ΠΈΡΠΏΡΠ°Π²Π»ΡΡΡΡΡ ΡΡΠ½ΠΊΡΠΈΡ Π·Π΄Π΅ΡΡ from pymorphy2 import MorphAnalyzer import pymorphy2 def pymorphy2_example(): morph = pymorphy2.MorphAnalyzer() # Π‘ΠΎΠ·Π΄Π°Π΅ΠΌ ΠΎΠ±ΡΠ΅ΠΊΡ MorphAnalyzer ΠΏΠΎΡΠ»Π΅ ΠΏΡΠΈΠΌΠ΅Π½Π΅Π½ΠΈΡ ΠΈΡΠΏΡΠ°Π²Π»Π΅Π½ΠΈΠΉ parse_result = morph.parse('Π»ΡΠΆΠ°') print(parse_result[0].normal_form) pymorphy2_example().