鍍金池/ 教程/ Python/ 符號(hào)化
文本翻譯
提取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ǔ)料訪(fǎng)問(wèn)
文字改寫(xiě)
文本處理簡(jiǎn)介
處理Word文檔
Python文本處理開(kāi)發(fā)環(huán)境
排序行

符號(hào)化

在Python中,標(biāo)記化基本上是指將更大的文本體分成更小的行,單詞甚至為非英語(yǔ)語(yǔ)言創(chuàng)建單詞。各種標(biāo)記化函數(shù)功能內(nèi)置在nltk模塊中,可以在程序中使用,如下所示。

行標(biāo)記化

在下面的示例中,使用函數(shù)sent_tokenize將給定文本劃分為不同的行。

import nltk
sentence_data = "The First sentence is about Python. The Second: about Django. You can learn Python,Django and Data Ananlysis here. "
nltk_tokens = nltk.sent_tokenize(sentence_data)
print (nltk_tokens)

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

['The First sentence is about Python.', 'The Second: about Django.', 'You can learn Python,Django and Data Ananlysis here.']

非英語(yǔ)標(biāo)記化

在下面的示例中,將德語(yǔ)文本標(biāo)記為。

import nltk

german_tokenizer = nltk.data.load('tokenizers/punkt/german.pickle')
german_tokens=german_tokenizer.tokenize('Wie geht es Ihnen?  Gut, danke.')
print(german_tokens)

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

['Wie geht es Ihnen?', 'Gut, danke.']

單詞符號(hào)化

我們使用nltkword_tokenize函數(shù)將單詞標(biāo)記。參考以下代碼 -

import nltk

word_data = "It originated from the idea that there are readers who prefer learning new skills from the comforts of their drawing rooms"
nltk_tokens = nltk.word_tokenize(word_data)
print (nltk_tokens)

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

['It', 'originated', 'from', 'the', 'idea', 'that', 'there', 'are', 'readers', 
'who', 'prefer', 'learning', 'new', 'skills', 'from', 'the',
'comforts', 'of', 'their', 'drawing', 'rooms']