

npm install compromise

文字製作多麼簡單, 
↬ᔐᖜ實際解析和使用有多困難?

妥協盡力將文本轉變為數據。
它做出有限而明智的決定。
它並不像您想像的那麼聰明。 

import nlp from 'compromise'
let doc = nlp ( 'she sells seashells by the seashore.' )
doc . verbs ( ) . toPastTense ( )
doc . text ( )
// 'she sold seashells by the seashore.' 
if ( doc . has ( 'simon says #Verb' ) ) {
return true
} 

let doc = nlp ( entireNovel )
doc . match ( 'the #Adjective of times' ) . text ( )
// "the blurst of times?"

並獲取數據:
import plg from 'compromise-speech'
nlp . extend ( plg )
let doc = nlp ( 'Milwaukee has certainly had its share of visitors..' )
doc . compute ( 'syllables' )
doc . places ( ) . json ( )
/*
[{
"text": "Milwaukee",
"terms": [{
"normal": "milwaukee",
"syllables": ["mil", "wau", "kee"]
}]
}]
*/

避免脆性解析器的問題:
let doc = nlp ( "we're not gonna take it.." )
doc . has ( 'gonna' ) // true
doc . has ( 'going to' ) // true (implicit)
// transform
doc . contractions ( ) . expand ( )
doc . text ( )
// 'we are not going to take it..'
![]()
像數據一樣鞭打東西:
let doc = nlp ( 'ninety five thousand and fifty two' )
doc . numbers ( ) . add ( 20 )
doc . text ( )
// 'ninety five thousand and seventy two'
![]()
- 因為它實際上是 -
let doc = nlp ( 'the purple dinosaur' )
doc . nouns ( ) . toPlural ( )
doc . text ( )
// 'the purple dinosaurs'

在客戶端使用它:
< script src =" https://unpkg.com/compromise " > </ script >
< script >
var doc = nlp ( 'two bottles of beer' )
doc . numbers ( ) . minus ( 1 )
document . body . innerHTML = doc . text ( )
// 'one bottle of beer'
</ script >或同樣:
import nlp from 'compromise'
var doc = nlp ( 'London is calling' )
doc . verbs ( ) . toNegative ( )
// 'London is not calling' 
![]()
妥協是〜250KB (縮小):

很快。它可以在鍵盤上運行:

它主要通過結合基本單詞列表的所有形式來工作。
最後的詞典約為14,000個字:

您可以在此處閱讀更多有關其工作原理的信息。很奇怪。

好的 -
compromise/one單詞,句子和標點符號的tokenizer 。

import nlp from 'compromise/one'
let doc = nlp ( "Wayne's World, party time" )
let data = doc . json ( )
/* [{
normal:"wayne's world party time",
terms:[{ text: "Wayne's", normal: "wayne" },
...
]
}]
*/妥協/一個人將您的文本拆分,將其包裹在方便的API中,

/一個是快速的 - 大多數句子要佔毫秒的第十千分之一。
它可以執行〜1MB的文本一秒鐘 - 或10個Wikipedia頁面。
無限的玩笑需要3秒。

compromise/two part-of-speech 。

import nlp from 'compromise/two'
let doc = nlp ( "Wayne's World, party time" )
let str = doc . match ( '#Possessive #Noun' ) . text ( )
// "Wayne's World"
這比人們有時意識到的更有用。
輕語法可幫助您編寫清潔模板,並更接近信息。

妥協有83個標籤,以英俊的圖表排列。
#firstname → #person → #propernoun → #noun
您可以通過運行doc.debug()看到每個單詞的語法
您可以使用nlp.verbose('tagger')看到每個標籤的推理。
如果您喜歡Penn標籤,則可以通過以下方式得出以下方式。
let doc = nlp ( 'welcome thrillho' )
doc . compute ( 'penn' )
doc . json ( ) 
compromise/three Phrase和句子工具。

import nlp from 'compromise/three'
let doc = nlp ( "Wayne's World, party time" )
let str = doc . people ( ) . normalize ( ) . text ( )
// "wayne"妥協/三是一組工具,可以放大文本的各個部分。
.numbers() .subtract()
當您有一個短語或一組單詞時,您可以使用.json()看到其他元數據
let doc = nlp ( 'four out of five dentists' )
console . log ( doc . fractions ( ) . json ( ) )
/*[{
text: 'four out of five',
terms: [ [Object], [Object], [Object], [Object] ],
fraction: { numerator: 4, denominator: 5, decimal: 0.8 }
}
]*/ let doc = nlp ( '$4.09CAD' )
doc . money ( ) . json ( )
/*[{
text: '$4.09CAD',
terms: [ [Object] ],
number: { prefix: '$', num: 4.09, suffix: 'cad'}
}
]*/ 
(匹配方法使用Match-Syntax。)
(這些方法在主要的nlp對像上)
nlp.tokenize(str) - 解析文本而無需運行pos -tagging
nlp.lazy(str,匹配) - 通過最少分析的文本掃描
nlp.plugin({}) - 混合在妥協-plugin中
nlp.parsematch(str) - 將任何匹配語句預先放在JSON中
nlp.world() - 抓取或更改內部庫
NLP.Model() - 獲取所有當前的語言數據
NLP.Methods() - 抓取或更改內部方法
nlp.hooks() - 請參閱哪些計算方法自動運行
nlp.verbose(模式) - 記錄我們用於調試的決策
nlp.version-庫的當前SEMVER版本
nlp.addwords(obj,isfrozen?) - 在詞典中添加新單詞
NLP.ADDAGS(OBJ) - 在標籤集中添加新標籤
nlp.typeahead(arr) - 在自動填充詞典中添加單詞
nlp.buildtrie(arr) - 將單詞列表編譯成快速查找表單
nlp.buildnet(arr) - 將匹配列表彙編為快速匹配表格


'football captain' → 'football captains''turnovers' → 'turnover''will go' → 'went''walked' → 'walks''walked' → 'will walk''walks' → 'walk''walks' → 'walking''drive' → 'had driven''went' → 'did not go'"didn't study" → 'studied' 5fivefifth或5thfive或5'$2.50'之類的東西?!? ! 'quick''wash-out''(939) 555-0113'之類的東西'#nlp'之類的東西'[email protected]'之類的東西:)?'@nlp_compromise'之類的東西'compromise.cool'之類的東西'he'之類的東西'but'類的東西'of''Mrs.'之類的東西'quickly'之類的東西'FBI'之類的東西"Spencer's"之類的東西

該庫帶有英語語法的體貼,常識性的基線。
您可以自由地更改或浪費任何設置 - 這實際上是有趣的部分。
最簡單的部分只是建議任何給定單詞的標籤:
let myWords = {
kermit : 'FirstName' ,
fozzie : 'FirstName' ,
}
let doc = nlp ( muppetText , myWords )或通過妥協 - 氾濫進行更重的更改。
import nlp from 'compromise'
nlp . extend ( {
// add new tags
tags : {
Character : {
isA : 'Person' ,
notA : 'Adjective' ,
} ,
} ,
// add or change words in the lexicon
words : {
kermit : 'Character' ,
gonzo : 'Character' ,
} ,
// change inflections
irregulars : {
get : {
pastTense : 'gotten' ,
gerund : 'gettin' ,
} ,
} ,
// add new methods to compromise
api : View => {
View . prototype . kermitVoice = function ( ) {
this . sentences ( ) . prepend ( 'well,' )
this . match ( 'i [(am|was)]' ) . prepend ( 'um,' )
return this
}
} ,
} )


| 概念 | API | 插件 |
|---|---|---|
| 準確性 | 登入 | 形容詞 |
| 快取 | 構造方法方法 | 日期 |
| 案件 | 收縮 | 出口 |
| 文件大小 | 插入 | 哈希 |
| 內部 | JSON | html |
| 理由 | 角色偏移 | 按鍵 |
| 詞典 | 循環 | ngrams |
| 匹配syntax | 匹配 | 數字 |
| 表現 | 名詞 | 段落 |
| 插件 | 輸出 | 掃描 |
| 專案 | 選擇 | 句子 |
| 標記器 | 排序 | 音節 |
| 標籤 | 分裂 | 發音 |
| 令牌化 | 文字 | 嚴格的 |
| 指定性 | UTILS | 賓夕法尼亞州 |
| 空格 | 動詞 | 打字 |
| 世界數據 | 正常化 | 掃 |
| 模糊匹配 | 打字稿 | 突變 |
| 根形 |



這些是一些有用的擴展:
npm install compromise-dates
June 8th或03/03/182 weeks或5mins4:30pm或half past fivenpm install compromise-stats
.tfidf({}) - 按頻率和唯一性排名單詞
.ngrams({}) - 列出所有重複子名字,
.omigrams() - 一個單詞
.bigrams() - 兩個單詞的n -grams
.trigrams() - 帶有三個單詞的n -grams
.startgrams() - n -grams,包括短語的第一項
.endgrams() - n -grams,包括短語的最後一項
。
npm install compromise-syllables
npm install compromise-wikipedia

我們致力於在Main和官方Plugins中獲得打字稿/DENO的支持:
import nlp from 'compromise'
import stats from 'compromise-stats'
const nlpEx = nlp . extend ( stats )
nlpEx ( 'This is type safe!' ) . ngrams ( { min : 1 } )
Slash-Support:我們目前將Slash slash作為不同的單詞,就像我們為連字符所做的那樣。因此,像這樣的事情不起作用: nlp('the koala eats/shoots/leaves').has('koala leaves') //false
句子間匹配:默認情況下,句子是頂級抽象。沒有插件的句子間句子或多句子匹配不支持: nlp("that's it. Back to Winnipeg!").has('it back')//false
嵌套匹配語法: Regex的危險之處在於您可以無限期地反復出現。我們的比賽語法要弱得多。 (尚不可能)這樣的事情: doc.match('(modern (major|minor))? general')必須通過連續的.match()語句來實現複雜匹配。
依賴性解析:正確的句子轉換需要理解句子的語法樹,我們目前不這樣做。我們應該!需要幫助。

en-pos-亞歷克斯·科維(Alex Corvi)
NaturalNode- javaScript中的thaternode-統計NLP
winkjs- pos-tagger,dokenizer,JavaScript中的機器學習
dariusk/pos -js- javaScript中的fasttag fork
Compendium -js- JavaScript中的POS和情感分析
節點語言學- 結合,JavaScript中的變形
retext- JavaScript中的非常令人印象深刻的文本實用程序
上標- JS中的對話引擎
JSPO- javaScript構建經過時間測試的Brill-Tagger
Spacy- c/python中的快速,多語言標記器
散文- Joseph Kato的快速標記
TextBlob -Python Tagger

麻省理工學院