{
  "schema": "leumas.docs.page/1",
  "id": "adapter:domain/nlp",
  "slug": "adapters/domain/nlp",
  "kind": "capabilities",
  "bucket": "package",
  "title": "nlp — natural-language analysis pack",
  "name": "nlp",
  "eyebrow": "natural-language analysis pack",
  "chip": null,
  "summary": "Natural-language analysis pack: statistical corpus analysis over text with zero ML dependencies. Lexicon-based sentiment (AFINN-style), RAKE/TF keyword extraction, extractive summarization, n-gram...",
  "keywords": [
    "nlp",
    "lexicon-based",
    "afinn-style",
    "stopword-profile",
    "word-frequency",
    "nlp api",
    "n-gram",
    "flesch"
  ],
  "audience": "both",
  "funnel": {
    "product": null,
    "cta": null
  },
  "body": "# nlp — natural-language analysis pack\n\nStatistical / lexicon-based corpus analysis over text. **Pure JS, zero npm deps, no ML models** —\neverything is deterministic (frequency counts, an AFINN-style lexicon, stopword profiles, Flesch\nformulas).\n\n## Tools\n\n| Tool | What it does |\n|---|---|\n| `sentiment({ text })` | Lexicon-based (AFINN-style, `data/afinn.json`) with negation flipping → `{ score, comparative, label:'positive'\\|'negative'\\|'neutral', positive:[], negative:[] }`. |\n| `keywords({ text, top=10 })` | RAKE-style keyword/keyphrase extraction (candidate phrases scored by word degree/frequency, stopwords excluded) → ranked terms with scores. |\n| `summarize({ text, sentences=3 })` | Extractive summary: sentences scored by content-word frequency, top-N returned **in original order**. |\n| `ngrams({ text, n=2, top? })` | n-gram frequency table. |\n| `languageDetect({ text })` | Stopword-profile heuristic across en/es/fr/de/it/pt/nl (+ `unknown`) → `{ language, confidence, scores }`. |\n| `readability({ text })` | Full **Flesch Reading Ease** + **Flesch-Kincaid grade**, syllable estimate, avg sentence length. |\n| `tokenize({ text, mode='word'\\|'sentence' })` | Word or sentence tokenization. |\n| `wordFrequency({ text, stopwords=true, top=20 })` | Word-frequency table (optionally excluding stopwords). |\n| `entities({ text })` | Heuristic entities: capitalized sequences → proper nouns, plus regex for emails / urls / dates / money / numbers, grouped. |\n| `stats({ text })` | chars / words / sentences / paragraphs / avgWordLength / uniqueRatio. |\n\n## Usage\n\n```js\nimport nlp from './index.js';\n\nnlp.adapters.sentiment({ text: 'I love this, it is great and wonderful' });\n// → { score: 10, comparative: 1.25, label: 'positive', positive: ['love','great','wonderful'], negative: [], tokens: 8 }\n\nnlp.adapters.languageDetect({ text: 'el gato está en la casa y la comida es muy buena' });\n// → { language: 'es', confidence: ..., scores: { en, es, fr, de, it, pt, nl } }\n\nnlp.adapters.readability({ text: 'The cat sat on the mat. It was a sunny day.' });\n// → { fleschReadingEase: <number>, fleschKincaidGrade: <number>, ... }\n```\n\nEvery tool takes one args object (`text` required) and returns a plain JSON-serializable object.\n\n## DRY boundary vs `domain/a-text`\n\n- **`a-text`** = per-string **transforms**: case conversion, base64, ciphers, digests, extraction,\n  a *basic* `readabilityScore`, and stemming on a single word/string.\n- **`nlp`** (this pack) = statistical **corpus analysis**: sentiment, keyword/summary extraction,\n  language detection, the **full** readability metrics (Flesch Reading Ease + Flesch-Kincaid grade,\n  where a-text only offers a basic readability score), n-grams, entity/stat roll-ups over a whole\n  document.\n\nRule of thumb: need a **number about the text** → `nlp`; need to **reshape a string** → `a-text`.\n\n## Data\n\n- `data/afinn.json` — ~230-word AFINN-style sentiment lexicon (scores -5..+5).\n- `data/stopwords.json` — English stopword list (shared by keywords / summarize / wordFrequency / entities).\n- `data/lang-profiles.json` — top-function-word profiles for the 7 detected languages.\n",
  "source": {
    "path": "shared/engines/adapters/domain/nlp/README.md",
    "blobSha": "",
    "commit": "",
    "committedAt": "",
    "provenance": "no-git",
    "bytes": 3377,
    "hash": "ec92783ac74db45d69430f59ef9e818aa1399bb5"
  },
  "urls": {
    "html": "/p/adapters/domain/nlp",
    "json": "/docs/adapters/domain/nlp.json",
    "md": "/docs/adapters/domain/nlp.md"
  },
  "links": {
    "composes": [],
    "usedBy": [],
    "product": [],
    "howTo": [],
    "skills": []
  }
}
