Package Exports
- compromise
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (compromise) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme

var nlp = require('compromise')
nlp('Wee-ooh, I look just like buddy holly.').sentences().toPastTense()
// 'Wee-ooh, I looked just like buddy holly.'
nlp('..then consider me Miles Davis!').people().out('freq')
// [{ text:'Miles Davis', count:1 }]
210kb
one javascript file
|
86%
on the Penn treebank
|
π
npm install compromise
|
IE9+
caniuse, youbetcha
|
Text in β data out.
without training, jargon or configDemos Usage API WTF
β‘οΈ on the Client-side
<script src="https://unpkg.com/compromise@latest/builds/compromise.min.js"></script>
<script>
var doc = nlp('dinosaur')
var str = doc.nouns().toPlural().out('text')
console.log(str)
// 'dinosaurs'
</script>
π Server-side!
var nlp = require('compromise')
var doc = nlp('London is calling')
doc.sentences().toNegative()
// 'London is not calling'
nouns! verbs! adjectives!
|
people, places, organizations
|
seven hundred and fifty == 750
|
like a regex for a sentence
|
all your base are belong
|
contractions, style, mood..
|
pop right in:
var doc= nlp(myNovel) //whoosh
doc.match('the #Superlative of times').length
|
API is bearable:
doc.contractions().expand()
doc.people().lastNames()
|
loosely-held opinions..
var ayeRight= require('nlp-scottish-slang')
nlp.plugin(ayeRight)
|
no foolin,
6 years, 150 PRs, 60 devs
in production in the United Nationsπ
|
Throw in text,
even if it's just one word:
var doc = nlp('Ludwig van Beethoven')
Grab a part:
query any pattern with .match(), or use built-in methods like .nouns(), or .people():doc.match('#TitleCase van #LastName').out()
// 'Ludwig van Beethoven'
doc.people().out('list')
// ['ludwig van beethoven']
Move stuff around:
- Plural/singular: - grab the noun-phrases, make em plural:
doc = nlp('a bottle of beer on the wall.')
doc.nouns().first().toPlural()
doc.out('text')
//'The bottles of beer on the wall.'
- Number parsing: - parse written-out numbers, and change their form:
doc = nlp('ninety five thousand and fifty two')
doc.values().toNumber().out('text')
// '95052'
doc = nlp('the 23rd of December')
doc.values().add(2).toText()
doc.out('text')
// 'the twenty fifth of December'
- Normalization: - handle the craziness:
doc = nlp("the guest-singer's bjΓΆrk at seven thirty.").normalize().out('text')
// 'The guest singer is Bjork at 7:30.'
- Tense: - switch between conjugations of any verb
let doc = nlp('she sells seashells by the seashore.')
doc.sentences().toFutureTense().out('text')
//'she will sell seashells...'
doc.verbs().conjugate()
// [{ PastTense: 'sold',
// Infinitive: 'sell',
// Gerund: 'selling', ...
// }]
- Contractions: - grab, expand and contract them:
doc = nlp("we're not gonna take it, no we ain't gonna take it.")
doc.has('going') // true
doc.match('are not').length // == 2
doc.contractions().expand().out()
//'we are not going to take it, no we are not going to take it'
- Named-entities: - get the people, places, organizations:
doc = nlp('that opera about richard nixon visiting china')
doc.topics().data()
// [
// { text: 'richard nixon' },
// { text: 'china' }
// ]
- Error correction: - make it say what you'd like:
var lexicon={
'boston': 'MusicalGroup'
}
doc = nlp('i heard Boston\'s set in Chicago', lexicon)
//alternatively, fix it all 'in-post':
doc.match('heard #Possessive set').terms(1).tag('MusicalGroup')
- Handy outputs: - get sensible data:
doc = nlp('We like Roy! We like Roy!').sentences().out('array')
// ['We like Roy!', 'We like Roy!']
doc = nlp('Tony Hawk').out('html')
/*
<span>
<span class="nl-Person nl-FirstName">Tony</span>
<span> </span>
<span class="nl-Person nl-LastName">Hawk</span>
</span>
*/
of course, there's a lot more stuff.
Join in - we're fun, using semver, and moving fast:
![]() Twitter
|
![]() Slack group
|
![]() Mailing-list
|
![]() Projects
|
![]() Pull-requests
|
π Can it run on my arduino-watch?
Only if it's water-proof!
Read quickStart for all sorts of funny environments.
β¨ Partial builds?
compromise can't really be tree-shaken, because it's one function.
.. and the tagging methods are competitive, so it's not recommended to pull things out.
It's best to load the library fully, given it's smaller than this gif.
A plug-in scheme is in the works.
Don't forget about:
- naturalNode - decidedly fancier, statistical nlp in javascript
- superScript - clever conversation engine in js
- nodeBox Linguistics - conjugation, inflection in javascript
- reText - very impressive text utilities in javascript
- jsPos - javascript build of the time-tested Brill-tagger
- spaCy - speedy, multilingual tagger in C/python
For the former promise-library, see jnewman/compromise (Thanks Joshua!)