Skip to content

winkjs/showcase-timeline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

16 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

winkNLP Timeline

built with winkNLP Gitter Follow on Twitter

Wikipedia Article to Timeline

This demo takes an article from English Wikipedia and converts it into a timeline. It does this by using the entity recognition in winkNLP. For all the DATEs that it finds it looks for the shapes that can be understood by the JavaScript Date object.

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 = "She was born in 1869. She died in 1940."

var doc = nlp.readDoc(text);
var timeline = [];
doc
  .entities()
  .filter((e) => {
    var shapes = e.tokens().out(its.shape);
    // We only want dates that can be converted to an actual
    // time using new Date()
    return (
      e.out(its.type) === 'DATE' &&
      (
        shapes[0] === 'dddd' ||
        ( shapes[0] === 'Xxxxx' && shapes[1] === 'dddd' ) ||
        ( shapes[0] === 'Xxxx' && shapes[1] === 'dddd' ) ||
        ( shapes[0] === 'dd' && shapes[1] === 'Xxxxx' && shapes[2] === 'dddd' ) ||
        ( shapes[0] === 'dd' && shapes[1] === 'Xxxx' && shapes[2] === 'dddd' ) ||
        ( shapes[0] === 'd' && shapes[1] === 'Xxxxx' && shapes[2] === 'dddd' ) ||
        ( shapes[0] === 'd' && shapes[1] === 'Xxxx' && shapes[2] === 'dddd' )
      )
    );
  })
  .each((e) => {
    e.markup();
    timeline.push({
      date: e.out(),
      unixTime: new Date(e.out()).getTime() / 1000,
      sentence: e.parentSentence().out(its.markedUpText)
    })
  });

timeline.sort((a, b) => {
  return a.unixTime - b.unixTime;
})

console.log(timeline);

Releases

No releases published

Packages

No packages published