# Compromise Nlp

Write correct code with the `compromise` JavaScript NLP library (the npm package...

- Repository: https://github.com/spencermountain/compromise (12169 stars)
- Category: Writing
- License: MIT
- Last updated: 2026-10-30
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add spencermountain/compromise --skill compromise-nlp -g -a claude-code -y`
Codex: `npx skills add spencermountain/compromise --skill compromise-nlp -g -a codex -y`
Cursor: `npx skills add spencermountain/compromise --skill compromise-nlp -g -a cursor -y`
Gemini CLI: `npx skills add spencermountain/compromise --skill compromise-nlp -g -a gemini-cli -y`

## Description

Write correct code with the `compromise` JavaScript NLP library (the npm package `compromise`, imported as `nlp`). Use this whenever you are writing or editing JS/TS that imports compromise, calls `nlp(...)`, or chains methods like `.match()`, `.tag()`, `.people()`, `.verbs()`, `.nouns()`, `.numbers()`, `.normalize()`, or `.replace()`, and also whenever doing rule-based natural-language tasks in JavaScript (extracting entities/dates/numbers, matching text patterns, changing verb tense, pluralizing, redacting/anonymizing text, building a simple chatbot intent matcher) where compromise is or could be the tool. compromise's match-syntax and tagset are non-obvious and easy to get wrong from memory; consult this skill before guessing.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Using compromise

`compromise` is a rule-based English NLP library for JavaScript (no network, no model, no deps).
You tokenize text into a **document**, it tags each word's part-of-speech, and you **find** and
**transform** parts of the text with a jQuery-like chained API.

```js
import nlp from 'compromise'

let doc = nlp('she sells seashells by the seashore.')
doc.verbs().toPastTense()        // transform
doc.text()                       // 'she sold seashells by the seashore.'
```

## The five rules that prevent almost every mistake

These are the things that are easy to get wrong from memory. Internalize them before writing code.

### 1. Transforms mutate the document in place, read the result from the original variable

Every transform method (`.toPastTense()`, `.replace()`, `.tag()`, `.normalize()`, case/whitespace
methods…) changes the underlying document. The View it *returns* is the selection it acted on, **not
the whole document**. So calling `.text()` on the chain gives you only the selected fragment:

```js
let doc = nlp('I walk to work')
doc.verbs().toPastTense()
doc.text()                                            // ✅ 'I walked to work'  (read from doc)

nlp('I walk to work').verbs().toPastTense().text()    // ❌ 'walked work'  (just the selection)
```

To transform a copy and leave the original untouched, call `.clone()` first:

```js
let past = doc.clone().verbs().toPastTense().text()
```

Read-only methods (`.match`, `.has`, `.if`, `.found`, `.text`, `.json`, accessors) never mutate.

### 2. Only real tags work, an invalid `#Tag` matches nothing, silently

The rest: https://github.com/spencermountain/compromise/blob/HEAD/docs/SKILL.md
