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
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 }]
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 |
<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>
var nlp = require('compromise')
var doc = nlp('London is calling')
doc.sentences().toNegative()
// 'London is not calling'
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']
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.'
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'
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.'
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', ...
// }]
find the people, places, organizations:
doc = nlp('that opera about richard nixon visiting china')
doc.topics().data()
// [
// { text: 'richard nixon' },
// { text: 'china' }
// ]
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
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> </span>
<span class="nl-Person nl-LastName">Hawk</span>
</span>
*/
Twitter
|
Slack group
|
Mailing-list
|
Applications
|
Pull-requests
|
For the former promise-library, see jnewman/compromise (Thanks Joshua!)
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.