Skip to content

Commit

Permalink
chore: update example in runkit and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjayaksaxena committed Oct 13, 2022
1 parent a074952 commit 90f978a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,33 +69,33 @@ If you’re using winkNLP in the browser use the [wink-eng-lite-web-model](https
The "Hello World!" in winkNLP is given below:

```javascript
// Load wink-nlp package & helpers.
// Load wink-nlp package.
const winkNLP = require( 'wink-nlp' );
// Load "its" helper to extract item properties.
const its = require( 'wink-nlp/src/its.js' );
// Load "as" reducer helper to reduce a collection.
const as = require( 'wink-nlp/src/as.js' );
// Load english language model — light version.
const model = require( 'wink-eng-lite-model' );
// Load english language model.
const model = require( 'wink-eng-lite-web-model' );
// Instantiate winkNLP.
const nlp = winkNLP( model );

// Obtain "its" helper to extract item properties.
const its = nlp.its;
// Obtain "as" reducer helper to reduce a collection.
const as = nlp.as;

// NLP Code.
const text = 'Hello World🌎! How are you?';
const doc = nlp.readDoc( text );

console.log( doc.out() );
// -> Hello World🌎! How are you?

console.log( doc.sentences().out() );
// -> [ 'Hello World🌎!', 'How are you?' ]

console.log( doc.entities().out( its.detail ) );
// -> [ { value: '🌎', type: 'EMOJI' } ]

console.log( doc.tokens().out() );
// -> [ 'Hello', 'World', '🌎', '!', 'How', 'are', 'you', '?' ]

console.log( doc.tokens().out( its.type, as.freqTable ) );
// -> [ [ 'word', 5 ], [ 'punctuation', 2 ], [ 'emoji', 1 ] ]
```
Expand Down
37 changes: 23 additions & 14 deletions runkit-example.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
// Load wink-nlp package.
const winkNLP = require( 'wink-nlp' );
const its = require( 'wink-nlp/src/its.js' );
// Use web model for RunKit.
// Load english language model — light version.
const model = require( 'wink-eng-lite-web-model' );
// Instantiate winkNLP.
const nlp = winkNLP( model );
// Obtain "its" helper to extract item properties.
const its = nlp.its;
// Obtain "as" reducer helper to reduce a collection.
const as = nlp.as;

const text = 'Its quarterly profits jumped 76% to $1.13 billion for the three months to December, from $639million of previous year.';
// NLP Code.
const text = 'Hello World🌎! How are you?';
const doc = nlp.readDoc( text );
// Print tokens.
console.log( doc.tokens().out() );
// Print each token's type.
console.log( doc.tokens().out( its.type ) );
// Print details of each entity.

console.log( doc.out() );
// -> Hello World🌎! How are you?

console.log( doc.sentences().out() );
// -> [ 'Hello World🌎!', 'How are you?' ]

console.log( doc.entities().out( its.detail ) );
// Markup entities along with their type for highlighting them in the text.
doc.entities().each( ( e ) => {
e.markup( '<mark>', `<sub style="font-weight:900"> ${e.out(its.type)}</sub></mark>` );
} );
// Render them as HTML via RunKit
doc.out( its.markedUpText );
// -> [ { value: '🌎', type: 'EMOJI' } ]

console.log( doc.tokens().out() );
// -> [ 'Hello', 'World', '🌎', '!', 'How', 'are', 'you', '?' ]

console.log( doc.tokens().out( its.type, as.freqTable ) );
// -> [ [ 'word', 5 ], [ 'punctuation', 2 ], [ 'emoji', 1 ] ]

0 comments on commit 90f978a

Please sign in to comment.