spencermountain / compromise

modest natural-language processing
http://compromise.cool
MIT License
11.31k stars 645 forks source link

`replaceWith()`s `keep.keepTags` not keeping tags when enabled #1120

Open Fdawgs opened 6 days ago

Fdawgs commented 6 days ago

Node version: 22.2.0 Compromise version: 14.13.0

Using replaceWith, with the keep.keepTags param property set to true, I would expect it to retain tags as documented.

Example:

'use strict'

/** @type {import('compromise').default} */
const nlp = require('compromise')

const text = 'Worst-case Ontario, you get caught.'

const doc = nlp(text)
console.log(doc.out('tags'))
/*
Prints:
[
  {
    worst: [ 'Adjective', 'Superlative', 'Hyphenated' ],
    case: [ 'Noun', 'Singular', 'Hyphenated' ],
    ontario: [ 'Noun', 'Singular', 'Place', 'ProperNoun', 'Region' ],
    you: [ 'Noun', 'Pronoun' ],
    get: [ 'Verb', 'PresentTense', 'Infinitive' ],
    caught: [ 'Verb', 'PastTense' ]
  }
]
*/

doc.match('Ontario').replaceWith('scenario', { keepTags: true })
console.log(doc.out('tags'))
/*
Prints:
[
  {
    worst: [ 'Adjective', 'Superlative', 'Hyphenated' ],
    case: [ 'Noun', 'Singular', 'Hyphenated' ],
    scenario: [ 'Noun', 'Singular' ],
    you: [ 'Noun', 'Pronoun' ],
    get: [ 'Verb', 'PresentTense', 'Infinitive' ],
    caught: [ 'Verb', 'PastTense' ]
  }
]

Expected:
[
  {
    worst: [ 'Adjective', 'Superlative', 'Hyphenated' ],
    case: [ 'Noun', 'Singular', 'Hyphenated' ],
    scenario: [ 'Noun', 'Singular', 'Place', 'ProperNoun', 'Region' ],
    you: [ 'Noun', 'Pronoun' ],
    get: [ 'Verb', 'PresentTense', 'Infinitive' ],
    caught: [ 'Verb', 'PastTense' ]
  }
]
  */