-
Notifications
You must be signed in to change notification settings - Fork 7
/
stage_text_processor.py
185 lines (147 loc) · 7.2 KB
/
stage_text_processor.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import pymorphy2
from matplotlib import rc
from sources.TextClassificationLib import DialogClassificationLib
from sources.utils import *
# Для корректного отображение шрифтов на графиках в Windows
if(os.name != 'posix'):
font = {'family': 'Verdana',
'weight': 'normal'}
rc('font', **font)
configurations = readConfigurationFile("configuration.cfg")
input_dir = configurations.get("input_files_directory", "input_files") + "/"
output_dir = configurations.get("output_files_directory", "output_files") + "/"
stop_words_filename = configurations.get("stop_words_file", "sources/russian_stop_words.txt")
from PyQt5.QtWidgets import QMainWindow, QSizePolicy, QSpacerItem, QFileDialog, QPushButton
from sources.XiSquare import *
from sources.TextClasterization import *
from sources.TextClassification import *
from sources.TextClastering import *
from sources.TextLSA import *
from sources.TextDecomposeAndRuleApply import *
from sources.AnnotationMaker import *
if not os.path.exists(input_dir):
os.makedirs(input_dir)
if not os.path.exists(output_dir):
os.makedirs(output_dir)
# Получаем экземпляр анализатора (10-20мб)
morph = pymorphy2.MorphAnalyzer()
# Класс главного окна
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
self.texts = []
def initUI(self):
button_clasterization = QPushButton("Кластеризация")
button_clasterization.setMinimumHeight(32)
button_clasterization.clicked.connect(self.clasterization)
button_clastering = QPushButton("Кластеризация (LIB)")
button_clastering.setMinimumHeight(32)
button_clastering.clicked.connect(self.clastering)
button_classification = QPushButton("Классификация")
button_classification.setMinimumHeight(32)
button_classification.clicked.connect(self.classification)
button_classification_lib = QPushButton("Классификация (LIB)")
button_classification_lib.setMinimumHeight(32)
button_classification_lib.clicked.connect(self.classification_lib)
button_lsa = QPushButton("Латентно-семантический анализ")
button_lsa.setMinimumHeight(32)
button_lsa.clicked.connect(self.makeLSA)
button_analyze_and_rule_apply = QPushButton("Анализ и правила вывода предложений")
button_analyze_and_rule_apply.setMinimumHeight(32)
button_analyze_and_rule_apply.clicked.connect(self.analyze_and_rule_apply)
button_xi_square = QPushButton("Рассчет критериев для выделения термов")
button_xi_square.setMinimumHeight(32)
button_xi_square.clicked.connect(self.makeXiSquare)
button_annotation = QPushButton("Создание аннотации документа")
button_annotation.setMinimumHeight(32)
button_annotation.clicked.connect(self.makeTextAnnotation)
#button_annotation.setEnabled(False)
spacer = QSpacerItem(20,40,QSizePolicy.Minimum,QSizePolicy.Expanding)
vbox = QVBoxLayout()
vbox.addWidget(button_clasterization)
vbox.addWidget(button_clastering)
vbox.addWidget(button_classification)
vbox.addWidget(button_classification_lib)
vbox.addWidget(button_lsa)
vbox.addWidget(button_analyze_and_rule_apply)
vbox.addWidget(button_xi_square)
vbox.addWidget(button_annotation)
vbox.addItem(spacer)
widget = QWidget();
widget.setLayout(vbox);
self.setCentralWidget(widget);
self.setGeometry(300, 300, 480, 320)
self.setWindowTitle('Этапный текстовый процессор')
self.show()
def clasterization(self):
print("Кластеризация")
filenames = getFilenamesFromUserSelection(input_dir + 'clasterization')
if(filenames != None):
dialogConfigClasterization = DialogConfigClasterization(filenames, morph, configurations, self)
self.hide()
dialogConfigClasterization.destroyed.connect(self.show)
dialogConfigClasterization.exec_()
def clastering(self):
print("Кластеризация (LIB)")
filenames = getFilenamesFromUserSelection(input_dir + 'clasterization')
if(filenames != None):
dialogConfigClastering = DialogClastering(filenames, morph, configurations, self)
self.hide()
dialogConfigClastering.destroyed.connect(self.show)
dialogConfigClastering.exec_()
def classification(self):
print("Классификация")
dirname = getDirFromUserSelection(input_dir + 'classification')
if(dirname != None):
dialogConfigClassification = DialogConfigClassification(dirname, morph, configurations, self)
self.hide()
dialogConfigClassification.destroyed.connect(self.show)
dialogConfigClassification.exec_()
def classification_lib(self):
print("Классификация (LIB)")
dirname = getDirFromUserSelection(input_dir + 'classification')
if(dirname != None):
dialogClassificationLib = DialogClassificationLib(dirname, morph, configurations, self)
self.hide()
dialogClassificationLib.destroyed.connect(self.show)
dialogClassificationLib.exec_()
def makeLSA(self):
print("LSA")
filenames = getFilenamesFromUserSelection(input_dir)
if(filenames != None):
dialogConfigLSA = DialogConfigLSA(filenames, morph, configurations, self)
self.hide()
dialogConfigLSA.destroyed.connect(self.show)
dialogConfigLSA.exec_()
def analyze_and_rule_apply(self):
print("Анализ и применение правил вывода")
filenames = getFilenamesFromUserSelection()
if(filenames != None):
dialogConfigDRA = DialogConfigDRA(filenames, morph, configurations, self)
self.hide()
dialogConfigDRA.destroyed.connect(self.show)
dialogConfigDRA.exec_()
def makeXiSquare(self):
print("Рассчет критериев для выделения термов")
filename = getFilenameFromUserSelection("CSV Files (*.csv)", input_dir)
if(filename != None):
dialogXiSquare = DialogXiSquare(filename, morph, configurations, self)
self.hide()
dialogXiSquare.destroyed.connect(self.show)
dialogXiSquare.exec_()
def makeTextAnnotation(self):
print("Аннотирование текста")
filename = getFilenameFromUserSelection("Text file (*.txt)", input_dir)
if (filename != None):
dialogAnnotationMaker = DialogAnnotationMaker(filename, morph, configurations, self)
self.hide()
dialogAnnotationMaker.destroyed.connect(self.show)
dialogAnnotationMaker.exec_()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MainWindow()
sys.exit(app.exec_())