在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ Python/ 塊分類(lèi)
文本翻譯
提取URL地址
處理PDF
塊分類(lèi)
搜索和匹配
大寫(xiě)轉(zhuǎn)換
提取電子郵件地址
字符串的不變性
文本處理狀態(tài)機(jī)
雙字母組
閱讀RSS提要
單詞替換
WordNet接口
重新格式化段落
標(biāo)記單詞
向后讀取文件
塊和裂口
美化打印數(shù)字
拼寫(xiě)檢查
將二進(jìn)制轉(zhuǎn)換為ASCII
文本分類(lèi)
文字換行
頻率分布
字符串作為文件
約束搜索
詞干算法
符號(hào)化
同義詞和反義詞
過(guò)濾重復(fù)的字詞
刪除停用詞
Python文本處理教程
文字摘要
段落計(jì)數(shù)令牌
語(yǔ)料訪問(wèn)
文字改寫(xiě)
文本處理簡(jiǎn)介
處理Word文檔
Python文本處理開(kāi)發(fā)環(huán)境
排序行

塊分類(lèi)

基于分類(lèi)的分塊涉及將文本分類(lèi)為一組單詞而不是單個(gè)單詞。一個(gè)簡(jiǎn)單的場(chǎng)景是在句子中標(biāo)記文本,將使用語(yǔ)料庫(kù)來(lái)演示分類(lèi)。選擇具有來(lái)自華爾街日?qǐng)?bào)語(yǔ)料庫(kù)(WSJ)的數(shù)據(jù)的語(yǔ)料庫(kù)conll2000,用于基于名詞短語(yǔ)的分塊。

首先,使用以下命令將語(yǔ)料庫(kù)添加到環(huán)境中。

import nltk
nltk.download('conll2000')

看看這個(gè)語(yǔ)料庫(kù)中的前幾句話(huà)。

from nltk.corpus import conll2000

x = (conll2000.sents())
for i in range(3):
     print x[i]
     print '\n'

當(dāng)運(yùn)行上面的程序時(shí),我們得到以下輸出 -

['Confidence', 'in', 'the', 'pond', 'is', 'widely', 'expected', 'to', 'take', 'another', 'sharp', 'dive', 'if', 'trade', 'figres', 'for', 'September', ',', 'de', 'for', 'release', 'tomorrow', ',', 'fail', 'to', 'show', 'a', 'sbstantial', 'improvement', 'from', 'Jly', 'and', 'Agst', "'s", 'near-record', 'deficits', '.']


['Chancellor', 'of', 'the', 'Excheqer', 'Nigel', 'Lawson', "'s", 'restated', 'commitment', 'to', 'a', 'firm', 'monetary', 'policy', 'has', 'helped', 'to', 'prevent', 'a', 'freefall', 'in', 'sterling', 'over', 'the', 'past', 'week', '.']


['Bt', 'analysts', 'reckon', 'nderlying', 'spport', 'for', 'sterling', 'has', 'been', 'eroded', 'by', 'the', 'chancellor', "'s", 'failre', 'to', 'annonce', 'any', 'new', 'policy', 'measres', 'in', 'his', 'Mansion', 'Hose', 'speech', 'last', 'Thrsday', '.']

接下來(lái),使用函數(shù)tagged_sents()來(lái)獲取標(biāo)記到其分類(lèi)器的句子。

from nltk.corpus import conll2000

x = (conll2000.tagged_sents())
for i in range(3):
     print x[i]
     print '\n'

當(dāng)運(yùn)行上面的程序時(shí),我們得到以下輸出 -

[('Confidence', 'NN'), ('in', 'IN'), ('the', 'DT'), ('pond', 'NN'), ('is', 'VBZ'), ('widely', 'RB'), ('expected', 'VBN'), ('to', 'TO'), ('take', 'VB'), ('another', 'DT'), ('sharp', 'JJ'), ('dive', 'NN'), ('if', 'IN'), ('trade', 'NN'), ('figres', 'NNS'), ('for', 'IN'), ('September', 'NNP'), (',', ','), ('de', 'JJ'), ('for', 'IN'), ('release', 'NN'), ('tomorrow', 'NN'), (',', ','), ('fail', 'VB'), ('to', 'TO'), ('show', 'VB'), ('a', 'DT'), ('sbstantial', 'JJ'), ('improvement', 'NN'), ('from', 'IN'), ('Jly', 'NNP'), ('and', 'CC'), ('Agst', 'NNP'), ("'s", 'POS'), ('near-record', 'JJ'), ('deficits', 'NNS'), ('.', '.')]


[('Chancellor', 'NNP'), ('of', 'IN'), ('the', 'DT'), ('Excheqer', 'NNP'), ('Nigel', 'NNP'), ('Lawson', 'NNP'), ("'s", 'POS'), ('restated', 'VBN'), ('commitment', 'NN'), ('to', 'TO'), ('a', 'DT'), ('firm', 'NN'), ('monetary', 'JJ'), ('policy', 'NN'), ('has', 'VBZ'), ('helped', 'VBN'), ('to', 'TO'), ('prevent', 'VB'), ('a', 'DT'), ('freefall', 'NN'), ('in', 'IN'), ('sterling', 'NN'), ('over', 'IN'), ('the', 'DT'), ('past', 'JJ'), ('week', 'NN'), ('.', '.')]


[('Bt', 'CC'), ('analysts', 'NNS'), ('reckon', 'VBP'), ('nderlying', 'VBG'), ('spport', 'NN'), ('for', 'IN'), ('sterling', 'NN'), ('has', 'VBZ'), ('been', 'VBN'), ('eroded', 'VBN'), ('by', 'IN'), ('the', 'DT'), ('chancellor', 'NN'), ("'s", 'POS'), ('failre', 'NN'), ('to', 'TO'), ('annonce', 'VB'), ('any', 'DT'), ('new', 'JJ'), ('policy', 'NN'), ('measres', 'NNS'), ('in', 'IN'), ('his', 'PRP$'), ('Mansion', 'NNP'), ('Hose', 'NNP'), ('speech', 'NN'), ('last', 'JJ'), ('Thrsday', 'NNP'), ('.', '.')]

上一篇:頻率分布下一篇:搜索和匹配