Socket
Socket
Sign inDemoInstall

compromise

Package Overview
Dependencies
Maintainers
2
Versions
169
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

compromise

natural language processing in the browser


Version published
Weekly downloads
52K
decreased by-5.79%
Maintainers
2
Weekly downloads
ย 
Created
Source
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
๐Ÿ™Œ you can do it!
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 the people, places, orgs..
Template-matches match natural-language forms Text cleanup contractions, hyphenation, punctuation

API docs ย  | ย  Demos

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'

Grab some words,

you can use pre-defined selections (like .nouns()) or grab any pattern with .match()

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

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

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

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

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:

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-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)
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 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>&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, 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 ๐Ÿ™‡ )

FAQs

Package last updated on 08 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc