markup()

markup( beginTagopt, endTagopt ) → { void }

This API allows you to mark any item in winkNLP with your choice of tags like symbols, HTML tags, ANSI escape sequences, etc.

The tags can be changed according to the requirement. The default values are:

  • beginTag - <mark>
  • endTag - </mark>

While the markup() method returns nothing, you can view the marked up text in a JavaScript string format. Use the its.markedUpText() property as parameter for out().

You can only view the marked up text in a winkNLP doc, collection of sentences and sentence item.

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

sentence.markup()

const sentence = doc.sentences().itemAt( 0 );
sentence.markup();

// marked-up text in document
console.log( doc.out( its.markedUpText ) );
// -> <mark>The Godfather premiered on March 15, 1972.</mark> It was released
//    on March 24, 1972.

// marked-up text in collection of sentences
console.log( doc.sentences().out( its.markedUpText ) );
// -> [ '<mark>The Godfather premiered on March 15, 1972.</mark>',
//      'It was released on March 24, 1972.' ]

// marked-up text in sentence item
console.log( sentence.out( its.markedUpText ) );
// -> <mark>The Godfather premiered on March 15, 1972.</mark>

entity.markup()

doc.entities()
  .each( ( entity ) => {
    // Extract type of entity using .out() with “its.type” as input parameter.
    if( entity.out( its.type ) === 'DATE' ) {
      entity.markup();
    }
} );

// marked-up text in document
console.log( doc.out( its.markedUpText ) );
// -> The Godfather premiered on <mark>March 15, 1972</mark>. It was released
//    on <mark>March 24, 1972</mark>.

// marked-up text in collection of sentences
console.log( doc.sentences().out( its.markedUpText ) );
// -> [ 'The Godfather premiered on <mark>March 15, 1972</mark>.',
//      'It was released on <mark>March 24, 1972</mark>.']

// marked-up text in sentence item
console.log( doc.sentences().itemAt( 1 ).out( its.markedUpText ) );
// -> It was released on <mark>March 24, 1972</mark>.

customEntity.markup()

const customEntity = doc.customEntities().itemAt( 1 );
customEntity.markup();

// marked-up text in document
console.log( doc.out( its.markedUpText ) );
// -> The Godfather premiered on March 15, 1972. It was <mark>released on March 24, 1972</mark>.

// marked-up text in collection of sentences
console.log( doc.sentences().out( its.markedUpText ) );
// -> [ 'The Godfather premiered on March 15, 1972.',
//      'It was <mark>released on March 24, 1972</mark>.' ]

// marked-up text in sentence item
console.log( doc.sentences().itemAt( 1 ).out( its.markedUpText ) );
// -> It was <mark>released on March 24, 1972</mark>.

token.markup()

doc.tokens()
  .each( ( token ) => {
    // Extract type of entity using .out() with “its.type” as input parameter.
    if( token.out( its.type ) === 'number' ) {
      token.markup();
    }
} );

// marked-up text in document
console.log( doc.out( its.markedUpText ) );
// -> The Godfather premiered on March <mark>15</mark>, <mark>1972</mark>. It
//    was released on March <mark>24</mark>, <mark>1972</mark>.

//marked-up text in collection of sentences
console.log( doc.sentences().out( its.markedUpText ) );
// -> [ 'The Godfather premiered on March <mark>15</mark>, <mark>1972</mark>.',
//      'It was released on March <mark>24</mark>, <mark>1972</mark>.' ]

// marked-up text in sentence item
console.log( doc.sentences().itemAt( 1 ).out( its.markedUpText ) );
// -> It was released on March <mark>24</mark>, <mark>1972</mark>.

Leave feedback