Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
compromise
Advanced tools
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()
}
<script src> |
🙏
npm install compromise
|
86%
on the Penn treebank
|
IE9+
caniuse, youbetcha
|
<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>
var nlp = require('compromise')
var doc = nlp('London is calling')
doc.sentences().toNegative()
// 'London is not calling'
Input → output
|
Match & transform
|
Making a bot
|
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.')
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.'
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> </span>
<span class="nl-Person nl-LastName">Hawk</span>
</span>
*/
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
...
*/
Twitter
|
Slack group
|
Mailing-list
|
Projects
|
Pull-requests
|
For the former promise-library, see jnewman/compromise (Thanks Joshua!)
11.10.0
honorifics
feature to .normalize().normalize()
now by defaultacronyms().stripPeriods()
and acronyms().addPeriods()
FAQs
modest natural language processing
The npm package compromise receives a total of 41,136 weekly downloads. As such, compromise popularity was classified as popular.
We found that compromise demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
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.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.