-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathindex.d.ts
384 lines (337 loc) · 11.9 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
// Minimum TypeScript Version: 4.0
declare module 'wink-nlp' {
// turn off exporting by default since we don't want to expose internal details
export { };
// *** BEGIN Language Model Specific Declarations ***
// These should be always in sync with the langauge model's type declarations.
// these types are internal details of the implementing model
type StemAddon = unknown;
type LemmatizeAddon = unknown;
type ReadabilityStatsAddon = unknown;
type WordVectorsAddon = unknown;
// optional addons that some language models may have
export interface ModelAddons {
stem?: StemAddon;
lemmatize?: LemmatizeAddon;
readabilityStats?: ReadabilityStatsAddon;
wordVectors?: WordVectorsAddon;
}
// these types are internal details of the implementing model
type CoreModel = unknown;
type SBDModel = unknown;
type POSModel = unknown;
type NERModel = unknown;
type NEGATIONModel = unknown;
type SAModel = unknown;
type CERMetaModel = unknown;
type FeatureFn = unknown;
// A language model
export interface Model {
core: CoreModel;
sbd: SBDModel;
pos: POSModel;
ner: NERModel;
negation: NEGATIONModel;
sa: SAModel;
metaCER: CERMetaModel;
featureFn: FeatureFn;
addons: ModelAddons;
}
// *** END Language Model Specific Declarations ***
// its helpers
export type Case =
"other" |
"lowerCase" |
"upperCase" |
"titleCase";
export type PartOfSpeech =
"ADJ" |
"ADP" |
"ADV" |
"AUX" |
"CCONJ" |
"DET" |
"INTJ" |
"NOUN" |
"NUM" |
"PART" |
"PRON" |
"PROPN" |
"PUNCT" |
"SCONJ" |
"SYM" |
"VERB" |
"X" |
"SPACE";
// Bag of words
export interface Bow {
[index: string]: number;
}
export interface ReadabilityStats {
fres: number;
sentiment: number;
numOfTokens: number;
numOfWords: number;
numOfComplexWords: number;
complexWords: Bow;
numOfSentences: number;
readingTimeMins: number;
readingTimeSecs: number;
}
export interface Detail {
value: string;
type: string;
}
export interface SentenceImportance {
index: number;
importance: number;
}
export type ModelTermFrequencies = Bow;
export type ModelInverseDocumentFrequencies = Bow;
// internal types that will never be exposed directly to the user
type Cache = unknown;
type Token = unknown;
type RawDocumentData = unknown;
// Its
export interface ItsHelpers {
case(index: number, rdd: RawDocumentData): Case;
uniqueId(index: number, rdd: RawDocumentData): number;
negationFlag(index: number, rdd: RawDocumentData): boolean;
normal(index: number, rdd: RawDocumentData): string;
contractionFlag(index: number, rdd: RawDocumentData): boolean;
pos(index: number, rdd: RawDocumentData): PartOfSpeech;
precedingSpaces(index: number, rdd: RawDocumentData): string;
prefix(index: number, rdd: RawDocumentData): string;
shape(index: number, rdd: RawDocumentData): string;
stopWordFlag(index: number, rdd: RawDocumentData): boolean;
abbrevFlag(index: number, rdd: RawDocumentData): boolean;
suffix(index: number, rdd: RawDocumentData): string;
type(index: number, rdd: RawDocumentData): string;
value(index: number, rdd: RawDocumentData): string;
stem(index: number, rdd: RawDocumentData, addons: ModelAddons): string;
lemma(index: number, rdd: RawDocumentData, addons: ModelAddons): string;
vector(): number[];
detail(): Detail;
markedUpText(index: number, rdd: RawDocumentData): string;
span(spanItem: number[]): number[];
sentenceWiseImportance(rdd: RawDocumentData): SentenceImportance[];
sentiment(spanItem: number[]): number;
readabilityStats(rdd: RawDocumentData, addons: ModelAddons): ReadabilityStats;
terms(tf: ModelTermFrequencies, idf: ModelInverseDocumentFrequencies, terms: string[]): string[];
docTermMatrix(tf: ModelTermFrequencies, idf: ModelInverseDocumentFrequencies, terms: string[]): number[][];
docBOWArray(tf: ModelTermFrequencies): Bow;
bow(tf: ModelTermFrequencies): Bow;
idf(tf: ModelTermFrequencies, idf: ModelInverseDocumentFrequencies): Array<[term: string, frequency: number]>;
tf(tf: ModelTermFrequencies): Array<[term: string, frequency: number]>;
modelJSON(tf: ModelTermFrequencies, idf: ModelInverseDocumentFrequencies): string;
}
// As
export interface AsHelpers {
array<T>(tokens: T[]): T[];
set<T>(tokens: T[]): Set<T>;
bow(tokens: any[]): Bow;
freqTable<T>(tokens: T[]): Array<[token: T, freq: number]>;
bigrams<T>(tokens: T[]): Array<[T, T]>;
unique<T>(tokens: T[]): T[];
vector(token: string[]): number[];
}
// functions for use with document
export type TokenItsFunction<OutType> = (index: number, token: Token, cache: Cache, addons: ModelAddons) => OutType;
export type SpanItsFunction<OutType> = (spanItem: number[]) => OutType;
export type VectorizerItsFunction<OutType> = (tf: ModelTermFrequencies, idf: ModelInverseDocumentFrequencies) => OutType;
export type ItsFunction<OutType> = TokenItsFunction<OutType> | SpanItsFunction<OutType> | VectorizerItsFunction<OutType>;
export type AsFunction<InType, OutType> = (tokens: InType[]) => OutType;
export interface ItemToken {
parentDocument(): Document;
parentEntity(): ItemEntity | undefined;
parentCustomEntity(): ItemCustomEntity | undefined;
markup(beginMarker?: string, endMarker?: string): void;
out(): string;
out<T>(itsf: ItsFunction<T>): T | string;
parentSentence(): ItemSentence;
index(): number;
}
export interface SelectedTokens {
each(cb: ((item: ItemToken) => void) | ((item: ItemToken, index: number) => void)): void;
filter(cb: (item: ItemToken) => boolean): SelectedTokens;
itemAt(k: number): ItemToken;
length(): number;
out(): string[];
out<T>(itsf: ItsFunction<T>): T[] | string[];
out<T, U>(itsf: ItsFunction<T>, asf: AsFunction<T, U>): U | T[] | string[];
}
export interface Tokens {
each(cb: ((item: ItemToken) => void) | ((item: ItemToken, index: number) => void)): void;
filter(cb: (item: ItemToken) => boolean): SelectedTokens;
itemAt(k: number): ItemToken;
length(): number;
out(): string[];
out<T>(itsf: ItsFunction<T>): T[] | string[];
out<T, U>(itsf: ItsFunction<T>, asf: AsFunction<T, U>): U | T[] | string[];
}
export interface ItemEntity {
parentDocument(): Document;
markup(beginMarker?: string, endMarker?: string): void;
out(): string;
out<T>(itsf: ItsFunction<T>): T | string;
parentSentence(): ItemSentence;
tokens(): Tokens;
index(): number;
}
export interface SelectedEntities {
each(cb: ((item: ItemEntity) => void) | ((item: ItemEntity, index: number) => void)): void;
filter(cb: (item: ItemEntity) => boolean): SelectedEntities;
itemAt(k: number): ItemEntity;
length(): number;
out(): string[];
out<T>(itsf: ItsFunction<T>): T[] | string[];
out<T, U>(itsf: ItsFunction<T>, asf: AsFunction<T, U>): U | T[] | string[];
}
export interface Entities {
each(cb: ((item: ItemEntity) => void) | ((item: ItemEntity, index: number) => void)): void;
filter(cb: (item: ItemEntity) => boolean): SelectedEntities;
itemAt(k: number): ItemEntity;
length(): number;
out(): string[];
out<T>(itsf: ItsFunction<T>): T[] | string[];
out<T, U>(itsf: ItsFunction<T>, asf: AsFunction<T, U>): U | T[] | string[];
}
export interface ItemCustomEntity {
parentDocument(): Document;
markup(beginMarker?: string, endMarker?: string): void;
out(): string;
out<T>(itsf: ItsFunction<T>): T | string;
parentSentence(): ItemSentence;
tokens(): Tokens;
index(): number;
}
export interface SelectedCustomEntities {
each(cb: ((item: ItemCustomEntity) => void) | ((item: ItemCustomEntity, index: number) => void)): void;
filter(cb: (item: ItemCustomEntity) => boolean): SelectedCustomEntities;
itemAt(k: number): ItemCustomEntity;
length(): number;
out(): string[];
out<T>(itsf: ItsFunction<T>): T[] | string[];
out<T, U>(itsf: ItsFunction<T>, asf: AsFunction<T, U>): U | T[] | string[];
}
export interface CustomEntities {
each(cb: ((item: ItemCustomEntity) => void) | ((item: ItemCustomEntity, index: number) => void)): void;
filter(cb: (item: ItemCustomEntity) => boolean): SelectedCustomEntities;
itemAt(k: number): ItemCustomEntity;
length(): number;
out(): string[];
out<T>(itsf: ItsFunction<T>): T[] | string[];
out<T, U>(itsf: ItsFunction<T>, asf: AsFunction<T, U>): U | T[] | string[];
}
export interface ItemSentence {
parentDocument(): Document;
markup(beginMarker?: string, endMarker?: string): void;
out(): string;
out<T>(itsf: ItsFunction<T>): T | string;
entities(): Entities;
customEntities(): CustomEntities;
tokens(): Tokens;
index(): number;
}
export interface Sentences {
each(cb: ((item: ItemSentence) => void) | ((item: ItemSentence, index: number) => void)): void;
itemAt(k: number): ItemSentence;
length(): number;
out(): string[];
out<T>(itsf: ItsFunction<T>): T[] | string[];
out<T, U>(itsf: ItsFunction<T>, asf: AsFunction<T, U>): U | T[] | string[];
}
export interface Include {
lemma?: boolean;
specificWordVectors?: string[];
similarWordVectors?: boolean;
wordVectorsLimit?: number;
}
export interface Document {
entities(): Entities;
customEntities(): CustomEntities;
isLexeme(text: string): boolean;
isOOV(text: string): boolean;
out(): string;
out<T>(itsf: ItsFunction<T>): T | string;
sentences(): Sentences;
tokens(): Tokens;
printTokens(): void;
pipeConfig(): string[];
contextualVectors(include: Include): string;
}
export interface CerExample {
name: string;
patterns: string[];
}
export interface CerConfig {
matchValue?: boolean;
usePOS?: boolean;
useEntity?: boolean;
}
export interface CustomEntityExample {
name: string;
patterns: string[];
}
// Wink word embeddings structure, should stay in sync with emdedding repo.
interface WordEmbedding {
precision: number;
l2NormIndex: number;
wordIndex: number;
dimensions: number;
unkVector: number[];
size: number;
words: string[];
vectors: Record<string, number[]>;
}
export interface WinkMethods {
readDoc(text: string): Document;
// returns number of learned entities
learnCustomEntities(examples: CustomEntityExample[], config?: CerConfig): number;
vectorOf(word: string): number[];
its: ItsHelpers;
as: AsHelpers;
}
export default function WinkFn(theModel: Model, pipe?: string[], wordEmbeddings?: WordEmbedding): WinkMethods;
}
declare module 'wink-nlp/utilities/bm25-vectorizer' {
// turn off exporting by default since we don't want to expose internal details
export { };
import { Tokens, Document, ItsFunction, Bow } from 'wink-nlp';
export type Norm = "l1" | "l2" | "none";
export interface BM25VectorizerConfig {
k: number;
k1: number;
b: number;
norm: Norm;
}
export interface BM25Vectorizer {
learn(tokens: string[]): void;
out<T>(f: ItsFunction<T>): T;
doc(n: number): Document;
vectorOf(tokens: string[]): number[];
bowOf(tokens: string[]): Bow;
config(): BM25VectorizerConfig;
loadModel(json: string): void;
}
export default function bm25Vectorizer(config?: BM25VectorizerConfig): BM25Vectorizer;
}
declare module 'wink-nlp/utilities/similarity' {
// turn off exporting by default since we don't want to expose internal details
export { };
import { Bow } from 'wink-nlp';
export interface SimilarityHelper {
bow: {
cosine(bowA: Bow, bowB: Bow): number;
};
set: {
tversky<T>(setA: Set<T>, setB: Set<T>, alpha?: number, beta?: number): number;
oo<T>(setA: Set<T>, setB: Set<T>): number;
};
vector: {
cosine(vectorA: number[], vectorB: number[]): number;
};
}
const similarity: SimilarityHelper;
export default similarity;
}