Skip to content

Latest commit

Β 

History

History
74 lines (60 loc) Β· 2.96 KB

README.md

File metadata and controls

74 lines (60 loc) Β· 2.96 KB

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));