MorphInterpretation.cpp
3.62 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* File: MorphInterpretation.cpp
* Author: mlenart
*
* Created on November 14, 2013, 11:47 AM
*/
#include <string>
#include <sstream>
#include "MorphInterpretation.hpp"
#include "EncodedInterpretation.hpp"
#include "const.hpp"
using namespace std;
MorphInterpretation::MorphInterpretation(
int startNode,
int endNode,
const string& orth,
const string& lemma,
// const string& homonymId,
int tagnum,
int namenum,
int qualifiersNum,
const Environment& env)
: startNode(startNode),
endNode(endNode),
orth(orth),
lemma(lemma),
//homonymId(homonymId),
tagnum(tagnum),
namenum(namenum),
tag(env.getTagset().getTag(tagnum, env.getCharsetConverter())),
name(env.getTagset().getName(namenum, env.getCharsetConverter())),
qualifiers(env.getQualifiersHelper().getQualifiers(qualifiersNum)) {
}
MorphInterpretation::MorphInterpretation(
int startNode,
const std::string& orth,
const Environment& env)
: startNode(startNode),
endNode(startNode + 1),
orth(orth),
lemma(orth),
//homonymId(""),
tagnum(0),
namenum(0),
// qualifiersNum(0),
tag(env.getTagset().getTag(0, env.getCharsetConverter())),
name(env.getTagset().getName(0, env.getCharsetConverter())),
qualifiers() {
}
MorphInterpretation MorphInterpretation::createIgn(int startNode, const std::string& orth, const Environment& env) {
return MorphInterpretation(startNode, orth, env);
}
int MorphInterpretation::getStartNode() const {
return this->startNode;
}
int MorphInterpretation::getEndNode() const {
return this->endNode;
}
const std::string& MorphInterpretation::getOrth() const {
return this->orth;
}
const std::string& MorphInterpretation::getLemma() const {
return this->lemma;
}
static inline bool hasEnding(const string &fullString, const string &ending) {
if (fullString.length() >= ending.length()) {
return (0 == fullString.compare(fullString.length() - ending.length(), ending.length(), ending));
}
else {
return false;
}
}
bool MorphInterpretation::hasHomonym(const string& homonymId) const {
size_t homonymSeparatorIdx = this->lemma.length() - homonymId.length() - 1;
return homonymSeparatorIdx > 0
&& this->lemma[homonymSeparatorIdx] == HOMONYM_SEPARATOR
&& hasEnding(this->lemma, homonymId);
}
//const std::string& MorphInterpretation::getHomonymId() const {
// return this->homonymId;
//}
int MorphInterpretation::getTagnum() const {
return this->tagnum;
}
int MorphInterpretation::getNamenum() const {
return this->namenum;
}
const std::string& MorphInterpretation::getTag() const {
return this->tag;
}
const std::string& MorphInterpretation::getName() const {
return this->name;
}
const vector<string>& MorphInterpretation::getQualifiers() const {
return this->qualifiers;
}
static inline string getQualifiersStr(const MorphInterpretation& mi) {
string res;
for (unsigned int i = 0; i < mi.getQualifiers().size(); i++) {
res += mi.getQualifiers()[i];
if (i + 1 < mi.getQualifiers().size()) {
res += "|";
}
}
return res;
}
std::string MorphInterpretation::toString(bool includeNodeNumbers) const {
std::stringstream res;
if (includeNodeNumbers) {
res << startNode << "," << endNode << ",";
}
res << orth << ",";
res << lemma;
// if (!this->homonymId.empty()) {
// res << ":" << homonymId;
// }
res << ",";
res << tag;
if (!name.empty()) {
res << "," << name;
}
if (!qualifiers.empty()) {
res << "," << getQualifiersStr(*this);
}
return res.str();
}