-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathindex.d.ts
139 lines (135 loc) · 3.89 KB
/
index.d.ts
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
/* auto-generated by NAPI-RS */
/* eslint-disable */
export declare class Jieba {
/** Create a new instance with empty dict */
constructor()
/**
* Create a new instance with dict
*
* With the default dict, you can use `dict` from `@node-rs/jieba/dict`:
* ```js
* import { Jieba } from '@node-rs/jieba'
* import { dict } from '@node-rs/jieba/dict'
*
* const jieba = Jieba.withDict(dict)
* ```
*/
static withDict(dict: Uint8Array): Jieba
/** Load dictionary after initialization */
loadDict(dict: Uint8Array): void
/**
* Cut the input text
*
* ## Params
*
* `sentence`: input text
*
* `hmm`: enable HMM or not
*/
cut(sentence: string | Uint8Array, hmm?: boolean | undefined | null): string[]
/** Cut the input text asynchronously */
cutAsync(sentence: string | Uint8Array, hmm?: boolean | undefined | null, signal?: AbortSignal | undefined | null): Promise<unknown>
/**
* Cut the input text, return all possible words
*
* ## Params
*
* `sentence`: input text
*/
cutAll(sentence: string | Uint8Array): string[]
/**
* Cut the input text in search mode
*
* ## Params
*
* `sentence`: input text
*
* `hmm`: enable HMM or not
*/
cutForSearch(sentence: string | Uint8Array, hmm?: boolean | undefined | null): string[]
/**
* Tag the input text
*
* ## Params
*
* `sentence`: input text
*
* `hmm`: enable HMM or not
*/
tag(sentence: string | Uint8Array, hmm?: boolean | undefined | null): Array<TaggedWord>
}
export declare class TfIdf {
static withDict(dict: Uint8Array): TfIdf
/** Creates an TfIdf. */
constructor()
/**
* Merges entires from `dict` into the `idf_dict`.
* ```js
* import { Jieba, TfIdf } from '@node-rs/jieba';
*
* import { dict, idf } from '@node-rs/jieba/dict';
*
* // Create default Jieba instance
* const jieba = Jieba.withDict(dict);
*
* // Create TfIdf instance and load initial dictionary
* let initIdf = "生化学 13.900677652
";
* const tfidf = new TfIdf();
* tfidf.loadDict(Buffer.from(initIdf));
*
* // Extract keywords with initial dictionary
* const text = "生化学不是光化学的,";
* const topK = jieba.extract(text, 3);
* // Result would be like:
* // [
* // { keyword: '不是', weight: 4.6335592173333335 },
* // { keyword: '光化学', weight: 4.6335592173333335 },
* // { keyword: '生化学', weight: 4.6335592173333335 }
* // ]
*
* // Load new dictionary with different weights
* let newIdf = "光化学 99.123456789
";
* tfidf.loadDict(Buffer.from(newIdf));
*
* // Extract keywords again with updated dictionary
* const newTopK = jieba.extract(text, 3);
* // Result would be like:
* // [
* // { keyword: '不是', weight: 33.041152263 },
* // { keyword: '光化学', weight: 33.041152263 },
* // { keyword: '生化学', weight: 4.6335592173333335 }
* // ]
* ```
*/
loadDict(dict: Uint8Array): void
setConfig(config: KeywordExtractConfig): void
/**
* Uses TF-IDF algorithm to extract the `top_k` keywords from `sentence`.
*
* If `allowed_pos` is not empty, then only terms matching those parts if
* speech are considered.
*/
extractKeywords(jieba: Jieba, sentence: string, topK: number, allowedPos?: Array<string> | undefined | null): Array<Keyword>
}
export interface Keyword {
keyword: string
weight: number
}
/**
* Creates a KeywordExtractConfig state that contains filter criteria as
* well as segmentation configuration for use by keyword extraction
* implementations.
*/
export interface KeywordExtractConfig {
stopWords?: Set<string> | undefined
/** Any segments less than this length will not be considered a Keyword */
minKeywordLength?: number
/** If true, fall back to hmm model if segment cannot be found in the dictionary */
useHmm?: boolean
}
export interface TaggedWord {
tag: string
word: string
}