parentEntity()

parentEntity() → { winkNLP entity }

This method returns the parent entity (if any) of a token item, as only a token can have a parent entity. If there is no parent entity, it returns undefined.

The entity is returned in a winkNLP format and can either be chained with other winkNLP methods or followed by out() to get the entity as a string.

Example:

const text = 'The Godfather premiered on March 15, 1972. It was released on March 24, 1972.';
const doc = nlp.readDoc( text );

const token = doc.tokens().itemAt( 7 ); // -> 1972
const parentEntity = token.parentEntity();
console.log(`Token: ${ token.out() }, Parent entity: "${ parentEntity.out() }"`);
// -> Token: 1972, Parent entity: "March 15, 1972"

Leave feedback