Skip to content

Commit 4e709ea

Browse files
committed
Add namespace Typescript definition
1 parent ae288e6 commit 4e709ea

3 files changed

Lines changed: 156 additions & 0 deletions

File tree

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 2.0
20+
21+
/* tslint:disable:max-line-length */
22+
/* tslint:disable:max-file-line-count */
23+
24+
import expandContractions = require( '@stdlib/nlp/expand-contractions' );
25+
import lda = require( '@stdlib/nlp/lda' );
26+
import porterStemmer = require( '@stdlib/nlp/porter-stemmer' );
27+
import tokenize = require( '@stdlib/nlp/tokenize' );
28+
29+
/**
30+
* Interface describing the `nlp` namespace.
31+
*/
32+
interface Namespace {
33+
/**
34+
* Expands all contractions to their formal equivalents.
35+
*
36+
* @param str - string to convert
37+
* @returns string with expanded contractions
38+
*
39+
* @example
40+
* var str = 'I won\'t be able to get y\'all out of this one.';
41+
* var out = ns.expandContractions( str );
42+
* // returns 'I will not be able to get you all out of this one.'
43+
*
44+
* @example
45+
* var str = 'It oughtn\'t to be my fault, because, you know, I didn\'t know';
46+
* var out = ns.expandContractions( str );
47+
* // returns 'It ought not to be my fault, because, you know, I did not know'
48+
*/
49+
expandContractions: typeof expandContractions;
50+
51+
/**
52+
* Latent Dirichlet Allocation via collapsed Gibbs sampling.
53+
*
54+
* @param documents - document corpus
55+
* @param K - number of topics
56+
* @param options - options object
57+
* @param options.alpha - Dirichlet hyper-parameter of topic vector theta:
58+
* @param options.beta - Dirichlet hyper-parameter for word vector phi
59+
* @throws second argument must be a positive integer
60+
* @throws must provide valid options
61+
* @returns model object
62+
*/
63+
lda: typeof lda;
64+
65+
/**
66+
* Extracts the stem of a given word.
67+
*
68+
* @param word - input word
69+
* @returns word stem
70+
*
71+
* @example
72+
* var out = ns.porterStemmer( 'walking' );
73+
* // returns 'walk'
74+
*
75+
* @example
76+
* var out = ns.porterStemmer( 'walked' );
77+
* // returns 'walk'
78+
*
79+
* @example
80+
* var out = ns.porterStemmer( 'walks' );
81+
* // returns 'walk'
82+
*
83+
* @example
84+
* var out = ns.porterStemmer( 'worldwide' );
85+
* // returns 'worldwid'
86+
*
87+
* @example
88+
* var out = ns.porterStemmer( '' );
89+
* // returns ''
90+
*/
91+
porterStemmer: typeof porterStemmer;
92+
93+
/**
94+
* Tokenize a string.
95+
*
96+
* @param str - input string
97+
* @param keepWhitespace - boolean indicating whether whitespace characters should be returned as part of the token array (default: false)
98+
* @returns array of tokens
99+
*
100+
* @example
101+
* var str = 'Hello World!';
102+
* var out = ns.tokenize( str );
103+
* // returns [ 'Hello', 'World', '!' ]
104+
*
105+
* @example
106+
* var str = '';
107+
* var out = ns.tokenize( str );
108+
* // returns []
109+
*
110+
* @example
111+
* var str = 'Hello Mrs. Maple, could you call me back?';
112+
* var out = ns.tokenize( str );
113+
* // returns [ 'Hello', 'Mrs.', 'Maple', ',', 'could', 'you', 'call', 'me', 'back', '?' ]
114+
*/
115+
tokenize: typeof tokenize;
116+
}
117+
118+
/**
119+
* Standard library natural language processing.
120+
*/
121+
declare var ns: Namespace;
122+
123+
124+
// EXPORTS //
125+
126+
export = ns;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/* tslint:disable:no-unused-expression */
20+
21+
import nlp = require( './index' );
22+
23+
24+
// TESTS //
25+
26+
// The exported value is the expected interface...
27+
{
28+
nlp; // $ExpectType Namespace
29+
}

lib/node_modules/@stdlib/nlp/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"lib": "./lib",
2020
"test": "./test"
2121
},
22+
"types": "./docs/types",
2223
"scripts": {},
2324
"homepage": "https://github.com/stdlib-js/stdlib",
2425
"repository": {

0 commit comments

Comments
 (0)