You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP β†’
Socket
Book a DemoInstallSign in
Socket

github.com/nlp-compromise/compromise

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/nlp-compromise/compromise

v11.14.3+incompatible
Source
Go
Version published
Created
Source
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') ){
  fireLazer()
} else {
  dontFire()
}
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 Β  Β 
86%
Β  Β  on the Penn treebank Β  Β 
IE9+
Β  Β  Β  caniuse, youbetcha Β  Β  Β 

⚑️ 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'
Get the hang of things:
Input β†’ output
Match & transform
Making a bot
Detailed docs:

Examples:

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..
  • Plural/singular: - grab the noun-phrases, make em plural:
doc = nlp('a bottle of beer on the wall.')
doc.nouns(0).toPlural()
doc.out('text')
//'The bottles of beer on the wall.'
doc = nlp('ninety five thousand and fifty two')
doc.values().toNumber().out()
// '95052'

doc = nlp('the 23rd of December')
doc.values().add(2).toText()
doc.out('text')
// '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.')
doc.sentences().toFutureTense().out('text')
//'she will sell seashells...'

doc.verbs().conjugate()
// [{ 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
doc.contractions().expand().out()
//'we are not going to take it, no we are not going to take it'
doc = nlp('the opera about richard nixon visiting china')
doc.topics().data()
// [
//   { 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>
  <span class="nl-Person nl-FirstName">Tony</span>
  <span>&nbsp;</span>
  <span class="nl-Person nl-LastName">Hawk</span>
</span>
*/
  • Plugins: - allow adding vocabulary, fixing errors, and setting context quickly:
var plugin = {
  tags:{
    Character:{
      isA: 'Noun'
    }
  },
  words:{
    itchy: 'Character',
    scratchy: 'Character'
  }
}
nlp.plugin(plugin)
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:

Β  Β  Β  Β  Twitter Β  Β  Β  Β 
Β  Β  Β  Gitter chat Β  Β  Β 
Β  Β  Β  Stackoverflow Β  Β  Β 
Β  Β  Β  Β  Projects Β  Β  Β  Β 
Β  Β  Β  Pull-requests Β  Β  Β 

    β˜‚οΈ Isn't javascript too...

      yeah!
      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?

      okay!
      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.

Also:

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

(and don't forget πŸ™‡ NLTK, GATE, Stanford, and Illinois libs )

FAQs

Package last updated on 28 Aug 2019

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.