1 /*
2  ner_leaderboard_model.cpp     MindForger thinking notebook
3 
4  Copyright (C) 2016-2020 Martin Dvorak <martin.dvorak@mindforger.com>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  as published by the Free Software Foundation; either version 2
9  of the License, or (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #include "ner_leaderboard_model.h"
20 
21 namespace m8r {
22 
23 using namespace std;
24 
NerLeaderboardModel(QWidget * parent)25 NerLeaderboardModel::NerLeaderboardModel(QWidget* parent)
26     : QStandardItemModel(parent)
27 {
28     setColumnCount(3);
29     setRowCount(0);
30 }
31 
~NerLeaderboardModel()32 NerLeaderboardModel::~NerLeaderboardModel()
33 {
34 }
35 
removeAllRows()36 void NerLeaderboardModel::removeAllRows()
37 {
38     QStandardItemModel::clear();
39 
40     QStringList tableHeader;
41     tableHeader
42         << tr("Name")
43         << tr("Type")
44         << tr("Score");
45 
46     // IMPROVE set tooltips: items w/ tooltips instead of just strings
47     setHorizontalHeaderLabels(tableHeader);
48 }
49 
addRow(string & entityName,NerNamedEntityType entityType,float score)50 void NerLeaderboardModel::addRow(string& entityName, NerNamedEntityType entityType, float score)
51 {
52     QList<QStandardItem*> items;
53     QStandardItem* item;
54 
55     QString html{};
56     html += QString::fromStdString(entityName);
57 
58     // item
59     item = new QStandardItem(html);
60     item->setToolTip(html);
61     items += item;
62 
63     html.clear();
64     switch(entityType) {
65     case NerNamedEntityType::PERSON:
66         html += tr("person");
67         break;
68     case NerNamedEntityType::LOCATION:
69         html += tr("location");
70         break;
71     case NerNamedEntityType::ORGANIZATION:
72         html += tr("organization");
73         break;
74     case NerNamedEntityType::MISC:
75         html += tr("misc");
76         break;
77     }
78 
79     item = new QStandardItem(html);
80     item->setToolTip(html);
81     items += item;
82 
83     html.clear();
84     if(score>0.29) {
85         html += "<span style='color: #00";
86         if(score>0.69) {
87             html += "CC";
88         } else if(score>0.49) {
89             html += "AA";
90         } else if(score>0.39) {
91             html += "66";
92         } else if(score>0.29) {
93             html += "44";
94         }
95         html += "00'>";
96     }
97     score = ROUND_FLOAT(score, 1000);
98     html += QString::number(score);
99     if(score>0.29) {
100         html += "</span>";
101     }
102     item = new QStandardItem(html);
103     item->setData(QVariant::fromValue(score));
104     items += item;
105 
106     appendRow(items);
107 }
108 
109 } // m8r namespace
110