modest natural-language processing
okay -
compromise/one
A tokenizer of words, sentences, and punctuation.
```js import nlp from 'compromise/one' let doc = nlp("Wayne's World, party time") let data = doc.json() /* [{ normal:"wayne's world party time", terms:[{ text: "Wayne's", normal: "wayne" }, ... ] }] */ ``` compromise/one splits your text up, wraps it in a handy API,
compromise/two
A part-of-speech tagger, and grammar-interpreter.
```js import nlp from 'compromise/two' let doc = nlp("Wayne's World, party time") let str = doc.match('#Possessive #Noun').text() // "Wayne's World" ```
compromise/two automatically calculates the very basic grammar of each word. this is more useful than people sometimes realize. Light grammar helps you write cleaner templates, and get closer to the information. compromise has 83 tags, arranged in a handsome graph. #FirstName → #Person → #ProperNoun → #Noun you can see the grammar of each word by running `doc.debug()` you can see the reasoning for each tag with `nlp.verbose('tagger')`. if you prefer Penn tags, you can derive them with: ```js let doc = nlp('welcome thrillho') doc.compute('penn') doc.json() ```
compromise/three
Phrase and sentence tooling.
```js import nlp from 'compromise/three' let doc = nlp("Wayne's World, party time") let str = doc.people().normalize().text() // "wayne" ``` compromise/three is a set of tooling to zoom into and operate on parts of a text. `.numbers()` grabs all the numbers in a document, for example - and extends it with new methods, like `.subtract()`. When you have a phrase, or group of words, you can see additional metadata about it with `.json()` ```js let doc = nlp('four out of five dentists') console.log(doc.fractions().json()) /*[{ text: 'four out of five', terms: [ [Object], [Object], [Object], [Object] ], fraction: { numerator: 4, denominator: 5, decimal: 0.8 } } ]*/ ``` ```js let doc = nlp('$4.09CAD') doc.money().json() /*[{ text: '$4.09CAD', terms: [ [Object] ], number: { prefix: '$', num: 4.09, suffix: 'cad'} } ]*/ ``` ## For AI agents & LLMs Plain-text, copy-paste docs that render without JavaScript live in this repo: - **[AGENTS.md](./AGENTS.md)** — start here: mental model, rules, and gotchas - **[docs/concepts.md](./docs/concepts.md)** — the document/View/Term model, mutability, build tiers - **[docs/match-syntax.md](./docs/match-syntax.md)** — the `.match()` mini-language - **[docs/tags.md](./docs/tags.md)** — the complete, valid part-of-speech tagset - **[docs/api.md](./docs/api.md)** — every method, signature, and description - **[docs/recipes.md](./docs/recipes.md)** — solutions to common tasks - **[llms-full.txt](./docs/llms-full.txt)** — all of the above in one fetchable file ## API ### Compromise/one ##### Output - **[.text()](https://observablehq.com/@spencermountain/compromise-text)** - return the document as text - **[.json()](https://observablehq.com/@spencermountain/compromise-json)** - return the document as data - **[.debug()](https://observablehq.com/@spencermountain/compromise-output)** - pretty-print the interpreted document - **[.out()](https://observablehq.com/@spencermountain/compromise-output)** - a named or custom output - **[.html({})](https://observablehq.com/@spencermountain/compromise-html)** - output custom html tags for matches - **[.wrap({})](https://observablehq.com/@spencermountain/compromise-output)** - produce custom output for document matches ##### Utils - **[.found](https://observablehq.com/@spencermountain/compromise-utils)** _[getter]_ - is this document empty? - **[.docs](https://observablehq.com/@spencermountain/compromise-utils)** _[getter]_ get term objects as json - **[.length](https://observablehq.com/@spencermountain/compromise-utils)** _[getter]_ - count the # of characters in the document (string length) - **[.isView](https://observablehq.com/@spencermountain/compromise-utils)** _[getter]_ - identify a compromise object - **[.compute()](https://observablehq.com/@spencermountain/compromise-compute)** - run a named analysis on the document - **[.clone()](https://observablehq.com/@spencermountain/compromise-utils)** - deep-copy the document, so that no references remain - **[.termList()](https://observablehq.com/@spencermountain/compromise-accessors)** - return a flat list of all Term objects in match - **[.cache({})](https://observablehq.com/@spencermountain/compromise-cache)** - freeze the current state of the document, for speed-purposes - **[.uncache()](https://observablehq.com/@spencermountain/compromise-cache)** - un-freezes the current state of the document, so it may be transformed - **[.freeze({})](https://observablehq.com/@spencermountain/compromise-freeze)** - prevent any tags from being removed, in these terms - **[.unfreeze({})](https://observablehq.com/@spencermountain/compromise-freeze)** - allow tags to change again, as default ##### Accessors - **[.all()](https://observablehq.com/@spencermountain/compromise-utils)** - return the whole original document ('zoom out') - **[.terms()](https://observablehq.com/@spencermountain/compromise-selections)** - split-up results by each individual term - **[.first(n)](https://observablehq.com/@spencermountain/compromise-accessors)** - use only the first result(s) - **[.last(n)](https://observablehq.com/@spencermountain/compromise-accessors)** - use only the last result(s) - **[.slice(n,n)](https://observablehq.com/@spencermountain/compromise-accessors)** - grab a subset of the results - **[.eq(n)](https://observablehq.com/@spencermountain/compromise-accessors)** - use only the nth result - **[.firstTerms()](https://observablehq.com/@spencermountain/compromise-accessors)** - get the first word in each match - **[.lastTerms()](https://observablehq.com/@spencermountain/compromise-accessors)** - get the end word in each match - **[.fullSentences()](https://observablehq.com/@spencermountain/compromise-accessors)** - get the whole sentence for each match - **[.groups()](https://observablehq.com/@spencermountain/compromise-accessors)** - grab any named capture-groups from a match - **[.wordCount()](https://observablehq.com/@spencermountain/compromise-utils)** - count the # of terms in the document - **[.confidence()](https://observablehq.com/@spencermountain/compromise-utils)** - an average score for pos tag interpretations ##### Match _(match methods use the [match-syntax](https://docs.compromise.cool/compromise-match-syntax).)_ - **[.match('')](https://observablehq.com/@spencermountain/compromise-match)** - return a new Doc, with this one as a parent - **[.not('')](https://observablehq.com/@spencermountain/compromise-match)** - return all results except for this - **[.matchOne('')](https://observablehq.com/@spencermountain/compromise-match)** - return only the first match - **[.if('')](https://observablehq.com/@spencermountain/compromise-match)** - return each current phrase, only if it contains this match ('only') - **[.ifNo('')](https://observablehq.com/@spencermountain/compromise-match)** - Filter-out any current phrases that have this match ('notIf') - **[.has('')](https://observablehq.com/@spencermountain/compromise-match)** - Return a boolean if this match exists - **[.before('')](https://observablehq.com/@spencermountain/compromise-match)** - return all terms before a match, in each phrase - **[.after('')](https://observablehq.com/@spencermountain/compromise-match)** - return all terms after a match, in each phrase - **[.union()](https://observablehq.com/@spencermountain/compromise-set)** - return combined matches without duplicates - **[.intersection()](https://observablehq.com/@spencermountain/compromise-set)** - return only duplicate matches - **[.complement()](https://observablehq.com/@spencermountain/compromise-set)** - get everything not in another match - **[.settle()](https://observablehq.com/@spencermountain/compromise-set)** - remove overlaps from matches - **[.growRight('')](https://observablehq.com/@spencermountain/compromise-match)** - add any matching terms immediately after each match - **[.growLeft('')](https://observablehq.com/@spencermountain/compromise-match)** - add any matching terms immediately before each match - **[.grow('')](https://observablehq.com/@spencermountain/compromise-match)** - add any matching terms before or after each match - **[.sweep(net)](https://observablehq.com/@spencermountain/compromise-sweep)** - apply a series of match objects to the document - **[.splitOn('')](https://observablehq.com/@spencermountain/compromise-split)** - return a Document with three parts for every match ('splitOn') - **[.splitBefore('')](https://observablehq.com/@spencermountain/compromise-split)** - partition a phrase before each matching segment - **[.splitAfter('')](https://observablehq.com/@spencermountain/compromise-split)** - partition a phrase after each matching segment - **[.join()](https://observablehq.com/@spencermountain/compromise-split)** - merge any neighbouring terms in each match - **[.joinIf(leftMatch, rightMatch)](https://observablehq.com/@spencermountain/compromise-split)** - merg
No open issues yet, or sync has not completed.