@vdegenne/kuromoji-core 0.1.2 → 0.1.3

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.
Files changed (2) hide show
  1. package/package.json +3 -1
  2. package/src/kuromoji.d.ts +185 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vdegenne/kuromoji-core",
3
3
  "description": "Core Kuromoji.js engine with support for .dat and .dat.gz dictionaries and loading progress tracking.",
4
- "version": "0.1.2",
4
+ "version": "0.1.3",
5
5
  "browser": {
6
6
  "./src/loader/NodeDictionaryLoader.js": "./src/loader/BrowserDictionaryLoader.js"
7
7
  },
@@ -11,11 +11,13 @@
11
11
  "files": [
12
12
  "src/"
13
13
  ],
14
+ "types": "./src/kuromoji.d.ts",
14
15
  "dependencies": {
15
16
  "async": "^2.0.1",
16
17
  "doublearray": "0.0.2"
17
18
  },
18
19
  "devDependencies": {
20
+ "@types/kuromoji": "^0.1.3",
19
21
  "browserify": "^16.1.1",
20
22
  "chai": "^4.1.2",
21
23
  "coveralls": "^3.0.0",
@@ -0,0 +1,185 @@
1
+ /// <reference types="doublearray" />
2
+
3
+ // dict/ConnectionCosts.js
4
+ export interface ConnectionCosts {
5
+ buffer: Int16Array
6
+ put(forward_id: number, backward_id: number, cost: number): void
7
+ get(forward_id: number, backward_id: number): number
8
+ loadConnectionCosts(connection_costs_buffer: Int16Array): void
9
+ }
10
+
11
+ // dict/DynamicDictionaries.js
12
+ export interface DynamicDictionaries {
13
+ trie: doublearray.DoubleArray
14
+ token_info_dictionary: TokenInfoDictionary
15
+ connection_costs: ConnectionCosts
16
+ unknown_dictionary: UnknownDictionary
17
+ loadTrie(
18
+ base_buffer: Int32Array,
19
+ check_buffer: Int32Array,
20
+ ): DynamicDictionaries
21
+ }
22
+
23
+ // dict/TokenInfoDictionary.js
24
+ export interface TokenInfoDictionary {
25
+ buildDictionary(entries: any[][]): {[word_id: number]: string}
26
+ put(
27
+ left_id: number,
28
+ right_id: number,
29
+ word_cost: number,
30
+ surface_form: string,
31
+ feature: string,
32
+ ): number
33
+ addMapping(source: number, target: number): void
34
+ targetMapToBuffer(): Uint8Array
35
+ loadDictionary(array_buffer: Uint8Array): TokenInfoDictionary
36
+ loadPosVector(array_buffer: Uint8Array): TokenInfoDictionary
37
+ loadTargetMap(array_buffer: Uint8Array): TokenInfoDictionary
38
+ getFeatures(token_info_id_str: string): string
39
+ }
40
+
41
+ // dict/UnknownDictionary.js
42
+ export type UnknownDictionary = TokenInfoDictionary
43
+
44
+ // util/ByteBuffer.js
45
+ export interface ByteBuffer {
46
+ buffer: Uint8Array
47
+ position: number
48
+ size(): number
49
+ reallocate(): void
50
+ shrink(): Uint8Array
51
+ put(b: number): void
52
+ get(index: number): number
53
+ putShort(num: number): void
54
+ getShort(index: number): number
55
+ putInt(num: number): void
56
+ getInt(index: number): number
57
+ readInt(): number
58
+ putString(str: string): void
59
+ getString(index: number): string
60
+ }
61
+
62
+ // util/DictionaryBuilder.js
63
+ export interface DictionaryBuilder {
64
+ tid_entries: string[]
65
+ unk_entries: string[]
66
+ addTokenInfoDictionary(text: string): DictionaryBuilder
67
+ costMatrix(matrix_text: string): DictionaryBuilder
68
+ charDef(char_text: string): DictionaryBuilder
69
+ unkDef(text: string): DictionaryBuilder
70
+ build(): DynamicDictionaries
71
+ buildTokenInfoDictionary(): {
72
+ trie: doublearray.DoubleArray
73
+ token_info_dictionary: TokenInfoDictionary
74
+ }
75
+ buildUnknownDictionary(): UnknownDictionary
76
+ buildConnectionCosts(): ConnectionCosts
77
+ buildDoubleArray(): doublearray.DoubleArray
78
+ }
79
+
80
+ // util/IpadicFormatter.js
81
+ export interface Formatter<T> {
82
+ formatEntry(
83
+ word_id: number,
84
+ position: number,
85
+ type: string,
86
+ features: string[],
87
+ ): T
88
+ formatUnknownEntry(
89
+ word_id: number,
90
+ position: number,
91
+ type: string,
92
+ features: string[],
93
+ ): T
94
+ }
95
+ export type IpadicFormatter = Formatter<IpadicFeatures>
96
+
97
+ export interface IpadicFeatures {
98
+ word_id: number
99
+ word_type: string
100
+ word_position: number
101
+ surface_form: string
102
+ pos: string
103
+ pos_detail_1: string
104
+ pos_detail_2: string
105
+ pos_detail_3: string
106
+ conjugated_type: string
107
+ conjugated_form: string
108
+ basic_form: string
109
+ reading?: string | undefined
110
+ pronunciation?: string | undefined
111
+ }
112
+
113
+ // viterbi/ViterbiBuilder.js
114
+ export interface ViterbiBuilder {
115
+ trie: doublearray.DoubleArray
116
+ token_info_dictionary: TokenInfoDictionary
117
+ unknown_dictionary: UnknownDictionary
118
+ build(sentence_str: string): ViterbiLattice
119
+ }
120
+
121
+ // viterbi/ViterbiLattice.js
122
+ export interface ViterbiLattice {
123
+ append(node: ViterbiNode): void
124
+ appendEos(): void
125
+ }
126
+
127
+ // viterbi/ViterbiNode.js
128
+ export interface ViterbiNode {
129
+ name: string
130
+ cost: number
131
+ start_pos: number
132
+ length: number
133
+ left_id: number
134
+ right_id: number
135
+ prev: ViterbiNode
136
+ surface_form: string
137
+ shortest_cost: number
138
+ type: string
139
+ }
140
+
141
+ // viterbi/ViterbiSearcher.js
142
+ export interface ViterbiSearcher {
143
+ connection_costs: ConnectionCosts
144
+ search(lattice: ViterbiLattice): ViterbiNode[]
145
+ forward(lattice: ViterbiLattice): ViterbiLattice
146
+ backward(lattice: ViterbiLattice): ViterbiNode[]
147
+ }
148
+
149
+ // Tokenizer.js
150
+ export interface TokenizerStatic {
151
+ splitByPunctuation(input: string): string[]
152
+ }
153
+ export interface Tokenizer<T> {
154
+ token_info_dictionary: TokenInfoDictionary
155
+ unknown_dictionary: UnknownDictionary
156
+ viterbi_builder: ViterbiBuilder
157
+ viterbi_searcher: ViterbiSearcher
158
+ formatter: Formatter<T>
159
+ tokenize(text: string): T[]
160
+ getLattice(text: string): ViterbiLattice
161
+ }
162
+
163
+ // TokenizerBuilder.js
164
+ export interface TokenizerBuilder<T> {
165
+ build(callback: (err: Error, tokenizer: Tokenizer<T>) => void): void
166
+ }
167
+ export interface DictionaryProgress {
168
+ loaded: number
169
+ total: number
170
+ lengthComputable: boolean
171
+ filesLoaded: number
172
+ filesTotal: number
173
+ }
174
+
175
+ export interface TokenizerBuilderOption {
176
+ dicPath?: string | undefined
177
+ dictFileFormat?: 'dat' | 'gz'
178
+ onProgress?: ((progress: DictionaryProgress) => void) | undefined
179
+ }
180
+
181
+ // kuromoji.js
182
+ export function builder(
183
+ option: TokenizerBuilderOption,
184
+ ): TokenizerBuilder<IpadicFeatures>
185
+ export function dictionaryBuilder(): DictionaryBuilder