|
| 1 | +// Load wink-nlp package. |
1 | 2 | const winkNLP = require( 'wink-nlp' ); |
2 | | -const its = require( 'wink-nlp/src/its.js' ); |
3 | | -// Use web model for RunKit. |
| 3 | +// Load english language model — light version. |
4 | 4 | const model = require( 'wink-eng-lite-web-model' ); |
| 5 | +// Instantiate winkNLP. |
5 | 6 | const nlp = winkNLP( model ); |
| 7 | +// Obtain "its" helper to extract item properties. |
| 8 | +const its = nlp.its; |
| 9 | +// Obtain "as" reducer helper to reduce a collection. |
| 10 | +const as = nlp.as; |
6 | 11 |
|
7 | | -const text = 'Its quarterly profits jumped 76% to $1.13 billion for the three months to December, from $639million of previous year.'; |
| 12 | +// NLP Code. |
| 13 | +const text = 'Hello World🌎! How are you?'; |
8 | 14 | const doc = nlp.readDoc( text ); |
9 | | -// Print tokens. |
10 | | -console.log( doc.tokens().out() ); |
11 | | -// Print each token's type. |
12 | | -console.log( doc.tokens().out( its.type ) ); |
13 | | -// Print details of each entity. |
| 15 | + |
| 16 | +console.log( doc.out() ); |
| 17 | +// -> Hello World🌎! How are you? |
| 18 | + |
| 19 | +console.log( doc.sentences().out() ); |
| 20 | +// -> [ 'Hello World🌎!', 'How are you?' ] |
| 21 | + |
14 | 22 | console.log( doc.entities().out( its.detail ) ); |
15 | | -// Markup entities along with their type for highlighting them in the text. |
16 | | -doc.entities().each( ( e ) => { |
17 | | - e.markup( '<mark>', `<sub style="font-weight:900"> ${e.out(its.type)}</sub></mark>` ); |
18 | | -} ); |
19 | | -// Render them as HTML via RunKit |
20 | | -doc.out( its.markedUpText ); |
| 23 | +// -> [ { value: '🌎', type: 'EMOJI' } ] |
| 24 | + |
| 25 | +console.log( doc.tokens().out() ); |
| 26 | +// -> [ 'Hello', 'World', '🌎', '!', 'How', 'are', 'you', '?' ] |
| 27 | + |
| 28 | +console.log( doc.tokens().out( its.type, as.freqTable ) ); |
| 29 | +// -> [ [ 'word', 5 ], [ 'punctuation', 2 ], [ 'emoji', 1 ] ] |
0 commit comments