Skip to content

Commit 6535d55

Browse files
committed
Update example code
1 parent 344aea2 commit 6535d55

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

lib/node_modules/@stdlib/nlp/lda/README.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,31 +98,35 @@ var words = model.getTerms( 0, 3 );
9898
<!-- eslint no-undef: "error" -->
9999

100100
```javascript
101-
var getSpeeches = require( '@stdlib/datasets/sotu' );
101+
var sotu = require( '@stdlib/datasets/sotu' );
102102
var roundn = require( '@stdlib/math/base/special/roundn' );
103-
var STOPWORDS = require( '@stdlib/datasets/stopwords-en' );
103+
var stopwords = require( '@stdlib/datasets/stopwords-en' );
104+
var lowercase = require( '@stdlib/string/lowercase' );
104105
var lda = require( '@stdlib/nlp/lda' );
105106

106107
var speeches;
108+
var words;
107109
var terms;
108110
var model;
109111
var str;
110112
var i;
113+
var j;
111114

112-
function getText( e ) {
113-
str = e.text.toLowerCase();
114-
STOPWORDS.forEach( remove );
115-
return str;
116-
117-
function remove( word ) {
118-
var RE = new RegExp( '\\b' + word + '\\b', 'gi' );
119-
str = str.replace( RE, '' );
120-
}
115+
words = stopwords();
116+
for ( i = 0; i < words.length; i++ ) {
117+
words[ i ] = new RegExp( '\\b'+words[ i ]+'\\b', 'gi' );
121118
}
122119

123-
speeches = getSpeeches({
120+
speeches = sotu({
124121
'range': [ 1930, 2010 ]
125-
}).map( getText );
122+
});
123+
for ( i = 0; i < speeches.length; i++ ) {
124+
str = lowercase( speeches[ i ].text );
125+
for ( j = 0; j < words.length; j++ ) {
126+
str = str.replace( words[ j ], '' );
127+
}
128+
speeches[ i ] = str;
129+
}
126130

127131
model = lda( speeches, 3 );
128132

0 commit comments

Comments
 (0)