PythonNLP学习进阶:第二章练习题(Python自然语言处理)

python自然语言处理.2014年7月第一版课后习题练习

1.

>>> phrase=["Valentine's"]
>>> phrase=["lonely"]+phrase+["day"]
>>> phrase
['lonely', "Valentine's", 'day']
>>> phrase[1]
"Valentine's"
>>> phrase[1][1]
'a'
>>> phrase.index('day')
2
>>> sorted(phrase)
["Valentine's", 'day', 'lonely']
>>> phrase[1:2]
["Valentine's"]
>>> phrase*3
['lonely', "Valentine's", 'day', 'lonely', "Valentine's", 'day', 'lonely', "Valentine's", 'day']


2.

>>> from nltk.corpus import gutenberg
>>> gutenberg.fileids()
[u'austen-emma.txt', u'austen-persuasion.txt', u'austen-sense.txt', u'bible-kjv.txt', u'blake-poems.txt', u'bryant-stories.txt', u'burgess-busterbrown.txt', u'carroll-alice.txt', u'chesterton-ball.txt', u'chesterton-brown.txt', u'chesterton-thursday.txt', u'edgeworth-parents.txt', u'melville-moby_dick.txt', u'milton-paradise.txt', u'shakespeare-caesar.txt', u'shakespeare-hamlet.txt', u'shakespeare-macbeth.txt', u'whitman-leaves.txt']
>>> persuasion=gutenberg.words('austen-persuasion.txt')
>>> len(persuasion)
98171
>>> len(set(persuasion))//词类型,我不知道是不是指有多少个不一样的词
6132
3.

>>> from nltk.corpus import brown
>>> brown.categories()
[u'adventure', u'belles_lettres', u'editorial', u'fiction', u'government', u'hobbies', u'humor', u'learned', u'lore', u'mystery', u'news', u'religion', u'reviews', u'romance', u'science_fiction']
>>> brown.words(categories='lore')
[u'In', u'American', u'romance', u',', u'almost', ...]
>>> brown.words(categories='mystery')
[u'There', u'were', u'thirty-eight', u'patients', ...]

>>> from nltk.corpus import webtext
>>> webtext.fileids()
[u'firefox.txt', u'grail.txt', u'overheard.txt', u'pirates.txt', u'singles.txt', u'wine.txt']
>>> webtext.words('firefox.txt')
[u'Cookie', u'Manager', u':', u'"', u'Don', u"'", u't', ...]
>>> webtext.words('grail.txt
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值