欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python学习自然语言处理

程序员文章站 2022-07-13 10:09:50
...
!pip install nltk
import nltk
nltk.download('nps_chat')
nltk.download('webtext')
[nltk_data] Downloading package nps_chat to /Users/andrew/nltk_data...
[nltk_data]   Package nps_chat is already up-to-date!
[nltk_data] Downloading package webtext to /Users/andrew/nltk_data...
[nltk_data]   Unzipping corpora/webtext.zip.

from nltk.book import *
from nltk.corpus import udhr
*** Introductory Examples for the NLTK Book ***
Loading text1, ..., text9 and sent1, ..., sent9
Type the name of the text or sentence to view it.
Type: 'texts()' or 'sents()' to list the materials.
text1: Moby Dick by Herman Melville 1851
text2: Sense and Sensibility by Jane Austen 1811
text3: The Book of Genesis
text4: Inaugural Address Corpus
text5: Chat Corpus
text6: Monty Python and the Holy Grail
text7: Wall Street Journal
text8: Personals Corpus
text9: The Man Who Was Thursday by G . K . Chesterton 1908
# Chap1 语言处理与Python
# 目的:
# 1)简单的程序如何与大规模的文本结合?
# 2)如何自动地提取出关键字和词组?如何使用它们来总结文本的风格和内容?
# 3)Python为文本处理提供了哪些工具和技术?
# 4)自然语言处理中还有哪些有趣的挑战?

# 1. 语言计算:文本和词汇
# 1.3. 搜索文本
# 1. 语言计算:文本和词汇
# 1.3. 搜索文本

# 查找 monstrous 词出现的位置
text1.concordance('monstrous')
text1.concordance('contemptible')

Displaying 11 of 11 matches:
ong the former , one was of a most monstrous size . ... This came towards us , 
ON OF THE PSALMS . " Touching that monstrous bulk of the whale or ork we have r
ll over with a heathenish array of monstrous clubs and spears . Some were thick
d as you gazed , and wondered what monstrous cannibal and savage could ever hav
that has survived the flood ; most monstrous and most mountainous ! That Himmal
they might scout at Moby Dick as a monstrous fable , or still worse and more de
th of Radney .'" CHAPTER 55 Of the Monstrous Pictures of Whales . I shall ere l
ing Scenes . In connexion with the monstrous pictures of whales , I am strongly
ere to enter upon those still more monstrous stories of them which are to be fo
ght have been rummaged out of this monstrous cabinet there is no telling . But 
of Whale - Bones ; for Whales of a monstrous size are oftentimes cast up dead u
Displaying 4 of 4 matches:
, we shall find they will appear contemptible in the comparison . The whale is
 God ? Miserable man ! Oh ! most contemptible and worthy of all scorn ; with s
s these pig - fish are a noisy , contemptible set , mostly lurking in the mout
 harm , it may possibly be of no contemptible advantage ; considering that oil
# 与 monstrous 使用一个词汇相似的上下文的单词
# 'most monstrous and'
# 'most contemptible and'
text1.similar('monstrous')
true contemptible christian abundant few part mean careful puzzled
mystifying passing curious loving wise doleful gamesome singular
delightfully perilous fearless