modest natural-language processing in javascript
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
builds update deps, v11.13.0 Jan 9, 2019
data fix for Jan 5, 2019
demo fix for #554 Jan 5, 2019
docs Merge pull request #1 from fmacdonald/master Sep 20, 2018
scripts update deps, v11.13.0 Jan 9, 2019
src fixes for #558 Jan 9, 2019
test fixes for #558 Jan 9, 2019
.esformatter move tests around Feb 3, 2017
.eslintrc 10 tests failing Jul 5, 2017
.gitignore update deps Dec 4, 2018
.npmignore update deps Dec 4, 2018
.travis.yml move travis to node 6 Jul 25, 2018
LICENSE Create LICENSE Sep 7, 2017 11.12.6 Jan 5, 2019 update deps, v11.13.0 Jan 9, 2019
compromise.d.ts add unicode normalize again Jun 18, 2018 start another pass at ambiguous names Feb 2, 2018
package.json update deps, v11.13.0 Jan 9, 2019
scratch.js fixes for #558 Jan 9, 2019

modest natural-language processing in javascript
by Spencer Kelly and many contributors

save yourself from regex-whackamole🤞:

nlp(entireNovel).sentences().if('the #Adjective of times').out()
// "it was the blurst of times??"

move things around:

nlp('she sells seashells by the seashore.').sentences().toFutureTense().out()
// 'she will sell seashells...'

respond to text input:

if( doc.has('^simon says (shoot|fire) #Determiner lazer') ){
} else {
compromise is not the cleverest.
but it is small, quick, and good-enough for a bunch of stuff.

<script src>
        one javascript file        
    npm install compromise    
    on the Penn treebank    
      caniuse, youbetcha      

⚡️ on the Client-side

<script src=""></script>
  var doc = nlp('dinosaur')

  var str = doc.nouns().toPlural().out('text')
  // 'dinosaurs'

🌋 Server-side!

var nlp = require('compromise')

var doc = nlp('London is calling')
// 'London is not calling'
Get the hang of things:
Input → output
Match & transform
Making a bot
Detailed docs:


nouns! verbs! adjectives!
people, places, organizations
seven hundred and fifty == 750
like a regex for a sentence
all your base are belong
case, whitespace, contractions..
doc = nlp('a bottle of beer on the wall.')
//'The bottles of beer on the wall.'
doc = nlp('ninety five thousand and fifty two')
// '95052'

doc = nlp('the 23rd of December')
// 'the twenty fifth of December'
doc = nlp("the guest-singer's björk   at seven thirty.").normalize().out('text')
// 'The guest singer is Bjork at 7:30.'
  • Tense: - switch to/from conjugations of any verb
let doc = nlp('she sells seashells by the seashore.')
//'she will sell seashells...'

// [{ PastTense: 'sold',
//    Infinitive: 'sell',
//    Gerund: 'selling', ...
// }]
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
//'we are not going to take it, no we are not going to take it'
doc = nlp('the opera about richard nixon visiting china')
// [
//   { text: 'richard nixon' },
//   { text: 'china' }
// ]
var lexicon={
  'boston': 'MusicalGroup'
doc = nlp('i heard Boston\'s set in Chicago', lexicon)

//alternatively, fix it 'in-post':
doc.match('heard #Possessive set').terms(1).tag('MusicalGroup')
doc = nlp('We like Roy! We like Roy!').sentences().out('array')
// ['We like Roy!', 'We like Roy!']

doc = nlp('Tony Hawk').out('html')
  <span class="nl-Person nl-FirstName">Tony</span>
  <span class="nl-Person nl-LastName">Hawk</span>
  • Plugins: - allow adding vocabulary, fixing errors, and setting context quickly:
var plugin = {
      isA: 'Noun'
    itchy: 'Character',
    scratchy: 'Character'
nlp(`Couldn't Itchy share his pie with Scratchy?`).debug()
   couldn't   - #Modal, #Verb
   itchy      - #Character, #Noun
   share      - #Infinitive, #Verb

of course, there's a lot more stuff.

Join in - we're fun, using semver, and moving fast:

      Slack group      

    ☂️ Isn't javascript too...

      it wasn't built to compete with the stanford tagger, and may not fit every project.
      string stuff is synchronous too, and parallelizing is weird.
      See here for information about speed & performance, and here> for project motivations

    💃 Can it run on my arduino-watch?

      Only if it's water-proof!
      Read quickStart for all sorts of funny environments.

    🌎 Other Languages?

      we've got work-in-progress forks for German and French, in the same philosophy.
      Get involved!

    Partial builds?

      compromise is one function so can't really be tree-shaken.
      .. 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.


For the former promise-library, see jnewman/compromise (Thanks Joshua!)

(and don't forget 🙇 NLTK, GATE, Stanford, and Illinois libs )