@@ -15,14 +15,14 @@ static JIEBA: OnceCell<Jieba> = OnceCell::new();
15
15
static TFIDF_INSTANCE : OnceCell < TFIDF > = OnceCell :: new ( ) ;
16
16
17
17
#[ napi]
18
- fn load ( ) -> Result < ( ) > {
18
+ pub fn load ( ) -> Result < ( ) > {
19
19
assert_not_init ( ) ?;
20
20
let _ = JIEBA . get_or_init ( Jieba :: new) ;
21
21
Ok ( ( ) )
22
22
}
23
23
24
24
#[ napi]
25
- fn load_dict ( dict : Buffer ) -> Result < ( ) > {
25
+ pub fn load_dict ( dict : Buffer ) -> Result < ( ) > {
26
26
assert_not_init ( ) ?;
27
27
let mut readable_dict: & [ u8 ] = & dict;
28
28
JIEBA . get_or_init ( || {
@@ -50,7 +50,7 @@ fn assert_not_init() -> Result<()> {
50
50
}
51
51
52
52
#[ napi( ts_return_type = "string[]" ) ]
53
- fn cut ( env : Env , sentence : Either < String , Buffer > , hmm : Option < bool > ) -> Result < Array > {
53
+ pub fn cut ( env : Env , sentence : Either < String , Buffer > , hmm : Option < bool > ) -> Result < Array > {
54
54
let hmm = hmm. unwrap_or ( false ) ;
55
55
let jieba = JIEBA . get_or_init ( Jieba :: new) ;
56
56
let cutted = jieba. cut (
@@ -66,7 +66,7 @@ fn cut(env: Env, sentence: Either<String, Buffer>, hmm: Option<bool>) -> Result<
66
66
}
67
67
68
68
#[ napi( ts_return_type = "string[]" ) ]
69
- fn cut_all ( env : Env , sentence : Either < String , Buffer > ) -> Result < Array > {
69
+ pub fn cut_all ( env : Env , sentence : Either < String , Buffer > ) -> Result < Array > {
70
70
let jieba = JIEBA . get_or_init ( Jieba :: new) ;
71
71
let cutted = jieba. cut_all ( match & sentence {
72
72
Either :: A ( s) => s. as_str ( ) ,
@@ -79,7 +79,11 @@ fn cut_all(env: Env, sentence: Either<String, Buffer>) -> Result<Array> {
79
79
}
80
80
81
81
#[ napi( ts_return_type = "string[]" ) ]
82
- fn cut_for_search ( env : Env , sentence : Either < String , Buffer > , hmm : Option < bool > ) -> Result < Array > {
82
+ pub fn cut_for_search (
83
+ env : Env ,
84
+ sentence : Either < String , Buffer > ,
85
+ hmm : Option < bool > ,
86
+ ) -> Result < Array > {
83
87
let hmm = hmm. unwrap_or ( false ) ;
84
88
let jieba = JIEBA . get_or_init ( Jieba :: new) ;
85
89
let cutted = jieba. cut_for_search (
@@ -96,13 +100,13 @@ fn cut_for_search(env: Env, sentence: Either<String, Buffer>, hmm: Option<bool>)
96
100
}
97
101
98
102
#[ napi( object) ]
99
- struct TaggedWord {
103
+ pub struct TaggedWord {
100
104
pub tag : String ,
101
105
pub word : String ,
102
106
}
103
107
104
108
#[ napi]
105
- fn tag ( sentence : Either < String , Buffer > , hmm : Option < bool > ) -> Result < Vec < TaggedWord > > {
109
+ pub fn tag ( sentence : Either < String , Buffer > , hmm : Option < bool > ) -> Result < Vec < TaggedWord > > {
106
110
let jieba = JIEBA . get_or_init ( Jieba :: new) ;
107
111
let tagged = jieba. tag (
108
112
match & sentence {
@@ -132,7 +136,7 @@ pub struct Keyword {
132
136
}
133
137
134
138
#[ napi]
135
- fn extract (
139
+ pub fn extract (
136
140
sentence : Either < String , Buffer > ,
137
141
topn : u32 ,
138
142
allowed_pos : Option < String > ,
@@ -176,7 +180,7 @@ fn extract(
176
180
}
177
181
178
182
#[ napi( js_name = "loadTFIDFDict" ) ]
179
- fn load_tfidf_dict ( dict : Buffer ) -> Result < ( ) > {
183
+ pub fn load_tfidf_dict ( dict : Buffer ) -> Result < ( ) > {
180
184
let mut readable_dict: & [ u8 ] = & dict;
181
185
if TFIDF_INSTANCE . get ( ) . is_some ( ) {
182
186
return Err ( Error :: new (
0 commit comments