-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathhypothesismodel.cpp
More file actions
133 lines (122 loc) · 3.98 KB
/
Copy pathhypothesismodel.cpp
File metadata and controls
133 lines (122 loc) · 3.98 KB
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
#include "hypothesismodel.h"
hypothesismodel::hypothesismodel(QList<CHypothesis*> * hypotheses) {
m_hypotheses = hypotheses;
}
int hypothesismodel::rowCount(const QModelIndex &parent )const {
Q_UNUSED(parent);
return m_hypotheses->count();
}
int hypothesismodel::columnCount(const QModelIndex &parent )const {
Q_UNUSED(parent);
return m_hypotheses->count();
}
QVariant hypothesismodel::data(const QModelIndex & index, int role )const {
if (!index.isValid())
return QVariant();
int row = index.row();
int column = index.column();
CHypothesis* hypothesis(m_hypotheses->at(row));
if (row > m_hypotheses->count()){ return QVariant();}
switch (column) {
case 0:
if (role==Qt::DisplayRole){
return QVariant(hypothesis->get_morpheme());
}
break;
case 1:{
if (role==Qt::DisplayRole){
return QVariant ("=>");
}
break;
}
case 2:{
if (role==Qt::DisplayRole){
return QVariant(hypothesis->get_sig1());
}
break;
}
case 3:{
if (role==Qt::DisplayRole){
return QVariant(hypothesis->get_sig2());
}
break;
}
case 4:{
if (role==Qt::DisplayRole){
return QVariant(hypothesis->get_number_of_words_saved());
}
break;
}
default:
return QVariant();
}
return QVariant();
}
QModelIndex hypothesismodel::index(int row, int column, const QModelIndex &parent ) const {
Q_UNUSED(parent);
return createIndex(row, column, nullptr);
}
QModelIndex hypothesismodel::parent(const QModelIndex &index) const {
Q_UNUSED(index);
return QModelIndex();
}
QVariant hypothesismodel::headerData(int section, Qt::Orientation orientation, int role) const {
if (role != Qt::DisplayRole) {return QVariant();}
if (orientation == Qt::Horizontal){
if (section == 0) return QVariant("Hypothesis" );
/*
if (section == 1) return QVariant("stem count");
if (section == 2) return QVariant("robustness");
if (section == 3) return QVariant("fullness");
if (section == 4) return QVariant("# affixes");
*/
}
return QVariant();
}
bool less_than_affix(CHypothesis* hypothesis1, CHypothesis* hypothesis2){
return hypothesis1->get_morpheme() < hypothesis2->get_morpheme();
}
bool greater_than_affix(CHypothesis* hypothesis1, CHypothesis* hypothesis2){
return hypothesis1->get_morpheme() > hypothesis2->get_morpheme();
}
bool less_than_sig1(CHypothesis* hypothesis1, CHypothesis* hypothesis2){
return hypothesis1->get_sig1() < hypothesis2->get_sig1();
}
bool greater_than_sig1(CHypothesis* hypothesis1, CHypothesis* hypothesis2){
return hypothesis1->get_sig1() > hypothesis2->get_sig1();
}
bool less_than_sig2(CHypothesis* hypothesis1, CHypothesis* hypothesis2){
return hypothesis1->get_sig2() < hypothesis2->get_sig2();
}
bool greater_than_sig2(CHypothesis* hypothesis1, CHypothesis* hypothesis2){
return hypothesis1->get_sig2() > hypothesis2->get_sig2();
}
void hypothesismodel::sort(int column, Qt::SortOrder order ) {
switch (column){
case 0:{
if (order == Qt::AscendingOrder){
std::sort(m_hypotheses->begin(), m_hypotheses->end(), less_than_affix);
} else{
std::sort(m_hypotheses->begin(), m_hypotheses->end(), greater_than_affix);
}
break;
}
case 2:{
if (order == Qt::AscendingOrder){
std::sort(m_hypotheses->begin(), m_hypotheses->end(), less_than_sig1);
} else{
std::sort(m_hypotheses->begin(), m_hypotheses->end(), greater_than_sig1);
}
break;
}
case 3:{
if (order == Qt::AscendingOrder){
std::sort(m_hypotheses->begin(), m_hypotheses->end(), less_than_sig2);
} else{
std::sort(m_hypotheses->begin(), m_hypotheses->end(), greater_than_sig2);
}
break;
}
}
emit layoutChanged();
};