Aller au contenu
Skillpedia
Programmation générale12k · #11471

compromise-nlp

Ce qu’il fait

Cette compétence apprend à l'IA à utiliser la bibliothèque compromise pour trouver des mots, étiqueter les catégories grammaticales et transformer des phrases. Elle s'adresse aux développeurs JavaScript qui travaillent avec du texte anglais.

Quand l’utiliser

  • ✓Quand vous écrivez du JavaScript qui trouve des noms, des verbes ou des noms propres dans un texte anglais.
  • ✓Quand vous voulez mettre des phrases au passé ou normaliser un texte avec compromise.
  • ✓Quand vous déboguez du code compromise qui renvoie des résultats inattendus.

Lien du skill

https://github.com/spencermountain/compromise/blob/master/docs/SKILL.md

Copiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.

Comment l’utiliser

Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.

Message prêt à coller

Utilise ce skill pour m’aider : https://github.com/spencermountain/compromise/blob/master/docs/SKILL.md Lis le fichier SKILL.md de ce lien et suis ses instructions pour ma tâche.
Envie que votre IA trouve seule des skills comme celui-ci ?Installez le MCP gratuit de Skillpedia : une ligne, et elle cherche parmi 15 000+ skills avant chaque tâche.Installer en 1 minute →

Exemple de demande à votre IA

“Peux-tu m'aider à écrire du JavaScript qui extrait les noms de personnes d'un paragraphe de texte anglais ?”

5 nouveaux skills par semaine. 1 minute de lecture.

Comment ça marche

L'IA transforme le texte en document, étiquette chaque mot, puis utilise les méthodes de sélection et de transformation pour trouver ou modifier des parties du texte.

Contenu technique (SKILL.md original)

Texte original de l’auteur, en anglais, directement depuis GitHub.

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

There are ~88 valid part-of-speech tags, and they're a hierarchy (#FirstName ⊂ #Person ⊂ #Noun). A #Tag that isn't real does not error — it just matches nothing, which looks like a logic bug. Common inventions that are NOT tags: #Name, #Location, #Subject, #Object, #Adj, #Entity. (Valid ones include #Person, #Place, #Organization, #Noun, #Verb, #Value, #Date.) When unsure, check node_modules/compromise/docs/tag-definitions.md.

3. Match-syntax is term-level, not regex

.match() matches whole words/terms, not characters. + * ? . ^ $ operate on terms. For character-level patterns, use a /regex/ token. Cheat sheet (see references for the rest):

Token Means Example
#Tag a part-of-speech tag #Person
. any one term the . sat
* any run of terms the * sat
(a|b) one of these (cat|dog)
word? optional term the big? cat
#Tag+ one or more #Adjective+
! negate a term the !#Verb
[ ] / [<name> ] capture group [<who>#Person+]
^ / $ sentence start / end ^the / sat$
~word~ fuzzy / typo-tolerant ~organization~
{root} match all conjugations {walk} matches walked/walking
/regex/ character-level regex /colou?r/
nlp('John Smith left').match('[<who>#Person+]').groups('who').text()   // 'john smith'

4. Sentences are the ceiling — matches don't cross sentence boundaries

nlp("that's it. Back to Winnipeg!").has('it back') is false. For multi-sentence matching, use the compromise-paragraphs plugin.

5. compromise is the full build — import it unless size is critical

  • import nlp from 'compromise' — full library: .people(), .verbs(), .numbers(), all selections. Default.
  • import nlp from 'compromise/two' — POS tags + .match(), but no named selections.
  • import nlp from 'compromise/tokenize' (/one) — tokenize only, no tags (#Tag patterns won't work).

There's no useful tree-shaking below these tiers; run the full build.

Common tasks (verified patterns)

// entities
nlp(text).people().out('array')        // ['Mary', 'Dr. John Smith']
nlp(text).topics().out('array')        // people + places + organizations
// NOTE: out('array') keeps trailing punctuation ('Paris.'); use .text('normal') for clean tokens

// transform (remember rule #1 — read from doc)
let d = nlp('I walk'); d.verbs().toPastTense(); d.text()      // 'I walked'
let n = nlp('one dog'); n.nouns().toPlural(); n.text()        // 'one dogs'

// numbers
nlp('five hundred').numbers().toNumber().text()   // '500'
nlp('it cost twelve dollars').numbers().get()     // [12]

// find / route (boolean, never mutates)
nlp('the deal is closed').has('#Determiner #Noun')   // true

// teach it words
nlp(text, { kermit: 'FirstName' })      
Questions fréquentes

Faut-il un service d'IA ou un accès à internet ?

Non. La bibliothèque compromise fonctionne localement, sans réseau, sans modèle et sans dépendance supplémentaire.

Pourquoi ma sortie n'affiche-t-elle qu'une partie de la phrase ?

Les transformations modifient le document sur place et ne renvoient que la sélection. Il faut donc relire le texte complet depuis la variable du document d'origine.

Comprend-elle le sens ?

Pas complètement. Elle utilise un étiquetage à base de règles, donc elle n'offre pas une compréhension sémantique profonde.

Détails

Description originale de l’auteur

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 co

repo: spencermountain/compromise

Popularité

Étoiles GitHub
12k
Position au classement
#11471
Licence
MIT
Mis à jour
30/10/2026

Ce skill vous est-il utile ?

0

Connectez-vous pour voter.

Commentaires

  • …

Autres skills de ce dépôt

Skills similaires