Repository navigation
Expand file tree
/
Copy pathMorph.cpp
More file actions
83 lines (60 loc) · 1.77 KB
/
Copy pathMorph.cpp
File metadata and controls
83 lines (60 loc) · 1.77 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
/**
* @author Jamie (jamie.lim@kakaocorp.com)
* @copyright Copyright (C) 2018-, Kakao Corp. All rights reserved.
*/
#include "khaiii/Morph.hpp"
//////////////
// includes //
//////////////
#include <cassert>
#include <string>
#include <vector>
#include "khaiii/util.hpp"
namespace khaiii {
using std::string;
using std::vector;
using std::wstring;
using std::wstringstream;
///////////////
// variables //
///////////////
static const char* _TAG_SET[POS_TAG_SIZE] = {
"EC", "EF", "EP", "ETM", "ETN", "IC", "JC", "JKB", "JKC", "JKG",
"JKO", "JKQ", "JKS", "JKV", "JX", "MAG", "MAJ", "MM", "NNB", "NNG",
"NNP", "NP", "NR", "SE", "SF", "SH", "SL", "SN", "SO", "SP",
"SS", "SW", "SWK", "VA", "VCN", "VCP", "VV", "VX", "XPN", "XR",
"XSA", "XSN", "XSV", "ZN", "ZV", "ZZ",
};
////////////////////
// ctors and dtor //
////////////////////
Morph::Morph(wstring wlex, pos_tag_t tag, const wchar_t* wbegin, int wlength)
: wlex(wlex), wbegin(wbegin), wlength(wlength), _lex(wstr_to_utf8(wlex)) {
lex = _lex.c_str();
this->tag = pos_str(tag);
begin = -1;
length = -1;
next = nullptr;
}
/////////////
// methods //
/////////////
const char* Morph::pos_str(pos_tag_t num) {
assert(0 < num && num <= POS_TAG_SIZE);
return _TAG_SET[num-1];
}
void Morph::organize(const wstring& wraw, const vector<int>& wbegins, const vector<int>& wends) {
int begin_idx = wbegin - wraw.c_str();
int end_idx = begin_idx + wlength - 1;
begin = wbegins[begin_idx];
length = wends[end_idx] - begin;
}
string Morph::str() {
return wstr_to_utf8(wstr());
}
wstring Morph::wstr() {
wstringstream wss;
wss << wlex << L"/" << tag << L":" << begin << L"," << length;
return wss.str();
}
} // namespace khaiii