I'm a DMer & MLer & NLPer & IRer
博文有原创,有转载。均为分享学习之用。P.S. 部分转载可能未注明出处。若有冒昧,请与我联系:(ILoveDataMining AT gmail DOT com)

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
统计
 

1. NLTK的安装步骤

在做python版的汉语词法分析时用到了NLTK,感觉安装步骤比较繁琐,特整理如下。

一、linux下运行python非常方便,不多说了。

二、windows下安装NLTK,运行一个python比较麻烦些:

1. 安装Python2.5(暂不支持2.6和3.0);

2. 安装NumPy:运行numpy-1.2.1-win32-superpack-python2.5.exe;

3. 安装MatPlotLib:运行matplotlib-0.98.5.2.win32-py2.5.exe;

4. 安装NLTK:运行nltk-0.9.8.win32-py2.5.msi;

5. 安装Prover9:解压LADR1007B-win.zip,将解压产生的文件夹LADR1007B-win改名为prover9,并将文件夹prover9移动到C:\nltk_data中;

6. 安装MSVCP71.DLL:如果有必要,将MSVCP71.zip文件解压,将解压得到的MSVCP71.DLL文件复制到C:\Windows\System32下;

7. 安装NLTK数据:在命令行窗口中运行python -m nltk.downloader all,将自动下载并安装所有数据(语料库、词典等),总共约428M。

   如果NLTK数据安装失败,有可能是NLTK的版本冲突,需要卸载老版本的NLTK,重装最新版本。

  or

  >>> import nltk

 >>> nltk.download()

2. 开始看数据

ntlk的示例数据是book

我们可以用命令from nltk.book import * 来看看数据:

*** 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

>>> 

对这些文本信息的查询,python提供了多种形式:

Any time we want to find out about these texts, we just have to enter their names at the Python prompt:

>>> text1

<Text: Moby Dick by Herman Melville 1851>

concordance(主要词语索引) view :

例如我们向想看词 monstrous(巨大的) 在text1对应的 Moby Dick(白鲸记) 中出现的信息(前后文):

>>> text1.concordance("monstrous")

clip_image006

细心的发现了monstrous容易出新在下面的模式中:

the ___ pictures and the ___

 

 

posted on   wentingtu  阅读(8027)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
 
点击右上角即可分享
微信分享提示