-
Notifications
You must be signed in to change notification settings - Fork 5
/
evaluation_evalparses.cpp
73 lines (62 loc) · 1.89 KB
/
evaluation_evalparses.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
#include "evaluation.h"
#include <QTextStream>
#include<QFile>
#include <QRegularExpression>
EvalParses::EvalParses(): m_parses() { }
EvalParses::EvalParses(QString& file_name):
m_parses(), m_file_name(file_name) { }
EvalParses::EvalParses(const EvalParses& eval)
{
m_parses = eval.m_parses;
m_results = eval.m_results;
m_file_name = eval.m_file_name;
m_evaluated = eval.m_evaluated;
}
EvalParses& EvalParses::operator=(const EvalParses& eval)
{
if (&eval != this) {
m_parses = eval.m_parses;
m_results = eval.m_results;
m_file_name = eval.m_file_name;
m_evaluated = eval.m_evaluated;
}
return *this;
}
EvalParses::~EvalParses()
{ }
bool EvalParses::evaluate(GoldStandard *p_gs)
{
return p_gs->evaluate(this);
}
// __input
bool EvalParses::read_morfessor_txt_file()
{
if(m_file_name.isEmpty())
return false;
m_parses = ParseMapHandler();
QFile parse_file(m_file_name);
if (!parse_file.open(QIODevice::ReadOnly))
return false;
QTextStream out_corpus_costs(&parse_file);
int word_count = 0;
while (!parse_file.atEnd()) {
QString line = parse_file.readLine();
if (line[0] == '#')
continue;
word_count++;
line.remove(QRegularExpression("\\/[A-Z]+"));
QStringList tokens = line.split(QRegularExpression("\\s\\+\\s|1\\s"));
word_t str_word = tokens.join("");
int word_len = str_word.length();
int cut_position = tokens[0].length();
int list_len = tokens.length();
for (int i = 1; i < list_len; i++) {
stem_t stem = str_word.left(cut_position);
affix_t suffix = str_word.right(word_len - cut_position);
cut_position += tokens[i].length();
m_parses.add_parse_triple(str_word, stem, suffix);
}
}
m_results.set_retrieved_word_count(word_count);
return true;
}