本文へスキップ
Skillpedia
一般的なプログラミング12k · #11471

compromise-nlp

できること

AIに、compromiseライブラリを使って単語を照合し、品詞を付け、文を変換する方法を教えます。英語のテキストを扱うJavaScriptの開発者向けです。

使う場面

  • ✓英語の文章から名詞、動詞、人名を見つけるJavaScriptを書くとき。
  • ✓文を過去形に変えたり、compromiseでテキストを正規化したりしたいとき。
  • ✓compromiseのコードが予想と違う結果を返し、そのデバッグをするとき。

スキルのリンク

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

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/spencermountain/compromise/blob/master/docs/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“英語の文章から人名だけを取り出すJavaScriptを書く手伝いをしてもらえますか。”

毎週5つの新しいスキル。1分で読めます。

仕組み

AIはテキストをドキュメントに変換し、各単語に品詞を付け、選択と変換のメソッドを使って、テキストの一部を見つけたり変えたりします。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)を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' })      
よくある質問

AIサービスやインターネット接続は必要ですか?

いいえ。compromiseライブラリはネットワーク、モデル、追加の依存関係なしで、手元で動きます。

なぜ出力に文の一部しか表示されないのですか?

変換はドキュメントをその場で変更し、選択した部分だけを返すためです。元のドキュメントの変数から全文を読み取ってください。

意味を理解しますか?

完全には理解しません。ルールに基づく品詞付けを使うため、深い意味の理解は提供しません。

詳細

作者による元の説明

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

人気

GitHubのスター
12k
ランキング
#11471
ライセンス
MIT
更新日
2026/10/30

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル