JSPM

  • Created
  • Published
  • Downloads 135527
  • Score
    100M100P100Q152866F
  • License MIT

natural language processing in the browser

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

natural language processing, actually in the browser
by Spencer Kelly and contributors

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 }]
210k
    one javascript file    
86%
    on the Penn treebank    
πŸ™
  npm install compromise  
IE9+
    caniuse, youbetcha    

with deliberate, rule-based nlp,
compromise makes working with text easy
no jargon,   |   no config,   |   no training
Part-of-Speech tags nouns, verbs, adjectives.. Verb conjugation change tense of a verb or sentence
Number parsing seven hundred and fifty -> 750 Named-entities all the people, places, orgs..
Template-matches match natural-language forms Text cleanup contractions, hyphenation, punctuation
πŸ™Œ you can do it!

API docs   |   Demos list

Client-side!

<script src="https://unpkg.com/compromise@latest/builds/compromise.min.js"></script>
<script>
  var doc = nlp('dinosaur')

  doc.nouns().toPlural()
  console.log(doc.out('text'))
  // 'dinosaurs'
</script>

πŸŒ‹ Server-side!

var nlp = require('compromise')

var doc = nlp('London is calling')
doc.sentences().toNegative()
// 'London is not calling'

Grab some words,

the match() syntax lets you grab non-specific words or patterns:

doc = nlp('Ludwig van Beethoven wrote to Josephine Brunsvik')

doc.match('#TitleCase van #LastName').out()
// 'Ludwig van Beethoven'

doc.match('#PastTense to').hyphenate().out()
// 'wrote-to'

common match-patterns have handy methods like .nouns(), or .people(),

doc.people().out('list')
// ['ludwig van beethoven', 'josephine brunsvik']

Plural/singular:

grab your 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 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().toText()
doc.out('text')
// 'the twenty third of December'

Normalization:

some wrappers for common changes:

doc = nlp("the guest-singer's bjΓΆrk at seven thirty.").normalize().out('text')
// 'The guest singer is Bjork at 7:30.'

Tense:

all your base are belong:

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', ...
// }]

Named-entity spotting:

find 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)
doc.match('#MusicalGroup').length
// 1

//alternatively, fix it all 'in-post':
doc.match('heard #Possessive set').terms(1).tag('MusicalGroup')
doc.match('#MusicalGroup').length
// 1

Handy outputs:

get some 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>&nbsp;</span>
  <span class="nl-Person nl-LastName">Hawk</span>
</span>
*/

and yes, ofcourse, there's a lot more stuff.

Join in - we're fun, we're using semver, and moving fast. get involved

      Twitter      
      Slack group      
      Mailing-list      
      Applications      
      Pull-requests      

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!)

(also don't forget πŸ™‡ NLTK, GATE, Stanford, and Illinois toolkit ) ❀️️