Blame view

morfeusz/MorphInterpretation.cpp 3.86 KB
Michał Lenart authored
1
2
3
4
5
6
7
8
/* 
 * File:   MorphInterpretation.cpp
 * Author: mlenart
 * 
 * Created on November 14, 2013, 11:47 AM
 */

#include <string>
Michał Lenart authored
9
#include <sstream>
Michał Lenart authored
10
#include "MorphInterpretation.hpp"
Michał Lenart authored
11
#include "const.hpp"
Michał Lenart authored
12
13
14

using namespace std;
Michał Lenart authored
15
16
namespace morfeusz {
Michał Lenart authored
17
18
19
MorphInterpretation::MorphInterpretation(
        int startNode,
        int endNode,
Michał Lenart authored
20
21
        const string& orth,
        const string& lemma,
Michał Lenart authored
22
        //        const string& homonymId,
Michał Lenart authored
23
24
        int tagnum,
        int namenum,
Michał Lenart authored
25
26
27
28
29
30
        int qualifiersNum,
        const Environment& env)
: startNode(startNode),
endNode(endNode),
orth(orth),
lemma(lemma),
Michał Lenart authored
31
//homonymId(homonymId),
Michał Lenart authored
32
33
34
35
tagnum(tagnum),
namenum(namenum),
tag(env.getTagset().getTag(tagnum, env.getCharsetConverter())),
name(env.getTagset().getName(namenum, env.getCharsetConverter())),
Michał Lenart authored
36
qualifiers(&env.getQualifiersHelper().getQualifiers(qualifiersNum)) {
Michał Lenart authored
37
Michał Lenart authored
38
Michał Lenart authored
39
40
}
Michał Lenart authored
41
42
static const vector<std::string> emptyQualifiers;
Michał Lenart authored
43
44
45
46
47
48
49
50
51
52
MorphInterpretation::MorphInterpretation() 
: startNode(),
endNode(),
orth(),
lemma(),
//homonymId(homonymId),
tagnum(),
namenum(),
tag(),
name(),
Michał Lenart authored
53
qualifiers(&emptyQualifiers){
Michał Lenart authored
54
55
56

}
Michał Lenart authored
57
58
59
MorphInterpretation::MorphInterpretation(
        int startNode,
        const std::string& orth,
Michał Lenart authored
60
61
62
63
64
        const Environment& env)
: startNode(startNode),
endNode(startNode + 1),
orth(orth),
lemma(orth),
Michał Lenart authored
65
//homonymId(""),
Michał Lenart authored
66
67
68
69
70
tagnum(0),
namenum(0),
//        qualifiersNum(0),
tag(env.getTagset().getTag(0, env.getCharsetConverter())),
name(env.getTagset().getName(0, env.getCharsetConverter())),
Michał Lenart authored
71
qualifiers(&emptyQualifiers) {
Michał Lenart authored
72
73
74

}
Michał Lenart authored
75
76
MorphInterpretation MorphInterpretation::createIgn(int startNode, const std::string& orth, const Environment& env) {
    return MorphInterpretation(startNode, orth, env);
Michał Lenart authored
77
78
}
Michał Lenart authored
79
80
81
82
83
84
85
86
int MorphInterpretation::getStartNode() const {
    return this->startNode;
}

int MorphInterpretation::getEndNode() const {
    return this->endNode;
}
Michał Lenart authored
87
88
89
90
91
92
93
94
const std::string& MorphInterpretation::getOrth() const {
    return this->orth;
}

const std::string& MorphInterpretation::getLemma() const {
    return this->lemma;
}
Michał Lenart authored
95
96
97
98
99
100
101
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;
    }
Michał Lenart authored
102
103
}
Michał Lenart authored
104
105
106
107
108
109
110
111
112
113
114
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;
//}
Michał Lenart authored
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
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;
}
Michał Lenart authored
131
const vector<string>& MorphInterpretation::getQualifiers() const {
Michał Lenart authored
132
    return *this->qualifiers;
Michał Lenart authored
133
134
135
136
137
138
139
140
141
142
143
144
145
}

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;
}
Michał Lenart authored
146
147
148
149
150
151
std::string MorphInterpretation::toString(bool includeNodeNumbers) const {
    std::stringstream res;
    if (includeNodeNumbers) {
        res << startNode << "," << endNode << ",";
    }
    res << orth << ",";
Michał Lenart authored
152
Michał Lenart authored
153
    res << lemma;
Michał Lenart authored
154
155
156
//    if (!this->homonymId.empty()) {
//        res << ":" << homonymId;
//    }
Michał Lenart authored
157
    res << ",";
Michał Lenart authored
158
Michał Lenart authored
159
160
161
162
    res << tag;
    if (!name.empty()) {
        res << "," << name;
    }
Michał Lenart authored
163
    if (!qualifiers->empty()) {
Michał Lenart authored
164
165
        res << "," << getQualifiersStr(*this);
    }
Michał Lenart authored
166
167
    return res.str();
}
Michał Lenart authored
168
169

}