NLTK 知识整理

nltk.corpus模块自带语料

NLTK comes with many corpora, toy grammars, trained models, etc. A complete list is posted at: http://nltk.org/nltk_data/

  1. Run the Python interpreter and type the commands:
>>> import nltk
>>> nltk.download()
  1. Test that the data has been installed as follows. (This assumes you downloaded the Brown Corpus):
>>> from nltk.corpus import brown
>>> brown.words()
['The', 'Fulton', 'County', 'Grand', 'Jury', 'said', ...]

API

  • words(): list of str
  • sents(): list of (list of str)
  • paras(): list of (list of (list of str))
  • tagged_words(): list of (str,str) tuple
  • tagged_sents(): list of (list of (str,str))
  • tagged_paras(): list of (list of (list of (str,str)))
  • chunked_sents(): list of (Tree w/ (str,str) leaves)
  • parsed_sents(): list of (Tree with str leaves)
  • parsed_paras(): list of (list of (Tree with str leaves))
  • xml(): A single xml ElementTree
  • raw(): unprocessed corpus contents

For example, to read a list of the words in the Brown Corpus, use nltk.corpus.brown.words():

>>> from nltk.corpus import brown
>>> print(", ".join(brown.words()))
The, Fulton, County, Grand, Jury, said, ...

Tokenize 英文分词

Tokenize some text:

>>> import nltk
>>> sentence = """At eight o'clock on Thursday morning
... Arthur didn't feel very good."""
>>> nltk.word_tokenize(sentence)
['At', 'eight', "o'clock", 'on', 'Thursday', 'morning',
'Arthur', 'did', "n't", 'feel', 'very', 'good', '.']

References

[1] NLTK 3.2.5 documentation http://www.nltk.org/

[2] nltk.corpus package http://www.nltk.org/api/nltk.corpus.html#module-nltk.corpus

NLTK 知识整理的更多相关文章

  1. js事件(Event)知识整理

    事件(Event)知识整理,本文由网上资料整理而来,需要的朋友可以参考下   鼠标事件 鼠标移动到目标元素上的那一刻,首先触发mouseover 之后如果光标继续在元素上移动,则不断触发mousemo ...

  2. Kali Linux渗透基础知识整理(四):维持访问

    Kali Linux渗透基础知识整理系列文章回顾 维持访问 在获得了目标系统的访问权之后,攻击者需要进一步维持这一访问权限.使用木马程序.后门程序和rootkit来达到这一目的.维持访问是一种艺术形式 ...

  3. Kali Linux渗透基础知识整理(二)漏洞扫描

    Kali Linux渗透基础知识整理系列文章回顾 漏洞扫描 网络流量 Nmap Hping3 Nessus whatweb DirBuster joomscan WPScan 网络流量 网络流量就是网 ...

  4. wifi基础知识整理

    转自 :http://blog.chinaunix.net/uid-9525959-id-3326047.html WIFI基本知识整理 这里对wifi的802.11协议中比较常见的知识做一个基本的总 ...

  5. 数据库知识整理<一>

    关系型数据库知识整理: 一,关系型数据库管理系统简介: 1.1使用数据库的原因: 降低存储数据的冗余度 提高数据的一致性 可以建立数据库所遵循的标准 储存数据可以共享 便于维护数据的完整性 能够实现数 ...

  6. 【转载】UML类图知识整理

    原文:UML类图知识整理 UML类图 UML,进阶必备专业技能,看不懂UML就会看不懂那些优秀的资料. 这里简单整理 类之间的关系 泛化关系(generalization) 泛化(generalize ...

  7. Linux进程管理知识整理

    Linux进程管理知识整理 1.进程有哪些状态?什么是进程的可中断等待状态?进程退出后为什么要等待调度器删除其task_struct结构?进程的退出状态有哪些? TASK_RUNNING(可运行状态) ...

  8. js事件(Event)知识整理[转]

    事件注册 平常我们绑定事件的时候用dom.onxxxx=function(){}的形式 这种方式是给元素的onxxxx属性赋值,只能绑定有一个处理句柄. 但很多时候我们需要绑定多个处理句柄到一个事件上 ...

  9. Spring Ioc知识整理

    Ioc知识整理(一): IoC (Inversion of Control) 控制反转. 1.bean的别名 我们每个bean元素都有一个id属性,用于唯一标识实例化的一个类,其实name属性也可用来 ...

随机推荐

  1. CentOS6.5安装kafka-2.10-0.8.2(单机)

    1.下载 地址:https://kafka.apache.org/downloads 本文中下载版本:kafka_2.10-0.8.2.2.tgz 2.安装 安装目录:/usr/local [root ...

  2. FluentScheduler:开源轻量级定时任务调度架构

    安装:FluentScheduler Install-Package FluentScheduler 一.控制台中使用 using System; using System.Collections.G ...

  3. cocos2dx 3.x(for 循环让精灵从中间往上下两边排列)

    最近很多游戏都喜欢房卡类的游戏,就是创建房间时(),选择玩法与规则,今天耗费2小时处理这个数学问题:例如选择规则两条,则背景框中间显示两条规则,若选择三条,则背景框中间显示三条规则与玩法,依次从中间往 ...

  4. Linux基础(六) Vim之vundle插件

    背景 Vim缺乏默认的插件管理器,所有插件的文件都散布在~/.vim下的几个文件夹中,插件的安装与更新与删除都需要自己手动来,既麻烦费事,又可能出现错误. Vundle简介 Vundle 是 Vim ...

  5. windows编程之Windows Shell 编程

    参考书<VC++ Windows Shell Programming>   这里仅仅是记录下该资源,推荐到下文列出的连接进行查看   用VC++ 进行Windows Shell 扩展编成 ...

  6. STL之Vector容器

    1.Vector容器 1)vector是将元素置于一个动态数组中加以管理的容器. 2)vector可以随机存取元素(支持索引值直接存取, 用[]操作符或at()方法,这个等下会详讲). 3)vecto ...

  7. hdu3037 lucas

    题意 :  给了n课不同的树,要求将 0,1,2,3,4,5,...m个松果,分别放在n棵树上的方案数有多少, 我们这样考虑, 如果将m个相同的松果 放入n棵树中 , 转化一下,我们让每个点至少放1个 ...

  8. 【转】Loadrunner 性能指标定位系统瓶颈

    转至:http://www.51testing.com/html/63/n-1224463.html Loadrunner 性能指标定位系统瓶颈 判断CPU瓶颈 1, %processor time ...

  9. RobotFrameWork(一)robotfamework(python版)及Ride在windows安装

    1.windows下的安装 (1)准备条件: python-2.7.3.msi robotframework-2.7.5.win32.exe wxPython2.8-win32-unicode-2.8 ...

  10. 任务调度工具 Apache Airflow 初识

    参考文章: Apache Airflow (incubating) Documentation — Airflow ... 任务调度神器 airflow 之初体验 airflow 介绍 - 简书(原文 ...