-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
63 lines (54 loc) · 1.52 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
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include "Model/Model.h"
#include "Preprocessing/Preprocessing.h"
#include <string>
#include <QFileDialog>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
QString email = ui->plainTextEdit->toPlainText();
int shape[2]= {1,3000};
auto* model = new Apollo::Model(shape, false);
model->loadModel("E:/Learning-E/Apollo-backend/Models/spam-100.csv");
model->compile();
Eigen::MatrixXd emailMatrix = Apollo::Preprocessing::spamPreprocessing(email.toStdString());
Eigen::MatrixXd pred = model->predict(emailMatrix);
double predVal = pred.sum();
if(predVal>0.3){
ui->label->setText("Spam " + QString::number(predVal));
}else{
ui->label->setText("Not Spam " + QString::number(predVal));
}
delete model;
}
void MainWindow::on_pushButton_2_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File")," ",tr("Text Files (*.txt)"));
std::string filePath = fileName.toStdString();
// start code here
ifstream File;
File.open(filePath);
std::string email;
std::string s;
while(getline(File,s)){
email+=s;
email+="\n";
}
ui->plainTextEdit->setPlainText(QString::fromStdString(email));
}
void MainWindow::on_pushButton_3_clicked()
{
// hide();
trainWindow = new TrainModel(this);
trainWindow->exec();
}