morfeusz2.h
7.76 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/*
* File: morfeusz2.h
* Author: mlenart
*
* Created on 13 czerwiec 2014, 17:28
*/
#ifndef MORFEUSZ2_H
#define MORFEUSZ2_H
#include <vector>
#include <string>
#include <list>
namespace morfeusz {
class MorphInterpretation;
class Morfeusz;
class ResultsIterator;
class Environment;
class MorfeuszException;
enum Charset {
UTF8 = 101,
// UTF16LE,
// UTF16BE,
// UTF32,
ISO8859_2 = 102,
CP1250 = 103,
CP852 = 104
};
enum TokenNumbering {
/**
* Start from 0. Reset counter for every invocation of Morfeusz::analyze
*/
SEPARATE = 201,
/**
* Also start from 0. Reset counter for every invocation of Morfeusz::setTokenNumbering only
*/
CONTINUOUS = 202
};
enum CaseHandling {
/**
* Case-sensitive but allows interpretations that do not match case but there are no alternatives
*/
WEAK = 100,
/**
* Strictly case-sensitive, reject all interpretations that do not match case
*/
STRICT = 101,
/**
* Case-insensitive - ignores case
*/
IGNORE = 102
};
/**
* Performs morphological analysis (analyze methods) and syntesis (generate methods).
*
* It is NOT thread-safe
* but it is possible to use separate Morfeusz instance for each concurrent thread.
*/
class Morfeusz {
public:
/**
* Creates actual instance of Morfeusz class.
* The caller is responsible for destroying it.
*
* @return
*/
static Morfeusz* createInstance();
/**
* Set a file used for morphological analysis.
*
* @param filename
*/
virtual void setAnalyzerDictionary(const std::string& filename) = 0;
/**
* Set a file used for morphological synthesis.
*
* @param filename
*/
virtual void setGeneratorDictionary(const std::string& filename) = 0;
virtual ~Morfeusz();
/**
* Analyze given text and return the results as iterator.
*
* @param text - text for morphological analysis
* @return - iterator over morphological analysis results
*/
virtual ResultsIterator analyze(const std::string& text) const = 0;
/**
* Perform morphological analysis on a given text and put results in a vector.
*
* @param text - text to be analyzed
* @param result - results vector
*/
virtual void analyze(const std::string& text, std::vector<MorphInterpretation>& result) const = 0;
/**
* Perform morphological synthesis on a given lemma and return the results as iterator.
*
* @param text - text for morphological analysis
* @return - iterator over morphological analysis results
*/
virtual ResultsIterator generate(const std::string& lemma) const = 0;
/**
* Perform morphological synthesis on a given lemma and return the results as iterator.
* Limit results to interpretations with the specified tag.
*
* @param text - text for morphological analysis
* @param tag - tag of result interpretations
* @return - iterator over morphological analysis results
*/
virtual ResultsIterator generate(const std::string& lemma, int tagnum) const = 0;
/**
* Perform morphological synthesis on a given lemma and put results in a vector.
*
* @param lemma - lemma to be analyzed
* @param result - results vector
*/
virtual void generate(const std::string& lemma, std::vector<MorphInterpretation>& result) const = 0;
/**
* Perform morphological synthesis on a given lemma and put results in a vector.
* Limit results to interpretations with the specified tag.
*
* @param lemma - lemma to be analyzed
* @param tag - tag of result interpretations
* @param result - results vector
*/
virtual void generate(const std::string& lemma, int tagnum, std::vector<MorphInterpretation>& result) const = 0;
/**
* Set encoding for input and output string objects.
*
* @param encoding
*/
virtual void setCharset(Charset encoding) = 0;
/**
* Set aggl segmentation option value.
*
* @param aggl
*/
virtual void setAggl(const std::string& aggl) = 0;
/**
* Set praet segmentation option value.
*
* @param praet
*/
virtual void setPraet(const std::string& praet) = 0;
/**
* If set to true characters case in analyzed text must match
* the case in the recognized forms from dictionary.
*
* @param caseSensitive
*/
virtual void setCaseHandling(CaseHandling caseHandling) = 0;
/**
* Set token numbering policy.
*
* @param numbering
*/
virtual void setTokenNumbering(TokenNumbering numbering) = 0;
/**
* Set debug option value.
*
* @param debug
*/
virtual void setDebug(bool debug) = 0;
};
class ResultsIterator {
public:
ResultsIterator(const std::vector<MorphInterpretation>& res);
MorphInterpretation getNext();
bool hasNext();
friend class Morfeusz;
private:
const char* rawInput;
std::list<MorphInterpretation> resultsBuffer;
int startNode;
};
/**
* Morphological interpretation as seen by the user in the analysis/generation results.
*/
class MorphInterpretation {
public:
MorphInterpretation(
int startNode,
int endNode,
const std::string& orth,
const std::string& lemma,
int tagnum,
int namenum,
int qualifiersNum,
const Environment& env);
MorphInterpretation();
static MorphInterpretation createIgn(int startNode, const std::string& orth, const Environment& env);
virtual ~MorphInterpretation() {}
int getStartNode() const;
int getEndNode() const;
const std::string& getOrth() const;
const std::string& getLemma() const;
bool hasHomonym(const std::string& homonymId) const;
int getTagnum() const;
int getNamenum() const;
const std::string getTag() const;
const std::string getName() const;
const std::vector<std::string>& getQualifiers() const;
std::string toString(bool includeNodeNumbers) const;
private:
MorphInterpretation(
int startNode,
const std::string& orth,
const Environment& env);
int startNode;
int endNode;
std::string orth;
std::string lemma;
int tagnum;
int namenum;
int qualifiersNum;
/**
* not owned by this
*/
const Environment* env;
};
class MorfeuszException : public std::exception {
public:
MorfeuszException(const std::string& what) : msg(what.c_str()) {
}
virtual ~MorfeuszException() throw () {
}
virtual const char* what() const throw () {
return this->msg.c_str();
}
private:
const std::string msg;
};
class FileFormatException : public MorfeuszException {
public:
FileFormatException(const std::string& what) : MorfeuszException(what) {
}
};
}
#endif /* MORFEUSZ2_H */