entities()

entities() → { collection of entities }

This API returns a collection of entities. You can extract entities from a winkNLP document or you can call this API on a sentence item and extract a collection of entities from that sentence.

The raw text may have entities like date, ordinal, cardinal, money, percent, time, duration, hashtag, emoji, emoticon, email, url and mention. If the input text does not contain any entities, then an empty collection is returned. If the input text contains only a single entity, like a date or number, then a collection with single member is returned.

You can chain it further with other winkNLP APIs like each(), length(), filter(), etc. However, to get the output in a JavaScript data type, you need to follow this API with out().

Example:

const text = 'At 4:18 p.m. on July 20, 1969, a voice crackled from the speakers at NASA's Mission Control in Houston. He said simply, "the Eagle has landed." They spent nearly 21 hours on the lunar surface. Twenty percent of the world's population watched humans walk on the Moon for the first time. The space-mission was televised live in 33 countries. To know more, visit https://tinyurl.com/y85owr2u';
const doc = nlp.readDoc( text );

// Entities in winkNLP doc
const entities = doc.entities().out();
console.log( entities );
// -> [ '4:18 p.m.',
//      'July 20, 1969',
//      'nearly 21 hours',
//      'Twenty percent',
//      'first',
//      '33',
//      'https://tinyurl.com/y85owr2u' ]

// Entities in a sentence item
// Twenty percent of...first time (fourth sentence)
const sentence = doc.sentences().itemAt( 3 );
console.log( 'Entities in Sentence No.: 4' );
console.log( sentence.entities().out() );
// -> Entities in Sentence No.: 4
//    [ 'Twenty percent', 'first' ]

Leave feedback