当前位置:   article > 正文

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

python自然语言处理题库

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

1.

  1. >>> phrase=["Valentine's"]
  2. >>> phrase=["lonely"]+phrase+["day"]
  3. >>> phrase
  4. ['lonely', "Valentine's", 'day']
  5. >>> phrase[1]
  6. "Valentine's"
  7. >>> phrase[1][1]
  8. 'a'
  9. >>> phrase.index('day')
  10. 2
  11. >>> sorted(phrase)
  12. ["Valentine's", 'day', 'lonely']
  13. >>> phrase[1:2]
  14. ["Valentine's"]
  15. >>> phrase*3
  16. ['lonely', "Valentine's", 'day', 'lonely', "Valentine's", 'day', 'lonely', "Valentine's", 'day']


2.

  1. >>> from nltk.corpus import gutenberg
  2. >>> gutenberg.fileids()
  3. [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']
  4. >>> persuasion=gutenberg.words('austen-persuasion.txt')
  5. >>> len(persuasion)
  6. 98171
  7. >>> len(set(persuasion))//词类型,我不知道是不是指有多少个不一样的词
  8. 6132
3.

  1. >>> from nltk.corpus import brown
  2. >>> brown.categories()
  3. [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']
  4. >>> brown.words(categories='lore')
  5. [u'In', u'American', u'romance', u',', u'almost', ...]
  6. >>> brown.words(categories='mystery')
  7. [u'There', u'were', u'thirty-eight', u'patients', ...]
  1. >>> from nltk.corpus import webtext
  2. >>> webtext.fileids()
  3. [u'firefox.txt', u'grail.txt', u'overheard.txt', u'pirates.txt', u'singles.txt', u'wine.txt']
  4. >>> webtext.words('firefox.txt')
  5. [u'Cookie', u'Manager', u':', u'"', u'Don', u"'", u't', ...]
  6. >>> webtext.words('grail.txt
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/521727
推荐阅读
相关标签
  

闽ICP备14008679号