react-native-jieba 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cpp/cppjieba/CHANGELOG.md +18 -0
- package/cpp/cppjieba/LICENSE +20 -0
- package/cpp/cppjieba/README.md +288 -0
- package/cpp/cppjieba/deps/limonp/CHANGELOG.md +175 -0
- package/cpp/cppjieba/deps/limonp/LICENSE +20 -0
- package/cpp/cppjieba/deps/limonp/README.md +43 -0
- package/cpp/cppjieba/deps/limonp/include/limonp/ArgvContext.hpp +70 -0
- package/cpp/cppjieba/deps/limonp/include/limonp/Closure.hpp +206 -0
- package/cpp/cppjieba/deps/limonp/include/limonp/Colors.hpp +31 -0
- package/cpp/cppjieba/deps/limonp/include/limonp/Condition.hpp +38 -0
- package/cpp/cppjieba/deps/limonp/include/limonp/Config.hpp +103 -0
- package/cpp/cppjieba/deps/limonp/include/limonp/ForcePublic.hpp +7 -0
- package/cpp/cppjieba/deps/limonp/include/limonp/LocalVector.hpp +139 -0
- package/cpp/cppjieba/deps/limonp/include/limonp/Logging.hpp +92 -0
- package/cpp/cppjieba/deps/limonp/include/limonp/NonCopyable.hpp +21 -0
- package/cpp/cppjieba/deps/limonp/include/limonp/StdExtension.hpp +157 -0
- package/cpp/cppjieba/deps/limonp/include/limonp/StringUtil.hpp +386 -0
- package/cpp/cppjieba/dict/README.md +62 -0
- package/cpp/cppjieba/dict/hmm_model.utf8 +34 -0
- package/cpp/cppjieba/dict/idf.utf8 +258826 -0
- package/cpp/cppjieba/dict/jieba.dict.utf8 +348982 -0
- package/cpp/cppjieba/dict/stop_words.utf8 +1534 -0
- package/cpp/cppjieba/dict/user.dict.utf8 +3 -0
- package/cpp/cppjieba/include/cppjieba/DictTrie.hpp +322 -0
- package/cpp/cppjieba/include/cppjieba/FullSegment.hpp +94 -0
- package/cpp/cppjieba/include/cppjieba/HMMModel.hpp +131 -0
- package/cpp/cppjieba/include/cppjieba/HMMSegment.hpp +211 -0
- package/cpp/cppjieba/include/cppjieba/Jieba.hpp +169 -0
- package/cpp/cppjieba/include/cppjieba/KeywordExtractor.hpp +152 -0
- package/cpp/cppjieba/include/cppjieba/MPSegment.hpp +137 -0
- package/cpp/cppjieba/include/cppjieba/MixSegment.hpp +109 -0
- package/cpp/cppjieba/include/cppjieba/PosTagger.hpp +77 -0
- package/cpp/cppjieba/include/cppjieba/PreFilter.hpp +54 -0
- package/cpp/cppjieba/include/cppjieba/QuerySegment.hpp +89 -0
- package/cpp/cppjieba/include/cppjieba/SegmentBase.hpp +46 -0
- package/cpp/cppjieba/include/cppjieba/SegmentTagged.hpp +23 -0
- package/cpp/cppjieba/include/cppjieba/TextRankExtractor.hpp +192 -0
- package/cpp/cppjieba/include/cppjieba/Trie.hpp +200 -0
- package/cpp/cppjieba/include/cppjieba/Unicode.hpp +231 -0
- package/cpp/cppjieba/include/cppjieba/UnicodeFile.hpp +68 -0
- package/package.json +3 -2
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
#ifndef LIMONP_STD_EXTEMSION_HPP
|
|
2
|
+
#define LIMONP_STD_EXTEMSION_HPP
|
|
3
|
+
|
|
4
|
+
#include <map>
|
|
5
|
+
|
|
6
|
+
#ifdef __APPLE__
|
|
7
|
+
#include <unordered_map>
|
|
8
|
+
#include <unordered_set>
|
|
9
|
+
#elif(__cplusplus >= 201103L)
|
|
10
|
+
#include <unordered_map>
|
|
11
|
+
#include <unordered_set>
|
|
12
|
+
#elif defined _MSC_VER
|
|
13
|
+
#include <unordered_map>
|
|
14
|
+
#include <unordered_set>
|
|
15
|
+
#else
|
|
16
|
+
#include <tr1/unordered_map>
|
|
17
|
+
#include <tr1/unordered_set>
|
|
18
|
+
namespace std {
|
|
19
|
+
using std::tr1::unordered_map;
|
|
20
|
+
using std::tr1::unordered_set;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
#endif
|
|
24
|
+
|
|
25
|
+
#include <set>
|
|
26
|
+
#include <string>
|
|
27
|
+
#include <vector>
|
|
28
|
+
#include <deque>
|
|
29
|
+
#include <fstream>
|
|
30
|
+
#include <sstream>
|
|
31
|
+
|
|
32
|
+
namespace std {
|
|
33
|
+
|
|
34
|
+
template<typename T>
|
|
35
|
+
ostream& operator << (ostream& os, const vector<T>& v) {
|
|
36
|
+
if(v.empty()) {
|
|
37
|
+
return os << "[]";
|
|
38
|
+
}
|
|
39
|
+
os<<"["<<v[0];
|
|
40
|
+
for(size_t i = 1; i < v.size(); i++) {
|
|
41
|
+
os<<", "<<v[i];
|
|
42
|
+
}
|
|
43
|
+
os<<"]";
|
|
44
|
+
return os;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
template<>
|
|
48
|
+
inline ostream& operator << (ostream& os, const vector<string>& v) {
|
|
49
|
+
if(v.empty()) {
|
|
50
|
+
return os << "[]";
|
|
51
|
+
}
|
|
52
|
+
os<<"[\""<<v[0];
|
|
53
|
+
for(size_t i = 1; i < v.size(); i++) {
|
|
54
|
+
os<<"\", \""<<v[i];
|
|
55
|
+
}
|
|
56
|
+
os<<"\"]";
|
|
57
|
+
return os;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
template<typename T>
|
|
61
|
+
ostream& operator << (ostream& os, const deque<T>& dq) {
|
|
62
|
+
if(dq.empty()) {
|
|
63
|
+
return os << "[]";
|
|
64
|
+
}
|
|
65
|
+
os<<"[\""<<dq[0];
|
|
66
|
+
for(size_t i = 1; i < dq.size(); i++) {
|
|
67
|
+
os<<"\", \""<<dq[i];
|
|
68
|
+
}
|
|
69
|
+
os<<"\"]";
|
|
70
|
+
return os;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
template<class T1, class T2>
|
|
75
|
+
ostream& operator << (ostream& os, const pair<T1, T2>& pr) {
|
|
76
|
+
os << pr.first << ":" << pr.second ;
|
|
77
|
+
return os;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
template<class T>
|
|
82
|
+
string& operator << (string& str, const T& obj) {
|
|
83
|
+
stringstream ss;
|
|
84
|
+
ss << obj; // call ostream& operator << (ostream& os,
|
|
85
|
+
return str = ss.str();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
template<class T1, class T2>
|
|
89
|
+
ostream& operator << (ostream& os, const map<T1, T2>& mp) {
|
|
90
|
+
if(mp.empty()) {
|
|
91
|
+
os<<"{}";
|
|
92
|
+
return os;
|
|
93
|
+
}
|
|
94
|
+
os<<'{';
|
|
95
|
+
typename map<T1, T2>::const_iterator it = mp.begin();
|
|
96
|
+
os<<*it;
|
|
97
|
+
it++;
|
|
98
|
+
while(it != mp.end()) {
|
|
99
|
+
os<<", "<<*it;
|
|
100
|
+
it++;
|
|
101
|
+
}
|
|
102
|
+
os<<'}';
|
|
103
|
+
return os;
|
|
104
|
+
}
|
|
105
|
+
template<class T1, class T2>
|
|
106
|
+
ostream& operator << (ostream& os, const std::unordered_map<T1, T2>& mp) {
|
|
107
|
+
if(mp.empty()) {
|
|
108
|
+
return os << "{}";
|
|
109
|
+
}
|
|
110
|
+
os<<'{';
|
|
111
|
+
typename std::unordered_map<T1, T2>::const_iterator it = mp.begin();
|
|
112
|
+
os<<*it;
|
|
113
|
+
it++;
|
|
114
|
+
while(it != mp.end()) {
|
|
115
|
+
os<<", "<<*it++;
|
|
116
|
+
}
|
|
117
|
+
return os<<'}';
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
template<class T>
|
|
121
|
+
ostream& operator << (ostream& os, const set<T>& st) {
|
|
122
|
+
if(st.empty()) {
|
|
123
|
+
os << "{}";
|
|
124
|
+
return os;
|
|
125
|
+
}
|
|
126
|
+
os<<'{';
|
|
127
|
+
typename set<T>::const_iterator it = st.begin();
|
|
128
|
+
os<<*it;
|
|
129
|
+
it++;
|
|
130
|
+
while(it != st.end()) {
|
|
131
|
+
os<<", "<<*it;
|
|
132
|
+
it++;
|
|
133
|
+
}
|
|
134
|
+
os<<'}';
|
|
135
|
+
return os;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
template<class KeyType, class ContainType>
|
|
139
|
+
bool IsIn(const ContainType& contain, const KeyType& key) {
|
|
140
|
+
return contain.end() != contain.find(key);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
template<class T>
|
|
144
|
+
basic_string<T> & operator << (basic_string<T> & s, ifstream & ifs) {
|
|
145
|
+
return s.assign((istreambuf_iterator<T>(ifs)), istreambuf_iterator<T>());
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
template<class T>
|
|
149
|
+
ofstream & operator << (ofstream & ofs, const basic_string<T>& s) {
|
|
150
|
+
ostreambuf_iterator<T> itr (ofs);
|
|
151
|
+
copy(s.begin(), s.end(), itr);
|
|
152
|
+
return ofs;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
} // namespace std
|
|
156
|
+
|
|
157
|
+
#endif
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
/************************************
|
|
2
|
+
* file enc : ascii
|
|
3
|
+
* author : wuyanyi09@gmail.com
|
|
4
|
+
************************************/
|
|
5
|
+
#ifndef LIMONP_STR_FUNCTS_H
|
|
6
|
+
#define LIMONP_STR_FUNCTS_H
|
|
7
|
+
#include <fstream>
|
|
8
|
+
#include <iostream>
|
|
9
|
+
#include <string>
|
|
10
|
+
#include <vector>
|
|
11
|
+
#include <algorithm>
|
|
12
|
+
#include <cctype>
|
|
13
|
+
#include <map>
|
|
14
|
+
#include <cassert>
|
|
15
|
+
#include <ctime>
|
|
16
|
+
#include <stdint.h>
|
|
17
|
+
#include <stdio.h>
|
|
18
|
+
#include <stdarg.h>
|
|
19
|
+
#include <memory.h>
|
|
20
|
+
#include <functional>
|
|
21
|
+
#include <locale>
|
|
22
|
+
#include <sstream>
|
|
23
|
+
#include <sys/types.h>
|
|
24
|
+
#include <iterator>
|
|
25
|
+
#include <algorithm>
|
|
26
|
+
#include "StdExtension.hpp"
|
|
27
|
+
|
|
28
|
+
namespace limonp {
|
|
29
|
+
using namespace std;
|
|
30
|
+
inline string StringFormat(const char* fmt, ...) {
|
|
31
|
+
int size = 256;
|
|
32
|
+
std::string str;
|
|
33
|
+
va_list ap;
|
|
34
|
+
while (1) {
|
|
35
|
+
str.resize(size);
|
|
36
|
+
va_start(ap, fmt);
|
|
37
|
+
int n = vsnprintf((char *)str.c_str(), size, fmt, ap);
|
|
38
|
+
va_end(ap);
|
|
39
|
+
if (n > -1 && n < size) {
|
|
40
|
+
str.resize(n);
|
|
41
|
+
return str;
|
|
42
|
+
}
|
|
43
|
+
if (n > -1)
|
|
44
|
+
size = n + 1;
|
|
45
|
+
else
|
|
46
|
+
size *= 2;
|
|
47
|
+
}
|
|
48
|
+
return str;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
template<class T>
|
|
52
|
+
void Join(T begin, T end, string& res, const string& connector) {
|
|
53
|
+
if(begin == end) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
stringstream ss;
|
|
57
|
+
ss<<*begin;
|
|
58
|
+
begin++;
|
|
59
|
+
while(begin != end) {
|
|
60
|
+
ss << connector << *begin;
|
|
61
|
+
begin ++;
|
|
62
|
+
}
|
|
63
|
+
res = ss.str();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
template<class T>
|
|
67
|
+
string Join(T begin, T end, const string& connector) {
|
|
68
|
+
string res;
|
|
69
|
+
Join(begin ,end, res, connector);
|
|
70
|
+
return res;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
inline string& Upper(string& str) {
|
|
74
|
+
transform(str.begin(), str.end(), str.begin(), (int (*)(int))toupper);
|
|
75
|
+
return str;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
inline string& Lower(string& str) {
|
|
79
|
+
transform(str.begin(), str.end(), str.begin(), (int (*)(int))tolower);
|
|
80
|
+
return str;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
inline bool IsSpace(unsigned c) {
|
|
84
|
+
// when passing large int as the argument of isspace, it core dump, so here need a type cast.
|
|
85
|
+
return c > 0xff ? false : std::isspace(c & 0xff) != 0;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
inline std::string& LTrim(std::string &s) {
|
|
89
|
+
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {
|
|
90
|
+
return !std::isspace(ch);
|
|
91
|
+
}));
|
|
92
|
+
return s;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
inline std::string& RTrim(std::string &s) {
|
|
96
|
+
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) {
|
|
97
|
+
return !std::isspace(ch);
|
|
98
|
+
}).base(), s.end());
|
|
99
|
+
return s;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
inline std::string& Trim(std::string &s) {
|
|
103
|
+
return LTrim(RTrim(s));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
inline std::string& LTrim(std::string& s, char x) {
|
|
107
|
+
s.erase(s.begin(), std::find_if(s.begin(), s.end(),
|
|
108
|
+
[x](unsigned char c) { return !std::isspace(c) && c != x; }));
|
|
109
|
+
return s;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
inline std::string& RTrim(std::string& s, char x) {
|
|
113
|
+
s.erase(std::find_if(s.rbegin(), s.rend(),
|
|
114
|
+
[x](unsigned char c) { return !std::isspace(c) && c != x; }).base(), s.end());
|
|
115
|
+
return s;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
inline std::string& Trim(std::string &s, char x) {
|
|
119
|
+
return LTrim(RTrim(s, x), x);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
inline void Split(const string& src, vector<string>& res, const string& pattern, size_t maxsplit = string::npos) {
|
|
123
|
+
res.clear();
|
|
124
|
+
size_t Start = 0;
|
|
125
|
+
size_t end = 0;
|
|
126
|
+
string sub;
|
|
127
|
+
while(Start < src.size()) {
|
|
128
|
+
end = src.find_first_of(pattern, Start);
|
|
129
|
+
if(string::npos == end || res.size() >= maxsplit) {
|
|
130
|
+
sub = src.substr(Start);
|
|
131
|
+
res.push_back(sub);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
sub = src.substr(Start, end - Start);
|
|
135
|
+
res.push_back(sub);
|
|
136
|
+
Start = end + 1;
|
|
137
|
+
}
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
inline vector<string> Split(const string& src, const string& pattern, size_t maxsplit = string::npos) {
|
|
142
|
+
vector<string> res;
|
|
143
|
+
Split(src, res, pattern, maxsplit);
|
|
144
|
+
return res;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
inline bool StartsWith(const string& str, const string& prefix) {
|
|
148
|
+
if(prefix.length() > str.length()) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
return 0 == str.compare(0, prefix.length(), prefix);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
inline bool EndsWith(const string& str, const string& suffix) {
|
|
155
|
+
if(suffix.length() > str.length()) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
return 0 == str.compare(str.length() - suffix.length(), suffix.length(), suffix);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
inline bool IsInStr(const string& str, char ch) {
|
|
162
|
+
return str.find(ch) != string::npos;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
inline uint16_t TwocharToUint16(char high, char low) {
|
|
166
|
+
return (((uint16_t(high) & 0x00ff ) << 8) | (uint16_t(low) & 0x00ff));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
template <class Uint16Container>
|
|
170
|
+
bool Utf8ToUnicode(const char * const str, size_t len, Uint16Container& vec) {
|
|
171
|
+
if(!str) {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
char ch1, ch2;
|
|
175
|
+
uint16_t tmp;
|
|
176
|
+
vec.clear();
|
|
177
|
+
for(size_t i = 0; i < len;) {
|
|
178
|
+
if(!(str[i] & 0x80)) { // 0xxxxxxx
|
|
179
|
+
vec.push_back(str[i]);
|
|
180
|
+
i++;
|
|
181
|
+
} else if ((uint8_t)str[i] <= 0xdf && i + 1 < len) { // 110xxxxxx
|
|
182
|
+
ch1 = (str[i] >> 2) & 0x07;
|
|
183
|
+
ch2 = (str[i+1] & 0x3f) | ((str[i] & 0x03) << 6 );
|
|
184
|
+
tmp = (((uint16_t(ch1) & 0x00ff ) << 8) | (uint16_t(ch2) & 0x00ff));
|
|
185
|
+
vec.push_back(tmp);
|
|
186
|
+
i += 2;
|
|
187
|
+
} else if((uint8_t)str[i] <= 0xef && i + 2 < len) {
|
|
188
|
+
ch1 = ((uint8_t)str[i] << 4) | ((str[i+1] >> 2) & 0x0f );
|
|
189
|
+
ch2 = (((uint8_t)str[i+1]<<6) & 0xc0) | (str[i+2] & 0x3f);
|
|
190
|
+
tmp = (((uint16_t(ch1) & 0x00ff ) << 8) | (uint16_t(ch2) & 0x00ff));
|
|
191
|
+
vec.push_back(tmp);
|
|
192
|
+
i += 3;
|
|
193
|
+
} else {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
template <class Uint16Container>
|
|
201
|
+
bool Utf8ToUnicode(const string& str, Uint16Container& vec) {
|
|
202
|
+
return Utf8ToUnicode(str.c_str(), str.size(), vec);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
template <class Uint32Container>
|
|
206
|
+
bool Utf8ToUnicode32(const string& str, Uint32Container& vec) {
|
|
207
|
+
uint32_t tmp;
|
|
208
|
+
vec.clear();
|
|
209
|
+
for(size_t i = 0; i < str.size();) {
|
|
210
|
+
if(!(str[i] & 0x80)) { // 0xxxxxxx
|
|
211
|
+
// 7bit, total 7bit
|
|
212
|
+
tmp = (uint8_t)(str[i]) & 0x7f;
|
|
213
|
+
i++;
|
|
214
|
+
} else if ((uint8_t)str[i] <= 0xdf && i + 1 < str.size()) { // 110xxxxxx
|
|
215
|
+
// 5bit, total 5bit
|
|
216
|
+
tmp = (uint8_t)(str[i]) & 0x1f;
|
|
217
|
+
|
|
218
|
+
// 6bit, total 11bit
|
|
219
|
+
tmp <<= 6;
|
|
220
|
+
tmp |= (uint8_t)(str[i+1]) & 0x3f;
|
|
221
|
+
i += 2;
|
|
222
|
+
} else if((uint8_t)str[i] <= 0xef && i + 2 < str.size()) { // 1110xxxxxx
|
|
223
|
+
// 4bit, total 4bit
|
|
224
|
+
tmp = (uint8_t)(str[i]) & 0x0f;
|
|
225
|
+
|
|
226
|
+
// 6bit, total 10bit
|
|
227
|
+
tmp <<= 6;
|
|
228
|
+
tmp |= (uint8_t)(str[i+1]) & 0x3f;
|
|
229
|
+
|
|
230
|
+
// 6bit, total 16bit
|
|
231
|
+
tmp <<= 6;
|
|
232
|
+
tmp |= (uint8_t)(str[i+2]) & 0x3f;
|
|
233
|
+
|
|
234
|
+
i += 3;
|
|
235
|
+
} else if((uint8_t)str[i] <= 0xf7 && i + 3 < str.size()) { // 11110xxxx
|
|
236
|
+
// 3bit, total 3bit
|
|
237
|
+
tmp = (uint8_t)(str[i]) & 0x07;
|
|
238
|
+
|
|
239
|
+
// 6bit, total 9bit
|
|
240
|
+
tmp <<= 6;
|
|
241
|
+
tmp |= (uint8_t)(str[i+1]) & 0x3f;
|
|
242
|
+
|
|
243
|
+
// 6bit, total 15bit
|
|
244
|
+
tmp <<= 6;
|
|
245
|
+
tmp |= (uint8_t)(str[i+2]) & 0x3f;
|
|
246
|
+
|
|
247
|
+
// 6bit, total 21bit
|
|
248
|
+
tmp <<= 6;
|
|
249
|
+
tmp |= (uint8_t)(str[i+3]) & 0x3f;
|
|
250
|
+
|
|
251
|
+
i += 4;
|
|
252
|
+
} else {
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
vec.push_back(tmp);
|
|
256
|
+
}
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
template <class Uint32ContainerConIter>
|
|
261
|
+
void Unicode32ToUtf8(Uint32ContainerConIter begin, Uint32ContainerConIter end, string& res) {
|
|
262
|
+
res.clear();
|
|
263
|
+
uint32_t ui;
|
|
264
|
+
while(begin != end) {
|
|
265
|
+
ui = *begin;
|
|
266
|
+
if(ui <= 0x7f) {
|
|
267
|
+
res += char(ui);
|
|
268
|
+
} else if(ui <= 0x7ff) {
|
|
269
|
+
res += char(((ui >> 6) & 0x1f) | 0xc0);
|
|
270
|
+
res += char((ui & 0x3f) | 0x80);
|
|
271
|
+
} else if(ui <= 0xffff) {
|
|
272
|
+
res += char(((ui >> 12) & 0x0f) | 0xe0);
|
|
273
|
+
res += char(((ui >> 6) & 0x3f) | 0x80);
|
|
274
|
+
res += char((ui & 0x3f) | 0x80);
|
|
275
|
+
} else {
|
|
276
|
+
res += char(((ui >> 18) & 0x03) | 0xf0);
|
|
277
|
+
res += char(((ui >> 12) & 0x3f) | 0x80);
|
|
278
|
+
res += char(((ui >> 6) & 0x3f) | 0x80);
|
|
279
|
+
res += char((ui & 0x3f) | 0x80);
|
|
280
|
+
}
|
|
281
|
+
begin ++;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
template <class Uint16ContainerConIter>
|
|
286
|
+
void UnicodeToUtf8(Uint16ContainerConIter begin, Uint16ContainerConIter end, string& res) {
|
|
287
|
+
res.clear();
|
|
288
|
+
uint16_t ui;
|
|
289
|
+
while(begin != end) {
|
|
290
|
+
ui = *begin;
|
|
291
|
+
if(ui <= 0x7f) {
|
|
292
|
+
res += char(ui);
|
|
293
|
+
} else if(ui <= 0x7ff) {
|
|
294
|
+
res += char(((ui>>6) & 0x1f) | 0xc0);
|
|
295
|
+
res += char((ui & 0x3f) | 0x80);
|
|
296
|
+
} else {
|
|
297
|
+
res += char(((ui >> 12) & 0x0f )| 0xe0);
|
|
298
|
+
res += char(((ui>>6) & 0x3f )| 0x80 );
|
|
299
|
+
res += char((ui & 0x3f) | 0x80);
|
|
300
|
+
}
|
|
301
|
+
begin ++;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
template <class Uint16Container>
|
|
307
|
+
bool GBKTrans(const char* const str, size_t len, Uint16Container& vec) {
|
|
308
|
+
vec.clear();
|
|
309
|
+
if(!str) {
|
|
310
|
+
return true;
|
|
311
|
+
}
|
|
312
|
+
size_t i = 0;
|
|
313
|
+
while(i < len) {
|
|
314
|
+
if(0 == (str[i] & 0x80)) {
|
|
315
|
+
vec.push_back(uint16_t(str[i]));
|
|
316
|
+
i++;
|
|
317
|
+
} else {
|
|
318
|
+
if(i + 1 < len) { //&& (str[i+1] & 0x80))
|
|
319
|
+
uint16_t tmp = (((uint16_t(str[i]) & 0x00ff ) << 8) | (uint16_t(str[i+1]) & 0x00ff));
|
|
320
|
+
vec.push_back(tmp);
|
|
321
|
+
i += 2;
|
|
322
|
+
} else {
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return true;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
template <class Uint16Container>
|
|
331
|
+
bool GBKTrans(const string& str, Uint16Container& vec) {
|
|
332
|
+
return GBKTrans(str.c_str(), str.size(), vec);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
template <class Uint16ContainerConIter>
|
|
336
|
+
void GBKTrans(Uint16ContainerConIter begin, Uint16ContainerConIter end, string& res) {
|
|
337
|
+
res.clear();
|
|
338
|
+
//pair<char, char> pa;
|
|
339
|
+
char first, second;
|
|
340
|
+
while(begin != end) {
|
|
341
|
+
//pa = uint16ToChar2(*begin);
|
|
342
|
+
first = ((*begin)>>8) & 0x00ff;
|
|
343
|
+
second = (*begin) & 0x00ff;
|
|
344
|
+
if(first & 0x80) {
|
|
345
|
+
res += first;
|
|
346
|
+
res += second;
|
|
347
|
+
} else {
|
|
348
|
+
res += second;
|
|
349
|
+
}
|
|
350
|
+
begin++;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/*
|
|
355
|
+
* format example: "%Y-%m-%d %H:%M:%S"
|
|
356
|
+
*/
|
|
357
|
+
inline void GetTime(const string& format, string& timeStr) {
|
|
358
|
+
time_t timeNow;
|
|
359
|
+
time(&timeNow);
|
|
360
|
+
|
|
361
|
+
struct tm tmNow;
|
|
362
|
+
|
|
363
|
+
#if defined(_WIN32) || defined(_WIN64)
|
|
364
|
+
errno_t e = localtime_s(&tmNow, &timeNow);
|
|
365
|
+
assert(e == 0);
|
|
366
|
+
#else
|
|
367
|
+
struct tm * tm_tmp = localtime_r(&timeNow, &tmNow);
|
|
368
|
+
assert(tm_tmp != nullptr);
|
|
369
|
+
#endif
|
|
370
|
+
|
|
371
|
+
timeStr.resize(64);
|
|
372
|
+
|
|
373
|
+
size_t len = strftime((char*)timeStr.c_str(), timeStr.size(), format.c_str(), &tmNow);
|
|
374
|
+
|
|
375
|
+
timeStr.resize(len);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
inline string PathJoin(const string& path1, const string& path2) {
|
|
379
|
+
if(EndsWith(path1, "/")) {
|
|
380
|
+
return path1 + path2;
|
|
381
|
+
}
|
|
382
|
+
return path1 + "/" + path2;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
}
|
|
386
|
+
#endif
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# CppJieba字典
|
|
2
|
+
|
|
3
|
+
文件后缀名代表的是词典的编码方式。
|
|
4
|
+
比如filename.utf8 是 utf8编码,filename.gbk 是 gbk编码方式。
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
## 分词
|
|
8
|
+
|
|
9
|
+
### jieba.dict.utf8/gbk
|
|
10
|
+
|
|
11
|
+
作为最大概率法(MPSegment: Max Probability)分词所使用的词典。
|
|
12
|
+
|
|
13
|
+
格式固定为:
|
|
14
|
+
|
|
15
|
+
```text
|
|
16
|
+
词语 词频 词性
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
- 每行必须正好三列。
|
|
20
|
+
- `词频` 读取后会换算成对数权重。
|
|
21
|
+
- `词性` 以字符串形式保存在词典节点中,库本身不做枚举校验。
|
|
22
|
+
|
|
23
|
+
### hmm_model.utf8/gbk
|
|
24
|
+
|
|
25
|
+
作为隐式马尔科夫模型(HMMSegment: Hidden Markov Model)分词所使用的词典。
|
|
26
|
+
|
|
27
|
+
__对于MixSegment(混合MPSegment和HMMSegment两者)则同时使用以上两个词典__
|
|
28
|
+
|
|
29
|
+
### user.dict.utf8
|
|
30
|
+
|
|
31
|
+
用户词典示例。
|
|
32
|
+
|
|
33
|
+
支持以下三种行格式:
|
|
34
|
+
|
|
35
|
+
```text
|
|
36
|
+
词语
|
|
37
|
+
词语 词性
|
|
38
|
+
词语 词频 词性
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
- `1` 列表示只指定词语,使用默认权重,词性为空。
|
|
42
|
+
- `2` 列表示 `词语 词性`。
|
|
43
|
+
- `3` 列表示 `词语 词频 词性`。
|
|
44
|
+
- 可以通过 `|` 或 `;` 传入多个用户词典文件路径。
|
|
45
|
+
- 不支持注释语法、额外列或带空格的词语字段。
|
|
46
|
+
|
|
47
|
+
当前默认权重来自主词典统计值,默认使用中位数权重;也可以在
|
|
48
|
+
`cppjieba::DictTrie` 构造时通过 `WordWeightMin`、`WordWeightMedian`、
|
|
49
|
+
`WordWeightMax` 调整策略。
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
## 关键词抽取
|
|
53
|
+
|
|
54
|
+
### idf.utf8
|
|
55
|
+
|
|
56
|
+
IDF(Inverse Document Frequency)
|
|
57
|
+
在KeywordExtractor中,使用的是经典的TF-IDF算法,所以需要这么一个词典提供IDF信息。
|
|
58
|
+
|
|
59
|
+
### stop_words.utf8
|
|
60
|
+
|
|
61
|
+
停用词词典
|
|
62
|
+
|