从文本中计算各种特征的软件包

textdescriptives的Python项目详细描述


文本说明

一个Python包,用于从文本计算各种统计信息。在

安装

克隆Github目录,在终端中导航到它,然后调用 pip install .

使用

要计算所有可能的指标:

import textdescriptives

# Input can be either a string, list of strings, or pandas Series 
en_test = ['The world is changed. I feel it in the water. I feel it in the earth. I smell it in the air. Much that once was is lost, for none now live who remember it.',
            'He felt that his whole life was some kind of dream and he sometimes wondered whose it was and whether they were enjoying it.']

textdescriptives.all_metrics(en_test, lang = 'en', snlp_path = snlp_path)
Textavg_word_lengthmedian_word_lengthstd_word_lengthavg_sentence_lengthmedian_sentence_lengthstd_sentence_lengthavg_syl_per_wordmedian_syl_per_wordstd_syl_per_wordtype_token_ratiolixrixn_typesn_sentencesn_tokensn_charsgunning_fogsmogflesch_reading_easeflesch_kincaid_gradeautomated_readability_indexcoleman_liau_indexGermanicLatinateLatinate/Germanicmean_dependency_distancestd_dependency_distancemean_prop_adjacent_dependency_relationstd_prop_adjacent_dependency_relation
0The world is changed.(...)3.2857131.54127763.098391.0857110.3681170.65714312.71430.4245351213.942865.68392107.879-0.0485714-2.45429-0.70857175250.3333331.603810.364930.6952380.0481871
1He felt that his whole (...)4.1666741.97203242401.1666710.4714050.83333340.666742112410111.2667083.7757.5366710.1957.4666783.333316.66670.22.1600.640

一次计算一个类别:

^{pr2}$

textDescriptions适用于大多数语言,只需更改国家/地区代码:

da_test = pd.Series(['Da jeg var atten, tog jeg patent på ild. Det skulle senere vise sig at blive en meget indbringende forretning',
            "Spis skovsneglen, Mulle. Du vil jo gerne være med i hulen, ikk'?"])

textdescriptives.all_metrics(da_test, lang = 'da', snlp_path=snlp_path)

如果您只需要基本统计数据的一个子集

textdescriptives.basic_stats(en_test, lang = 'en', metrics=['avg_word_length', 'n_chars'])
^{tb2}$

可读性

可读性度量很大程度上是从textstat库派生出来的,并在那里进行了彻底的定义。在

词源

词源度量是使用macroetym计算的,只是稍微重写了一下,以便从脚本中调用。他们是计算的,因为在英语中,拉丁语词源的单词频率越高,往往表示语言语域越正式。在

依赖距离

平均依存距离可以用来衡量文本的平均句法复杂度。请求snlp库。 依赖距离函数需要stanfordnlp及其语言模型。如果您已经下载了这些模型,那么可以在snlp_path参数中指定文件夹的路径。否则,模型将下载到您的工作目录+/snlp_resources。在

依赖关系

根据要计算的度量值的不同,依赖关系也不同。在

  • 基本和可读性:numpy,pandas,pyphen,pycountry
  • 词源:nltk和以下模型 python3 -c "import nltk; nltk.download('punkt'); nltk.download('stopwords'); nltk.download('averaged_perceptron_tagger'); nltk.download('wordnet')"
  • 依赖距离:snlp

指标

当前实施的指标:

  1. 基本描述性统计-以下各项的平均值、中位数、标准差:
  • 字长
  • 句子长度,单词
  • 句子长度,字符(TODO)
  • 每个单词的音节数
  • 字符数
  • 句子数
  • 类型数(唯一单词)
  • 标记数(总字数)
  • 类型/比率
  • Lix公司
  • 里克斯
  1. 可读性指标:
  • 喷雾
  • 烟雾
  • 弗莱施阅读简易
  • 弗莱施金凯级
  • 自动可读性索引
  • 科尔曼-利亚乌指数
  1. 词源相关指标:
  • 日耳曼语源词百分比
  • 拉丁语源词百分比
  • 拉丁/日耳曼血统比率
  1. 依赖距离度量:
  • 平均依赖距离,句子水平(平均值,标准差)
  • 平均比例相邻依存关系,句子水平(平均值,标准偏差)

{由Hansen在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java在Hibernate中使用条件连接两个表?   Stripes框架中的java对话范围   我的内存够吗?   Jenkins Java&Selenium如何处理2个随机异常?   javascript Java websockets跨端点共享会话   java是一种测试驱动的开发方法吗?   Java客户端中的Soap连接超时,但在SOAPUI中未超时   Java LibGDX:TileMap未在顶部和右侧渲染   linux Java::process builder:bash脚本:返回的文件名正确,但fileReader引发FileNotFoundException   java Selenium单击自动随机生成的DIV/ID/LINK   比较两个忽略元素和属性顺序的XMl文件   Java无限循环/调用   java如何防止操作修改cookie?   列出未保存的Java webpanel命令   在Java中,如何解决XXXX不能作为变量求解的错误?   Java概念后期版本格式化部分