-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update example in runkit and readme
- Loading branch information
1 parent
a074952
commit 90f978a
Showing
2 changed files
with
36 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ] ] |