npm install compromise
interpret and match text:
let doc = nlp(entireNovel)
doc.match('the #Adjective of times').text()
// "the blurst of times?"
if (doc.has('simon says #Verb') === false) {
return null
}
conjugate and negate verbs in any tense:
let doc = nlp('she sells seashells by the seashore.')
doc.verbs().toPastTense()
doc.text()
// 'she sold seashells by the seashore.'
play between plural, singular and possessive forms:
let doc = nlp('the purple dinosaur')
doc.nouns().toPlural()
doc.text()
// 'the purple dinosaurs'
interpret plain-text numbers
nlp.extend(require('compromise-numbers'))
let doc = nlp('ninety five thousand and fifty two')
doc.numbers().add(2)
doc.text()
// 'ninety five thousand and fifty four'
names/places/orgs, tldr:
let doc = nlp(buddyHolly)
doc.people().if('mary').json()
// [{text:'Mary Tyler Moore'}]
let doc = nlp(freshPrince)
doc.places().first().text()
// 'West Phillidelphia'
doc = nlp('the opera about richard nixon visiting china')
doc.topics().json()
// [
// { text: 'richard nixon' },
// { text: 'china' }
// ]
handle implicit terms:
let doc = nlp("we're not gonna take it, no we ain't gonna take it.")
// match an implicit term
doc.has('going') // true
// transform
doc.contractions().expand()
dox.text()
// 'we are not going to take it, no we are not going to take it.'
Use it on the client-side:
<script src="https://unpkg.com/compromise"></script>
<script src="https://unpkg.com/compromise-numbers"></script>
<script>
nlp.extend(compromiseNumbers)
var doc = nlp('two bottles of beer')
doc.numbers().minus(1)
document.body.innerHTML = doc.text()
// 'one bottle of beer'
</script>
as an es-module:
import nlp from 'compromise'
var doc = nlp('London is calling')
doc.verbs().toNegative()
// 'London is not calling'
compromise is 180kb (minified):
it's pretty fast. It can run on keypress:
it works mainly by conjugating all forms of a basic word list.
The final lexicon is ~14,000 words:
you can read more about how it works, here. it's weird.
decide how words get interpreted:
let myWords = {
kermit: 'FirstName',
fozzie: 'FirstName',
}
let doc = nlp(muppetText, myWords)
or make heavier changes with a compromise-plugin.
const nlp = require('compromise')
nlp.extend((Doc, world) => {
// add new tags
world.addTags({
Character: {
isA: 'Person',
notA: 'Adjective',
},
})
// add or change words in the lexicon
world.addWords({
kermit: 'Character',
gonzo: 'Character',
})
// add methods to run after the tagger
world.postProcess(doc => {
doc.match('light the lights').tag('#Verb . #Plural')
})
// add a whole new method
Doc.prototype.kermitVoice = function () {
this.sentences().prepend('well,')
this.match('i [(am|was)]').prepend('um,')
return this
}
})
(these methods are on the nlp
object)
.json()
result(all match methods use the match-syntax.)
'wash-out'
'(939) 555-0113'
'#nlp'
'hi@compromise.cool'
:)
��
'@nlp_compromise'
'compromise.cool'
'quickly'
'he'
'but'
'of'
'Mrs.'
people()
+ places()
+ organizations()
"she would"
-> "she'd"
"Spencer's"
'FBI'
'eats, shoots, and leaves'
'football captain' → 'football captains'
'turnovers' → 'turnover'
's
to the end, in a safe manner.'will go' → 'went'
'walked' → 'walks'
'walked' → 'will walk'
'walks' → 'walk'
'walks' → 'walking'
'drive' → 'driven'
- otherwise simple-past ('walked')'went' → 'did not go'
"didn't study" → 'studied'
These are some helpful extensions:
npm install compromise-adjectives
quick
quick
to quickest
quick
to quicker
quick
to quickly
quick
to quicken
quick
to quickness
npm install compromise-dates
June 8th
or 03/03/18
2 weeks
or 5mins
4:30pm
or half past five
npm install compromise-numbers
25 kilos'
1/3rd
five
or fifth
5
or 5th
fifth
or 5th
five
or 5
'$2.50'
npm install compromise-export
npm install compromise-html
npm install compromise-hash
npm install compromise-keypress
npm install compromise-ngrams
npm install compromise-paragraphs
this plugin creates a wrapper around the default sentence objects.
npm install compromise-sentences
he walks
-> he walked
he walked
-> he walks
he walks
-> he will walk
he walks
-> he didn't walk
he doesn't walk
-> he walks
?
!
?
or !
!
?
.
npm install compromise-strict
npm install compromise-syllables
npm install compromise-penn-tags
we're committed to typescript/deno support, both in main and in the official-plugins:
import nlp from 'compromise'
import ngrams from 'compromise-ngrams'
import numbers from 'compromise-numbers'
const nlpEx = nlp.extend(ngrams).extend(numbers)
nlpEx('This is type safe!').ngrams({ min: 1 })
nlpEx('This is type safe!').numbers()
or if you don't care about POS-tagging, you can use the tokenize-only build: (90kb!)
<script src="https://unpkg.com/compromise/builds/compromise-tokenize.js"></script>
<script>
var doc = nlp('No, my son is also named Bort.')
//you can see the text has no tags
console.log(doc.has('#Noun')) //false
//the rest of the api still works
console.log(doc.has('my .* is .? named /^b[oa]rt/')) //true
</script>
slash-support:We currently split slashes up as different words, like we do for hyphens. so things like this don't work:nlp('the koala eats/shoots/leaves').has('koala leaves') //false
inter-sentence match:By default, sentences are the top-level abstraction.Inter-sentence, or multi-sentence matches aren't supported without a plugin:nlp("that's it. Back to Winnipeg!").has('it back')//false
nested match syntax:the
danger
beauty of regex is that you can recurse indefinitely.Our match syntax is much weaker. Things like this are not (yet) possible:doc.match('(modern (major|minor))? general')
complex matches must be achieved with successive .match() statements.
dependency parsing:Proper sentence transformation requires understanding the syntax tree of a sentence, which we don't currently do.We should! Help wanted with this.
en-pos - very clever javascript pos-tagger by Alex Corvi
naturalNode - fancier statistical nlp in javascript
compendium-js - POS and sentiment analysis in javascript
nodeBox linguistics - conjugation, inflection in javascript
reText - very impressive text utilities in javascript
superScript - conversation engine in js
jsPos - javascript build of the time-tested Brill-tagger
spaCy - speedy, multilingual tagger in C/python
Prose - quick tagger in Go by Joseph Kato
MIT
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/D 题意: 给出两段文字,以#为结束符,输出最长的公共单词串。 案例: input die einkommen der landwirte sind fuer die ab
Unit 5 - The Language of Compromise(妥协的语言) The Language of Compromise Leslie Dunkling "Let me give you one piece of advice," I said to Ted and Mary just before they got married a few years ago. "If yo
He refused to compromise his principles. 他拒绝放弃原则。 ---------------------------------------------------------------------- compromise表示放弃(原则等 compromise也可做一个不及物动词,表示妥协,让步。要说明在哪个方面妥协或让步就用介词on。 例: He refu
UVA323 Jury Compromise - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) 由于选择人数有限制(等于 \(m\)),因此考虑将人数设入动态规划的一维。 考虑目标是 \(D + P\) 最大,那么考虑背包,将 \(D + P\) 考虑成物品的总价值。 设 \(f(i, j, k)\),表示前 \(i\) 个人中选了 \(j\) 个人,\(D - P = k\),\
Jury Compromise Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39580 Accepted: 10718 Special Judge Description In Frobnia, a far-away country, the verdicts in court trials are determined b
Jury Compromise Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 29984 Accepted: 7993 Special Judge Description In Frobnia, a far-away country, the verdicts in court trials are determined by
题目简述:给定n个元素,其有a和b两种属性,从中选m个元素,使得属性a之和与属性b之和的差值最小,满足上述条件后再保证属性a之和与属性b之和的和最大。要求输出方案。 分析:先不考输出方案,就是个简单的dp题。因为数据范围较小,可以多开几个维度,先考虑一维f[i]表示前i个元素中挑的最小差值,然而发现不能递推,于是增加第二维表示差值,这样,f[i][j]表示从i个元素中挑出差值j是否可能。然后,考虑
解法2:动态规划 AC代码: //动态规划 #include <iostream> #include <cstring> #include <algorithm> using namespace std; #pragma warning(push) #pragma warning(disable:6385) //801:加20*20修正D-P的值-》直接用下标来表示当前的D-P int dp[21