File tree Expand file tree Collapse file tree 1 file changed +17
-13
lines changed
lib/node_modules/@stdlib/nlp/lda Expand file tree Collapse file tree 1 file changed +17
-13
lines changed Original file line number Diff line number Diff 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' );
102102var 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' );
104105var lda = require ( ' @stdlib/nlp/lda' );
105106
106107var speeches;
108+ var words;
107109var terms;
108110var model;
109111var str;
110112var 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
127131model = lda ( speeches, 3 );
128132
You can’t perform that action at this time.
0 commit comments