gpt4 book ai didi

python-3.x - textstat/可读性包 Python 3 的经验

转载 作者:行者123 更新时间:2023-12-01 04:53:04 25 4
gpt4 key购买 nike

这里有人曾经在 python 中使用过可读性 0.2 或 textstat 0.3.1 包吗?找不到关于 SO 处理这个主题的任何内容或任何关于此的好的文档。

到目前为止,我的代码是:
它遍历本地存储的一堆 txt 文件,并将结果(可读性度量)打印到主文本文件中。

from textstat.textstat import textstat
import os
import glob
import contextlib


@contextlib.contextmanager
def stdout2file(fname):
import sys
f = open(fname, 'w', encoding="utf-8")
sys.stdout = f
yield
sys.stdout = sys.__stdout__
f.close()


def readability():
os.chdir(r"F:\Level1\Level2")
with stdout2file("Results_readability.txt"):
for file in glob.iglob("*.txt"): # iterates over all files in the directory ending in .txt
with open(file, encoding="utf8") as fin:
contents = fin.read()
if __name__ == '__main__':
print(textstat.flesch_reading_ease(contents))
print(file.split(os.path.sep)[-1], end=" | ")
print(textstat.smog_index(contents), end="\n ")
print(file.split(os.path.sep)[-1], end=" | ")
print(textstat.gunning_fog(contents), end="\n ")

这很有效,但是我有两个问题:
  • 是否可以将我的主文件存储到另一个目录中?如果我使用上面的代码,我的主文件与迭代的文件在同一目录中创建,这有点毫无意义...
  • 任何人都体验过这些包的工作准确度如何?我刚刚在 textstat 和 http://www.webpagefx.com/tools/read-able/check.php 中测试了相同的字符串/http://gunning-fog-index.com/并在所有措施上获得显着不同的结果?

  • 任何帮助表示赞赏。

    最佳答案

    我怀疑 textstat 使用不同的系数。一个简单的检查:在一个由一个音节组成的单词组成的句子上运行它。我用的文字 "No." :

    In: textstat.flesch_kincaid_grade("No.")
    Out: -4.6

    但根据文献中的公式,答案应该是 -3.4
    (即 0.39*1+11.8*1-15.59)

    关于python-3.x - textstat/可读性包 Python 3 的经验,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39537707/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com