Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Fdawgs opened this issue Jul 3, 2024 · 2 comments
Closed

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

Fdawgs opened this issue Jul 3, 2024 · 2 comments
Labels

Comments

@Fdawgs
Copy link
Contributor

Fdawgs commented Jul 3, 2024

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' ]
  }
]
  */
@Fdawgs Fdawgs changed the title replaceWith()s keep.keepTags not functioning as expected replaceWith()s keep.keepTags not keeping tags when enabled Jul 3, 2024
@spencermountain
Copy link
Owner

hey - you're right, this seems like a bug, to me.
Will put it on the pile!
cheers

@spencermountain
Copy link
Owner

hey Frazer, i don't remember when the API changed for this, but the usage now is { tags: true }:

const doc = nlp('Worst-case Ontario, you get caught.')
doc.match('Ontario').replaceWith('scenario', { tags: true })
doc.debug()

sorry for the delay, cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants