python自然语言处理工具NLTK各个包的意思和作用总结

               

【转】http://www.myexception.cn/perl-python/464414.html

【原】Python NLP实战之一:环境准备
最近正在学习Python,看了几本关于Python入门的书和用Python进行自然语言处理的书,如《Python编程实践》、《Python基础教程》(第2版)、《Python自然语言处理》(影印版)。因为以前是学Java的,有着良好的面向对象的思维方式,所以刚开始看Python的语法,觉得Pyhon太随意了,很别扭,有不正规之嫌。而且,Python自己也正在向面向对象(OO)靠拢。但是,后来看到Python有强大的类库,尤其在自然语言处理方面有着强大的NLTK支持,我逐渐改变了对它的看法。不得不承认,Python非常简洁和清晰,很容易上手,对于有编程经验的人来说,可以快速编写程序来实现某个应用。下面是本人学习中的一些心得,与大家分享。

Python NLP实战之一:环境准备

要下载和安装的软件和资源有:

  • Python
  • PyYAML
  • NLTK
  • NLTK-Data
  • NumPy
  • Matplotlib


(一)下载地址和版本:

  • Python:http://www.python.org/getit/releases/2.7.2/ 版本:Python 2.7.2 (注:现在是2.7.3。Python已经发布3.3版了,之所以下载2.7,是因为2.x比较稳定,兼容的第三方软件多。Python官网提示:如果你不知道用哪个版本的话,就从2.7开始吧!)
  • PyYAML:http://pypi.python.org/pypi/PyYAML/ 版本:PyYAML 3.10 功能:YAML的解析工具
  • NLTK: http://www.nltk.org 版本:nltk-2.0.1 功能:自然语言工具包
  • NumPy: http://pypi.python.org/pypi/numpy 版本:numpy 1.6.1 功能:支持多维数组和线性代数
  • Matplotlib: http://sourceforge.net/projects/matplotlib/files/matplotlib/matplotlib-1.1.0/ 版本:matplotlib-1.1.0 功能:用于数据可视化的二维图库

安装都很简单,我是在Window下安装的。

(二)运行Python IDLE
Python安装完成后,运行Python集成开发环境IDLE:开始->所有程序->Python 2.7 ->IDLE (Python GUI),打开一个新的窗口,显示如下信息,表明安装成功。

[java]  view plain  copy
  1. Python 2.7.2 (default, Jun 12 201115:08:59) [MSC v.1500 32 bit (Intel)] on win32  
  2. Type "copyright""credits" or "license()" for more information.  
  3. >>>  


(三)下载NLTK数据包
接下来,导入NLTK工具包,然后,下载NLTK数据源。

[java]  view plain  copy
  1. >>> import nltk  
  2. >>> nltk.download()  



注意:在导入MLTK工具包时,如果显示如下信息,表明没有安装PyYAML。

[java]  view plain  copy
  1. >>> import nltk  
  2. Traceback (most recent call last):  
  3.   File "<pyshell#0>", line 1, in <module>  
  4.     import nltk  
  5.   File "C:\Python27\lib\site-packages\nltk\__init__.py", line 107, in <module>  
  6.     from yamltags import *  
  7.   File "C:\Python27\lib\site-packages\nltk\yamltags.py", line 10, in <module>  
  8.     import yaml  
  9. ImportError: No module named yaml  



按照(一)所列的地址下载、安装完PyYAML后,再打开Python IDLE,导入NLTK,执行nltk.download(),我的界面出现的是文字提示,书上和网上有同学说是图形界面,两者都可以吧。

[java]  view plain  copy
  1. Python 2.7.2 (default, Jun 12 201115:08:59) [MSC v.1500 32 bit (Intel)] on win32  
  2. Type "copyright""credits" or "license()" for more information.  
  3. >>> import nltk  
  4. >>> nltk.download()  
  5. NLTK Downloader  
  6. ---------------------------------------  
  7.     d) Download   l) List    u) Update   c) Config   h) Help   q) Quit  
  8. ---------------------------------------  
  9. Downloader>  


选择d) Download,敲入d,再敲入l,然后按提示敲几次回车,显示的是将要下载的各种不同的数据包。

[java]  view plain  copy
  1. Downloader> d  
  2. Download which package (l=list; x=cancel)?  
  3.   Identifier> l  
  4. Packages:  
  5.   [ ] maxent_ne_chunker... ACE Named Entity Chunker (Maximum entropy)  
  6.   [ ] abc................. Australian Broadcasting Commission 2006  
  7.   [ ] alpino.............. Alpino Dutch Treebank  
  8.   [ ] biocreative_ppi..... BioCreAtIvE (Critical Assessment of Information  
  9.                            Extraction Systems in Biology)  
  10.   [ ] brown_tei........... Brown Corpus (TEI XML Version)  
  11.   [ ] cess_esp............ CESS-ESP Treebank  
  12.   [ ] chat80.............. Chat-80 Data Files  
  13.   [ ] brown............... Brown Corpus  
  14.   [ ] cmudict............. The Carnegie Mellon Pronouncing Dictionary (0.6)  
  15.   [ ] city_database....... City Database  
  16.   [ ] cess_cat............ CESS-CAT Treebank  
  17.   [ ] comtrans............ ComTrans Corpus Sample  
  18.   [ ] conll2002........... CONLL 2002 Named Entity Recognition Corpus  
  19.   [ ] conll2007........... Dependency Treebanks from CoNLL 2007 (Catalan  
  20.                            and Basque Subset)  
  21.   [ ] europarl_raw........ Sample European Parliament Proceedings Parallel  
  22.                            Corpus  
  23.   [ ] dependency_treebank. Dependency Parsed Treebank  
  24.   [ ] conll2000........... CONLL 2000 Chunking Corpus  
  25. Hit Enter to continue:   
  26.   [ ] floresta............ Portuguese Treebank  
  27.   [ ] names............... Names Corpus, Version 1.3 (1994-03-29)  
  28.   [ ] gazetteers.......... Gazeteer Lists  
  29.   [ ] genesis............. Genesis Corpus  
  30.   [ ] gutenberg........... Project Gutenberg Selections  
  31.   [ ] inaugural........... C-Span Inaugural Address Corpus  
  32.   [ ] jeita............... JEITA Public Morphologically Tagged Corpus (in  
  33.                            ChaSen format)  
  34.   [ ] movie_reviews....... Sentiment Polarity Dataset Version 2.0  
  35.   [ ] ieer................ NIST IE-ER DATA SAMPLE  
  36.   [ ] nombank.1.0......... NomBank Corpus 1.0  
  37.   [ ] indian.............. Indian Language POS-Tagged Corpus  
  38.   [ ] paradigms........... Paradigm Corpus  
  39.   [ ] kimmo............... PC-KIMMO Data Files  
  40.   [ ] knbc................ KNB Corpus (Annotated blog corpus)  
  41.   [ ] langid.............. Language Id Corpus  
  42.   [ ] mac_morpho.......... MAC-MORPHO: Brazilian Portuguese news text with  
  43.                            part-of-speech tags  
  44.   [ ] machado............. Machado de Assis -- Obra Completa  
  45.   [ ] pe08................ Cross-Framework and Cross-Domain Parser  
  46.                            Evaluation Shared Task  
  47. Hit Enter to continue:   
  48.   [ ] pl196x.............. Polish language of the XX century sixties  
  49.   [ ] pil................. The Patient Information Leaflet (PIL) Corpus  
  50.   [ ] nps_chat............ NPS Chat  
  51.   [ ] reuters............. The Reuters-21578 benchmark corpus, ApteMod  
  52.                            version  
  53.   [ ] qc.................. Experimental Data for Question Classification  
  54.   [ ] rte................. PASCAL RTE Challenges 12, and 3  
  55.   [ ] ppattach............ Prepositional Phrase Attachment Corpus  
  56.   [ ] propbank............ Proposition Bank Corpus 1.0  
  57.   [ ] problem_reports..... Problem Report Corpus  
  58.   [ ] sinica_treebank..... Sinica Treebank Corpus Sample  
  59.   [ ] verbnet............. VerbNet Lexicon, Version 2.1  
  60.   [ ] state_union......... C-Span State of the Union Address Corpus  
  61.   [ ] semcor.............. SemCor 3.0  
  62.   [ ] senseval............ SENSEVAL 2 Corpus: Sense Tagged Text  
  63.   [ ] smultron............ SMULTRON Corpus Sample  
  64.   [ ] shakespeare......... Shakespeare XML Corpus Sample  
  65.   [ ] stopwords........... Stopwords Corpus  
  66.   [ ] swadesh............. Swadesh Wordlists  
  67.   [ ] switchboard......... Switchboard Corpus Sample  
  68.   [ ] toolbox............. Toolbox Sample Files  
  69. Hit Enter to continue:   
  70.   [ ] unicode_samples..... Unicode Samples  
  71.   [ ] webtext............. Web Text Corpus  
  72.   [ ] timit............... TIMIT Corpus Sample  
  73.   [ ] ycoe................ York-Toronto-Helsinki Parsed Corpus of Old  
  74.                            English Prose  
  75.   [ ] treebank............ Penn Treebank Sample  
  76.   [ ] udhr................ Universal Declaration of Human Rights Corpus  
  77.   [ ] sample_grammars..... Sample Grammars  
  78.   [ ] book_grammars....... Grammars from NLTK Book  
  79.   [ ] spanish_grammars.... Grammars for Spanish  
  80.   [ ] wordnet............. WordNet  
  81.   [ ] wordnet_ic.......... WordNet-InfoContent  
  82.   [ ] words............... Word Lists  
  83.   [ ] tagsets............. Help on Tagsets  
  84.   [ ] basque_grammars..... Grammars for Basque  
  85.   [ ] large_grammars...... Large context-free and feature-based grammars  
  86.                            for parser comparison  
  87.   [ ] maxent_treebank_pos_tagger Treebank Part of Speech Tagger (Maximum entropy)  
  88.   [ ] rslp................ RSLP Stemmer (Removedor de Sufixos da Lingua  
  89.                            Portuguesa)  
  90.   [ ] hmm_treebank_pos_tagger Treebank Part of Speech Tagger (HMM)  
  91. Hit Enter to continue:   
  92.   [ ] punkt............... Punkt Tokenizer Models  
  93.   
  94. Collections:  
  95.   [ ] all-corpora......... All the corpora  
  96.   [ ] all................. All packages  
  97.   [ ] book................ Everything used in the NLTK Book  
  98.   
  99. ([*] marks installed packages)  



你可以选择敲入 all-corpora,或all,或book,我选的是all。保持网络畅通,下载可能需要一段时间。显示信息如下:

<

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

猜你喜欢

转载自blog.csdn.net/ggjttfc/article/details/86694557