itemAt()

itemAt( index ) → { item }

This method accepts an index number as its parameter and returns the item from the collection at that position.

The index parameter could be 0, (length of the collection - 1) or any number between zero and length.

Without using the out() method, this will return a winkNLP item. It can be further chained with other methods. However, to get the output in a JavaScript data type, you need to follow this method with out().

Example:

const text = '#Breaking: Can’t get over this #Oscars selfie from @TheEllenShow🤩! Go check it out:)https://pic.twitter.com/C9U5NOtGap #Share your best selfie@r2d2@gmail.com💯';
const patterns = [
  { name: 'wordEmoji', patterns: [ '[|NOUN|PROPN|ADP] [EMOJI|EMOTICON]' ] },
  { name: 'emailEmoji', patterns: [ '[EMAIL] [EMOJI|EMOTICON]' ] },
  { name: 'mentionEmoji', patterns: [ '[MENTION] [EMOJI|EMOTICON]' ] }
];
nlp.learnCustomEntities( patterns );
const doc = nlp.readDoc( text );

const sentence = doc.sentences().itemAt( 1 );
console.log( sentence.out() );
// -> Go check it out:)https://pic.twitter.com/C9U5NOtGap #Share your best
//    selfie@r2d2@gmail.com💯

const entity = doc.entities().itemAt( 2 );
console.log( entity.out() );
// -> @TheEllenShow

const customEntity = doc.customEntities().itemAt( 2 );
console.log( customEntity.out() );
// -> r2d2@gmail.com💯

const token = doc.tokens().itemAt( 3 );
console.log( token.out() );
// -> n’t

Leave feedback