Skip to content

πŸ§™πŸ½β€β™‚οΈ Visualize wink-nlp's features

License

Notifications You must be signed in to change notification settings

timturnerwhcc/showcase-wiz

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

winkNLP Wizard

built with winkNLP Gitter Follow on Twitter

All NLP Features from Text

This demo takes text and annotates it in real-time:

  • It tags all the Part of Speech tags and Entities in the text using the markup method.
  • It shows over-all statistics like number of tokens, words and sentences. To calculate the number of words it filters out all the tokens that have its.type as word.
  • For sentiment analysis it uses the its.sentiment helper.
  • Using the as helper it generates a table of all the words and their frequency of occurence

Wink Wizard Showcase

How to build this

const winkNLP = require('wink-nlp');
const its = require( 'wink-nlp/src/its.js' );
const as = require( 'wink-nlp/src/as.js' );
const model = require('wink-eng-lite-model');
const nlp = winkNLP(model);

var text = `Yesterday at 3am I was surfing http://twitter.com. I won a 100$ lottery for the first time. I spent 100% of it in just 1 hour :P Can you imagine that πŸ˜…? #yolo`;
var doc = nlp.readDoc(text);

// Entities
var entities = doc.entities().out(its.detail);

// Counts
var sentences = doc.sentences().length();
var tokens = doc.tokens().length();
var words = doc.tokens().filter( (token) => {
  return token.out(its.type) === 'word'
} ).length();

// Tagged text
var seenEntities = new Set();
doc.tokens().each( (token) => {
  var entity = token.parentEntity();
  if (entity === undefined) {
    if (token.out(its.type) === 'word') {
      token.markup('<span class=\"tag '+ token.out(its.pos) +'\">','</span>');
    }
  } else {
    if (!seenEntities.has(entity.index())) {
      entity.markup('<span class=\"tag '+ entity.out(its.type) +'\">', "</span>");
    }
    seenEntities.add(entity.index());
  }
} )

// Word frequency
var wordFreq = doc.tokens().filter((token) => {
  return token.out(its.type) === 'word' && !token.out(its.stopWordFlag);
}).out(its.normal, as.freqTable);
wordFreq = wordFreq.slice(0, 5)

// Sentiment
var sentiments = [];
doc.sentences().each((s) => {
  sentiments.push({
    sentence: s.out(),
    sentiment: s.out(its.sentiment)
  })
})

console.log(entities)
console.log(sentiments);
console.log(wordFreq);
console.log(doc.out(its.markedUpText));

About

πŸ§™πŸ½β€β™‚οΈ Visualize wink-nlp's features

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • CSS 42.8%
  • HTML 34.9%
  • JavaScript 22.3%