zoukankan      html  css  js  c++  java
  • 【语言处理与Python】1.1文本和单词

    【前言】
    自然语言:日常交流使用的语言
    NLP:Natural Language Processing

    【第1章 语言处理与Python】
    1.1语言计算:文本和单词
    基本入门
    -想要获得我们期望的小数除法,要输入from __future__ import division

    -下载NLTK数据包
     import nltk
     nltk.download()

    -加载要用的文本
     from nltk.book import *

    搜索文本
    -concordance词汇索引,会显示词汇所处的上下文
    text1.concordance("monstrous")

    -similar,查找还有哪些词会出现在相似的上下文中
    text1.similar("monstrous")

    -common_contexts,允许我们研究两个或者两个以上的词共同的上下文
    text2.common_contexts(["monstrous","very"])

    -dispersion_plot,判断词汇在文本中的位置,使用离散图来表示位置。
    text4.dispersion_plot(["citizens","democracy","freedom","duties","America"])

    -不同风格生成文本
    text3.generate()

    计数词汇
    -len(text3)出现的词和标点符号的个数
    -sorted(set(text3))所有文章出现的词汇,并且进行排序(词类型,一个词在一个文本中独一无二出现的形式或者拼写)
    -from __future__ import division
     len(text3)/len(set(text3))
     丰富度测量,每个字平均被使用的次数
    -text3.count("smote")特定次出现的次数
    -100*text4.count('a')/len(text4)特定的词在文本中占据的百分比
    -定义函数,进行重复运算。
     def lexical_diversity(text):
        return len(text)/len(set(text))
     def percentage(count,total):
        return 100*count/total

  • 相关阅读:
    sharepoint custom web service
    网站模板创建报错
    sharepoint 2013 持续爬网
    使用 SQL的 for xml path来进行字符串拼接 (group by)
    sharepoint 修改AD密码
    SharePoint 2013 BCS
    系统补丁对sharepoint很重要
    SharePoint 2010: Export User Profile Properties to a Text File or Excel using PowerShell
    SharePoint2013 错误
    sharepoint 开发相关工具总结
  • 原文地址:https://www.cnblogs.com/createMoMo/p/3078333.html
Copyright © 2011-2022 走看看