#1214·compromise

Inconsistent hyphenated word handling

Author: FdawgsCreated Aug 13, 2026Updated Aug 17, 2026
Labelsyesss

Node version: 22.22.3 Compromise version: 14.16.0

It is alluded to in the limitations in the readme that hyphenated words get split up, but this does not always occur and sometimes the words are merged instead.

Example:

javascript
'use strict'

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

console.log('\n1. "an x-ray was done" - only matches with the hyphen removed')
console.log('   x-ray:', nlp('an x-ray was done').has('x-ray')) // false
console.log('   xray:', nlp('an x-ray was done').has('xray')) // true

console.log('\n2. "she had covid-19" - only matches with the hyphen as a space')
console.log('   covid-19:', nlp('she had covid-19').has('covid-19')) // false
console.log('   covid 19:', nlp('she had covid-19').has('covid 19')) // true

console.log('\n3. "the x-ray-machine broke" - no spelling matches it at all')
console.log('   x-ray-machine:', nlp('the x-ray-machine broke').has('x-ray-machine')) // false
console.log('   x ray machine:', nlp('the x-ray-machine broke').has('x ray machine')) // false
console.log('   xraymachine:', nlp('the x-ray-machine broke').has('xraymachine')) // false
console.log('   xray machine:', nlp('the x-ray-machine broke').has('xray machine')) // false

console.log('\n4. same construction, different behaviour')
console.log('   pre-op:', nlp('booked for pre-op').has('pre-op')) // true
console.log('   preop:', nlp('booked for pre-op').has('preop')) // true
console.log('   post-op:', nlp('booked for post-op').has('post-op')) // true
console.log('   postop:', nlp('booked for post-op').has('postop')) // false

Console output:

1. "an x-ray was done" - only matches with the hyphen removed
   x-ray: false
   xray: true

2. "she had covid-19" - only matches with the hyphen as a space
   covid-19: false
   covid 19: true

3. "the x-ray-machine broke" - no spelling matches it at all
   x-ray-machine: false
   x ray machine: false
   xraymachine: false
   xray machine: false

4. same construction, different behaviour
   pre-op: true
   preop: true
   post-op: true
   postop: false

Source: spencermountain/compromise