parentSentence()

parentSentence() → { winkNLP sentence}

This method returns the parent sentence of an entity, custom entity and token item. The sentence is returned in a winkNLP format and can either be chained with other winkNLP APIs or it can be followed by out() to get the sentence as a string.

Examples:

const text = 'The Godfather premiered on March 15, 1972. It was released on March 24, 1972.';
const patterns = [
 { name: 'event', patterns: [ '[VERB] [|ADP] [DATE|DURATION]' ] }
];
nlp.learnCustomEntities( patterns );
const doc = nlp.readDoc( text );

entity.parentSentence()

doc.entities()
  .each( ( e ) => {
    console.log( `Entity: ${ e.out() } \n Parent Sentence: ${ e.parentSentence().out() }` );
} );
// -> Entity: March 15, 1972
//    Parent Sentence: The Godfather premiered on March 15, 1972.
//    Entity: March 24, 1972
//    Parent Sentence: It was released on March 24, 1972.

customEntity.parentSentence()

doc.customEntities()
  .each( ( c ) => {
    console.log( `Custom Entity: ${ c.out() } \n Parent Sentence: ${ c.parentSentence().out() }` );
  } );
// -> Custom Entity: premiered on March 15, 1972
//    Parent Sentence: The Godfather premiered on March 15, 1972.
//    Custom Entity: released on March 24, 1972
//    Parent Sentence: It was released on March 24, 1972.

token.parentSentence()

const token = doc.tokens().itemAt( 9 ); // -> It
const tParentSentence = token.parentSentence().out();
console.log( tParentSentence );
// -> It was released on March 24, 1972.

Leave feedback