-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
294 lines (229 loc) · 7.93 KB
/
mainwindow.cpp
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include <QFileDialog>
#include <QDebug>
#include <iostream>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
QString grand_array[5];
int FUNCTION_5(QStringList array, QString mostFrequentElement, int highestFrequency) {
QString findMostFrequentElement(const QStringList& array);
QMap<QString, int> frequencyMap;
for (const QString& element : array) {
frequencyMap[element]++;
}
highestFrequency = 0;
for (const QString& element : frequencyMap.keys()) {
if (frequencyMap[element] > highestFrequency) {
mostFrequentElement = element;
highestFrequency = frequencyMap[element];
}
}
//std::cout << "A leggyakoribb elem: " << mostFrequentElement.toStdString() << std::endl;
grand_array[4] = mostFrequentElement;
return 0;
}
void ranked_function_4(QStringList array_4, QStringList array_5, QString mostFrequentElement, int highestFrequency) {
for (int i = 0; i < highestFrequency; ++i){
qsizetype var = array_4.indexOf(mostFrequentElement);
array_4.remove(var);
}
array_5 = array_4;
FUNCTION_5(array_5, mostFrequentElement, highestFrequency);
}
int FUNCTION_4(QStringList array_4, QString mostFrequentElement, int highestFrequency) {
QString findMostFrequentElement(const QStringList& array);
QMap<QString, int> frequencyMap;
for (const QString& element : array_4) {
frequencyMap[element]++;
}
highestFrequency = 0;
for (const QString& element : frequencyMap.keys()) {
if (frequencyMap[element] > highestFrequency) {
mostFrequentElement = element;
highestFrequency = frequencyMap[element];
}
}
//std::cout << "A leggyakoribb elem: " << mostFrequentElement.toStdString() << std::endl;
grand_array[3] = mostFrequentElement;
QStringList array_5;
ranked_function_4(array_4, array_5, mostFrequentElement, highestFrequency);
return 0;
}
void ranked_function_3(QStringList array_3, QStringList array_4, QString mostFrequentElement, int highestFrequency) {
for (int i = 0; i < highestFrequency; ++i){
qsizetype var = array_3.indexOf(mostFrequentElement);
array_3.remove(var);
}
array_4 = array_3;
FUNCTION_4(array_4, mostFrequentElement, highestFrequency);
}
int FUNCTION_3(QStringList array_3, QString mostFrequentElement, int highestFrequency) {
QString findMostFrequentElement(const QStringList& array);
QMap<QString, int> frequencyMap;
for (const QString& element : array_3) {
frequencyMap[element]++;
}
highestFrequency = 0;
for (const QString& element : frequencyMap.keys()) {
if (frequencyMap[element] > highestFrequency) {
mostFrequentElement = element;
highestFrequency = frequencyMap[element];
}
}
//std::cout << "A leggyakoribb elem: " << mostFrequentElement.toStdString() << std::endl;
grand_array[2] = mostFrequentElement;
QStringList array_4;
ranked_function_3(array_3, array_4, mostFrequentElement, highestFrequency);
return 0;
}
void ranked_function_2(QStringList array_2, QStringList array_3, QString mostFrequentElement, int highestFrequency) {
for (int i = 0; i < highestFrequency; ++i){
qsizetype var = array_2.indexOf(mostFrequentElement);
array_2.remove(var);
}
array_3 = array_2;
FUNCTION_3(array_3, mostFrequentElement, highestFrequency);
}
int FUNCTION_2(QStringList array_2, QString mostFrequentElement, int highestFrequency) {
QString findMostFrequentElement(const QStringList& array);
QMap<QString, int> frequencyMap;
for (const QString& element : array_2) {
frequencyMap[element]++;
}
highestFrequency = 0;
for (const QString& element : frequencyMap.keys()) {
if (frequencyMap[element] > highestFrequency) {
mostFrequentElement = element;
highestFrequency = frequencyMap[element];
}
}
//std::cout << "A leggyakoribb elem: " << mostFrequentElement.toStdString() << std::endl;
grand_array[1] = mostFrequentElement;
QStringList array_3;
ranked_function_2(array_2, array_3, mostFrequentElement, highestFrequency);
return 0;
}
void ranked_function(QStringList array, QStringList array_2, QString mostFrequentElement, int highestFrequency) {
for (int i = 0; i < highestFrequency; ++i){
qsizetype var = array.indexOf(mostFrequentElement);
array.remove(var);
}
array_2 = array;
FUNCTION_2(array_2, mostFrequentElement, highestFrequency);
}
int wordcount;
int FUNCTION(QStringList array, QString mostFrequentElement, int highestFrequency) {
wordcount = array.length();
QString findMostFrequentElement(const QStringList& array);
QMap<QString, int> frequencyMap;
for (const QString& element : array) {
frequencyMap[element]++;
}
highestFrequency = 0;
for (const QString& element : frequencyMap.keys()) {
if (frequencyMap[element] > highestFrequency) {
mostFrequentElement = element;
highestFrequency = frequencyMap[element];
}
}
//std::cout << "A leggyakoribb elem: " << mostFrequentElement.toStdString() << std::endl;
grand_array[0] = mostFrequentElement;
QStringList array_2;
ranked_function(array, array_2, mostFrequentElement, highestFrequency);
return 0;
}
QString text;
int all_counter;
int h_counter;
void MainWindow::on_pushButton_clicked()
{
all_counter=0;
h_counter=0;
QString my_a("á");
QString my_o("ó");
QString my_u("ú");
QString my_e("é");
QString my_i("í");
QString my_o_1("ö");
QString my_o_2("ő");
QString my_u_1("ü");
QString my_u_2("ű");
text = ui->textEdit->toPlainText();
QStringList szavak = text.split(" ");
QStringList array;
QString mostFrequentElement;
int highestFrequency = 0;
for (int i = 0; i < szavak.size(); ++i) {
//std::cout << szavak.at(i).toStdString() << std::endl;
array.push_back(szavak[i]);
}
/*
for (int i = 0; i < array.size(); ++i) {
std::cout << array.at(i).toStdString() <<std::endl;
}
*/
FUNCTION(array, mostFrequentElement, highestFrequency);
for (int i = 0; i < text.length(); ++i) {
//printf("%d\n", i);
if(text.at(i) == 'a'){
all_counter++;
h_counter++;
}
if(text.at(i) == my_a){
all_counter++;
h_counter++;
}
if(text.at(i) == 'o'){
all_counter++;
h_counter++;
}
if(text.at(i) == my_o){
all_counter++;
h_counter++;
}
if(text.at(i) == 'u'){
all_counter++;
h_counter++;
}
if(text.at(i) == my_u){
all_counter++;
h_counter++;
}
if(text.at(i) == 'e' || text.at(i) == my_e || text.at(i) == 'i' || text.at(i) == my_i || text.at(i) == my_o_1 || text.at(i) == my_o_2 || text.at(i) == my_u_1 || text.at(i) == my_u_2){
all_counter++;
}
ui->lineEdit->setText(QVariant(i+1).toString());
ui->lineEdit_2->setText(QVariant(all_counter).toString());
ui->lineEdit_3->setText(QVariant(h_counter).toString());
ui->lineEdit_5->setText(QVariant(all_counter-h_counter).toString());
}
ui->textEdit_2->setText(grand_array[0]+'\n'+grand_array[1]+'\n'+grand_array[2]+'\n'+grand_array[3]+'\n'+grand_array[4]);
ui->lineEdit_4->setText(QVariant(wordcount).toString());
}
void MainWindow::on_actionF_jl_megnyit_sa_2_triggered()
{
QFileDialog dialog;
dialog.setFileMode(QFileDialog::ExistingFile);
dialog.setWindowTitle("Szöveges dokumentum betöltése");
if (dialog.exec()) {
QString filename = dialog.selectedFiles().first();
QFile file(filename);
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream in(&file);
QString text = in.readAll();
ui->textEdit->setText(text);
ui->textEdit->setReadOnly(true);
} else {
qWarning() << "Nem sikerült megnyitni a fájlt: " << filename;
}
}
}