Chuyển đến nội dung
Skillpedia
Lập trình chung12k · #11471

compromise-nlp

Skill này làm gì

Skill dạy AI dùng thư viện compromise để khớp từ, gắn nhãn từ loại và biến đổi câu. Skill dành cho lập trình viên JavaScript làm việc với văn bản tiếng Anh.

Khi nào nên dùng

  • ✓Khi bạn viết JavaScript để tìm danh từ, động từ hoặc tên trong văn bản tiếng Anh.
  • ✓Khi bạn muốn chuyển câu sang thì quá khứ hoặc chuẩn hóa văn bản bằng compromise.
  • ✓Khi bạn gỡ lỗi code compromise trả về kết quả không như mong đợi.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/spencermountain/compromise/blob/master/docs/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Bạn có thể giúp tôi viết JavaScript để lấy tên người từ một đoạn văn tiếng Anh không?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

AI chuyển văn bản thành tài liệu, gắn nhãn từng từ, rồi dùng các phương thức chọn lọc và biến đổi để tìm hoặc thay đổi các phần của nó.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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' })      
Câu hỏi thường gặp

Nó có cần dịch vụ AI hoặc truy cập internet không?

Không. Thư viện compromise chạy cục bộ, không cần mạng, mô hình hay phụ thuộc thêm.

Vì sao kết quả chỉ hiện một phần câu?

Các phép biến đổi thay đổi tài liệu tại chỗ và chỉ trả về phần đã chọn, nên hãy đọc toàn bộ văn bản từ biến tài liệu gốc.

Nó có hiểu nghĩa không?

Không hoàn toàn. Nó dùng gắn nhãn dựa trên quy tắc, nên không cung cấp hiểu biết ngữ nghĩa sâu.

Chi tiết

Mô tả gốc của tác giả

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

Độ phổ biến

Sao GitHub
12k
Vị trí xếp hạng
#11471
Giấy phép
MIT
Cập nhật
30/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự