NASSLLI2018-Corpus-Linguistics【Day 4】

More NLTK and Corpus Tools

n-grams

Conditional frequency distribution: by preceding word
What are the most common words following ‘shall’?
‘shall’ becomes the condition for the next word: conditional frequency distribution.
Stats can be compiled from a list of bigrams (w1, w2).

Conditional frequency distribution: count per year
Are words such as ‘freedom’, ‘liberty’, ‘god’ more frequent or less over time?
We will try out NLTK’s book chapter on the Inaugural corpus: http://www.nltk.org/book/ch02.html#inaugural-address-corpus
Plotting/visualization

nltk.Text object and other corpus tools
NLTK’s Text object class provides a concordancer and other classic corpus tools
A Text object can be built from a token list

exercise:

# In[1]:


import nltk 
from nltk.corpus import PlaintextCorpusReader
corpus_root = '/Users/lichun/Desktop/inaugural'  # Use your own userid; Mac users should omit C:
inaug = PlaintextCorpusReader(corpus_root, '.*txt')  # all files ending in 'txt'


# In[2]:


get_ipython().run_line_magic('pprint', '')
inaug.fileids()


# In[3]:


print(inaug.words()[:50])


# In[4]:


chom = 'colorless green ideas sleep furiously'.split()
chom


# In[5]:


nltk.bigrams(chom)
# fundtion returns a "generator" object: it is memory-efficient but won't let us take a peak


# In[6]:


# generator object works well in a loop environment
for x in nltk.bigrams(chom):
    print(x)


# In[7]:


# Force it into a list type
list(nltk.bigrams(chom))


# In[8]:


# trigram function also available
list(nltk.trigrams(chom))


# In[9]:


# let's build a bigram list of the entire inaugural corpus
inaug_bigrams = list(nltk.bigrams(inaug.words()))
inaug_bigrams[:10]


# In[10]:


# last 10 bigrams
inaug_bigrams[-10:]


# In[11]:


# What are the most frquent bigrams? 
inaug_bigrams_fd = nltk.FreqDist(inaug_bigrams)
inaug_bigrams_fd.most_common(30)


# In[12]:


inaug_bigrams_fd[('of', 'the')]


# In[13]:


# What functions are available with this object? 
dir(inaug_bigrams_fd)


# In[14]:


# over 1% of all bigrams are 'of the'! 
inaug_bigrams_fd.freq(('of', 'the'))


# In[15]:


# cfd is built from bigrams: a list of (w1, w2) 
inaug_bigrams_cfd = nltk.ConditionalFreqDist(inaug_bigrams)


# In[16]:


# 'shall' as the w1 condition. Value is a FreqDist! # 'shal 
inaug_bigrams_cfd['shall']


# In[17]:


inaug_bigrams_cfd['shall']['not']


# In[18]:


# total count of 'shall'
inaug_bigrams_cfd['shall'].N()


# In[19]:


# likelihood of 'not' following 'shall' 
inaug_bigrams_cfd['shall'].freq('not')


# In[20]:


inaug_bigrams_cfd['shall'].most_common(10)


# In[21]:


inaug_Text = nltk.Text(inaug.words())
inaug_Text.concordance("shall")


# In[25]:


help(inaug_Text.concordance)


# In[26]:


# What other handy functions are available? 
dir(inaug_Text)


# In[27]:


# More info on the method. Doesn't say what stats are used...
help(inaug_Text.collocations)


# In[28]:


# common context (surrounding words) shared by a list of words
inaug_Text.common_contexts(['shall', 'will'])

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我! 基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip
毕设新项目基于python3.7+django+sqlite开发的学生就业管理系统源码+使用说明(含vue前端源码).zip 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我! 学生就业管理系统(前端) ## 项目开发环境 - IDE: vscode - node版本: v12.14.1 - npm版本: 6.13.4 - vue版本: @vue/cli 4.1.2 - 操作系统: UOS 20 ## 1.进入项目目录安装依赖 ``` npm install ``` ## 2.命令行执行进入UI界面进行项目管理 ``` vue ui ``` ## 3.编译发布包(请注意编译后存储路径) #### PS:需要将编译后的包复制到后端项目的根目录下并命名为'static' 学生就业管理系统(后端) ## 1.项目开发环境 - IDE: vscode - Django版本: 3.0.3 - Python版本: python3.7.3 - 数据库 : sqlite3(测试专用) - 操作系统 : UOS 20 ## 2.csdn下载本项目并生成/安装依赖 ``` pip freeze > requirements.txt pip install -r requirements.txt ``` ## 3.项目MySQL数据库链接错误 [点击查看解决方法](https://www.cnblogs.com/izbw/p/11279237.html)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值