Skills

Compromise Nlp

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

Install

npx skills add spencermountain/compromise --skill compromise-nlp -g -a claude-code -y
Category
Writing
Updated
5d ago
License
MIT
Context cost
Mediumabout 1,594 tokens
Runs scripts
No, instructions only

What it does

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.

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.

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:

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:

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

Read the whole SKILL.md on GitHub

More in Writing