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. node 图片验证码生成

    var captchapng = require('captchapng'); var http = require("http") var server = http.creat ...

  2. PHP "松散比较"

    PHP 的整数和字符串比较是 "松散比较" var_dump('dev' == 0); bool(true) switch switch 在进行比较的时候,只是对值进行比较(&qu ...

  3. Hybrid设计--离线更新

    首先server端和前端做一个增量发布系统 ,1.就是把一个增量包发布到一个版本的Native上去,让他做更新.2.后台对这个增量包的到达率或者成功的更新做一个统计.这是比较复杂的. 离线更新的机制: ...

  4. 4.C#虚方法virtual详解

    C#虚方法virtual详解 在C++.Java等众多OOP语言里都可以看到virtual的身影,而C#作为一个完全面向对象的语言当然也不例外. 虚拟函数从C#的程序编译的角度来看,它和其它一般的函数 ...

  5. MS16-032 漏洞复现

    exploit-db的详情:  https://www.exploit-db.com/exploits/39574/ Windows: Secondary Logon Standard Handles ...

  6. HTML+css+html5基础+css3须知

    1.定位四种 静态定位(static):文档流默认的定位方式:一般不用写.      如果没有指定元素的position属性值,元素也就是静态定位.static是position属性的默认值,它表示块 ...

  7. “0x00,0x08”两个十六进制字符串,转换为整形

    int m_length=0;char buf[2]=={0x00,0x08};memcpy(&m_length,&buf[0],2); m_length=m_length<&l ...

  8. DOS命令下映射虚拟磁盘(驱动器)

    ---恢复内容开始--- subst命令,用于路径替换,进入dos窗口,键入“subst /?”(t和/之间有空格),会看到关于subst的用法如下: C:\Users\Administrator&g ...

  9. JS实例5

    做这么一个效果  鼠标单击某个名字后变色,没选中的鼠标移动上去变色 首先布局这个效果,然后给每个表格添加单击事件onclick.鼠标放上事件onmousemove.鼠标移出事件onmouseout 容 ...

  10. base64的编码

    计算机中的数据一般是由ascii编码,来存储的, 0---31以及127,表示的是控制字符: 32-126表示的是字符,包括空格,阿拉伯数字,大小写字母: 之后的128个字符,是不可见的字符, 在网络 ...