parentDocument()

parentDoc() → { winkNLP doc }

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

Example:

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 );

sentence.parentDocument()

// It was released on March 24, 1972.
const sentence = doc.sentences().itemAt( 1 );
const sParentDoc = sentence.parentDocument().out();
console.log( sParentDoc );
// -> The Godfather premiered on March 15, 1972. It was released on
//    March 24, 1972.

entity.parentDocument()

const entity = doc.entities().itemAt( 0 ); // -> March 15, 1972
const eParentDoc = entity.parentDocument().out();
console.log( eParentDoc );
// -> The Godfather premiered on March 15, 1972. It was released on
//    March 24, 1972.

customEntity.parentDocument()

const customEntity = doc.customEntities().itemAt( 1 );
const cParentDoc = customEntity.parentDocument().out();
console.log( cParentDoc );
// -> The Godfather premiered on March 15, 1972. It was released on
//    March 24, 1972.

token.parentDocument()

const token = doc.tokens().itemAt( 9 ); // -> It
const tParentDoc = token.parentDocument().out();
console.log( tParentDoc );
// -> The Godfather premiered on March 15, 1972. It was released on
//    March 24, 1972.

Leave feedback