readability-scorer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseReadability Scorer
可读性评分工具
Analyze text readability using industry-standard formulas. Get grade level estimates, complexity metrics, and suggestions for improving clarity.
使用行业标准公式分析文本可读性,获取年级水平估算、复杂度指标以及提升清晰度的建议。
Quick Start
快速开始
python
from scripts.readability_scorer import ReadabilityScorerpython
from scripts.readability_scorer import ReadabilityScorerScore text
为文本评分
scorer = ReadabilityScorer()
scores = scorer.analyze("Your text to analyze goes here.")
print(f"Grade Level: {scores['grade_level']}")
print(f"Flesch Reading Ease: {scores['flesch_reading_ease']}")
undefinedscorer = ReadabilityScorer()
scores = scorer.analyze("此处填入待分析的文本。")
print(f"年级水平: {scores['grade_level']}")
print(f"Flesch阅读舒适度: {scores['flesch_reading_ease']}")
undefinedFeatures
功能特性
- Multiple Formulas: Flesch-Kincaid, Gunning Fog, SMOG, Coleman-Liau, ARI
- Grade Level: US grade level estimate
- Reading Ease: 0-100 ease score
- Text Statistics: Words, sentences, syllables, complex words
- Batch Analysis: Process multiple documents
- Comparison: Compare readability across texts
- 多公式支持:Flesch-Kincaid、Gunning Fog、SMOG、Coleman-Liau、ARI
- 年级水平:美国年级水平估算
- 阅读舒适度:0-100分的舒适度评分
- 文本统计:单词数、句子数、音节数、复杂单词数
- 批量分析:处理多个文档
- 对比分析:跨文本比较可读性
API Reference
API 参考
Initialization
初始化
python
scorer = ReadabilityScorer()python
scorer = ReadabilityScorer()Analysis
分析功能
python
scores = scorer.analyze(text)python
scores = scorer.analyze(text)Returns:
返回结果:
{
{
'flesch_reading_ease': 65.2,
'flesch_reading_ease': 65.2,
'flesch_kincaid_grade': 8.1,
'flesch_kincaid_grade': 8.1,
'gunning_fog': 10.2,
'gunning_fog': 10.2,
'smog_index': 9.5,
'smog_index': 9.5,
'coleman_liau': 9.8,
'coleman_liau': 9.8,
'ari': 8.4,
'ari': 8.4,
'grade_level': 8.5, # Average
'grade_level': 8.5, # 平均值
'reading_time_minutes': 2.3,
'reading_time_minutes': 2.3,
'stats': {
'stats': {
'words': 250,
'words': 250,
'sentences': 15,
'sentences': 15,
'syllables': 380,
'syllables': 380,
'complex_words': 25,
'complex_words': 25,
'avg_words_per_sentence': 16.7,
'avg_words_per_sentence': 16.7,
'avg_syllables_per_word': 1.52
'avg_syllables_per_word': 1.52
}
}
}
}
undefinedundefinedIndividual Scores
单独获取分数
python
undefinedpython
undefinedGet specific scores
获取特定分数
fre = scorer.flesch_reading_ease(text)
fkg = scorer.flesch_kincaid_grade(text)
fog = scorer.gunning_fog(text)
smog = scorer.smog_index(text)
undefinedfre = scorer.flesch_reading_ease(text)
fkg = scorer.flesch_kincaid_grade(text)
fog = scorer.gunning_fog(text)
smog = scorer.smog_index(text)
undefinedBatch Analysis
批量分析
python
texts = [text1, text2, text3]
results = scorer.analyze_batch(texts)python
texts = [text1, text2, text3]
results = scorer.analyze_batch(texts)From files
从文件读取分析
results = scorer.analyze_files(["doc1.txt", "doc2.txt"])
undefinedresults = scorer.analyze_files(["doc1.txt", "doc2.txt"])
undefinedComparison
对比分析
python
undefinedpython
undefinedCompare two texts
对比两个文本
comparison = scorer.compare(text1, text2)
print(f"Text 1 grade: {comparison['text1']['grade_level']}")
print(f"Text 2 grade: {comparison['text2']['grade_level']}")
undefinedcomparison = scorer.compare(text1, text2)
print(f"文本1年级水平: {comparison['text1']['grade_level']}")
print(f"文本2年级水平: {comparison['text2']['grade_level']}")
undefinedCLI Usage
CLI 使用方法
bash
undefinedbash
undefinedAnalyze text
分析文本
python readability_scorer.py --text "Your text here"
python readability_scorer.py --text "此处填入你的文本"
Analyze file
分析文件
python readability_scorer.py --input document.txt
python readability_scorer.py --input document.txt
Compare files
对比文件
python readability_scorer.py --compare doc1.txt doc2.txt
python readability_scorer.py --compare doc1.txt doc2.txt
Batch analyze directory
批量分析目录
python readability_scorer.py --input-dir ./docs --output report.csv
python readability_scorer.py --input-dir ./docs --output report.csv
Specific formula only
仅使用特定公式
python readability_scorer.py --input doc.txt --formula flesch
undefinedpython readability_scorer.py --input doc.txt --formula flesch
undefinedCLI Arguments
CLI 参数
| Argument | Description | Default |
|---|---|---|
| Text to analyze | - |
| Input file | - |
| Directory of files | - |
| Output file (json/csv) | - |
| Compare two files | - |
| Specific formula | all |
| 参数 | 描述 | 默认值 |
|---|---|---|
| 待分析的文本 | - |
| 输入文件 | - |
| 文件目录 | - |
| 输出文件(json/csv格式) | - |
| 对比两个文件 | - |
| 指定使用的公式 | all |
Score Interpretation
分数解读
Flesch Reading Ease
Flesch阅读舒适度
| Score | Difficulty | Grade Level |
|---|---|---|
| 90-100 | Very Easy | 5th grade |
| 80-89 | Easy | 6th grade |
| 70-79 | Fairly Easy | 7th grade |
| 60-69 | Standard | 8th-9th grade |
| 50-59 | Fairly Hard | 10th-12th grade |
| 30-49 | Difficult | College |
| 0-29 | Very Difficult | College graduate |
| 分数 | 难度 | 年级水平 |
|---|---|---|
| 90-100 | 极易 | 5年级 |
| 80-89 | 容易 | 6年级 |
| 70-79 | 较易 | 7年级 |
| 60-69 | 标准 | 8-9年级 |
| 50-59 | 较难 | 10-12年级 |
| 30-49 | 困难 | 大学 |
| 0-29 | 极难 | 大学毕业 |
Grade Level Scale
年级水平对照表
| Grade | Audience |
|---|---|
| 1-5 | Elementary school |
| 6-8 | Middle school |
| 9-12 | High school |
| 13-16 | College |
| 17+ | Graduate level |
| 年级 | 受众 |
|---|---|
| 1-5 | 小学生 |
| 6-8 | 初中生 |
| 9-12 | 高中生 |
| 13-16 | 大学生 |
| 17+ | 研究生及以上 |
Examples
示例
Analyze Blog Post
分析博客文章
python
scorer = ReadabilityScorer()
blog_post = """
Writing clear content is essential for engaging readers.
Short sentences help. Simple words work best.
Your audience will thank you for making things easy to understand.
"""
scores = scorer.analyze(blog_post)
print(f"Flesch Reading Ease: {scores['flesch_reading_ease']:.1f}")
print(f"Grade Level: {scores['grade_level']:.1f}")
print(f"Reading Time: {scores['reading_time_minutes']:.1f} minutes")
if scores['grade_level'] > 8:
print("Consider simplifying for a wider audience.")python
scorer = ReadabilityScorer()
blog_post = """
撰写清晰的内容对于吸引读者至关重要。
短句更有帮助,简单词汇效果最佳。
你的读者会感谢你让内容易于理解。
"""
scores = scorer.analyze(blog_post)
print(f"Flesch阅读舒适度: {scores['flesch_reading_ease']:.1f}")
print(f"年级水平: {scores['grade_level']:.1f}")
print(f"阅读时间: {scores['reading_time_minutes']:.1f} 分钟")
if scores['grade_level'] > 8:
print("建议简化内容以覆盖更广泛的受众。")Compare Document Versions
对比文档版本
python
scorer = ReadabilityScorer()
original = open("original.txt").read()
simplified = open("simplified.txt").read()
comparison = scorer.compare(original, simplified)
print("Original:")
print(f" Grade Level: {comparison['text1']['grade_level']:.1f}")
print(f" Flesch Ease: {comparison['text1']['flesch_reading_ease']:.1f}")
print("\nSimplified:")
print(f" Grade Level: {comparison['text2']['grade_level']:.1f}")
print(f" Flesch Ease: {comparison['text2']['flesch_reading_ease']:.1f}")
improvement = comparison['text1']['grade_level'] - comparison['text2']['grade_level']
print(f"\nImprovement: {improvement:.1f} grade levels easier")python
scorer = ReadabilityScorer()
original = open("original.txt").read()
simplified = open("simplified.txt").read()
comparison = scorer.compare(original, simplified)
print("原版文档:")
print(f" 年级水平: {comparison['text1']['grade_level']:.1f}")
print(f" Flesch舒适度: {comparison['text1']['flesch_reading_ease']:.1f}")
print("\n简化版文档:")
print(f" 年级水平: {comparison['text2']['grade_level']:.1f}")
print(f" Flesch舒适度: {comparison['text2']['flesch_reading_ease']:.1f}")
improvement = comparison['text1']['grade_level'] - comparison['text2']['grade_level']
print(f"\n提升幅度: 降低了{improvement:.1f}个年级水平,更易阅读")Batch Analyze Documentation
批量分析文档
python
scorer = ReadabilityScorer()
import os
results = []
for filename in os.listdir("./docs"):
if filename.endswith(".md"):
text = open(f"./docs/{filename}").read()
scores = scorer.analyze(text)
results.append({
'file': filename,
'grade': scores['grade_level'],
'ease': scores['flesch_reading_ease']
})python
scorer = ReadabilityScorer()
import os
results = []
for filename in os.listdir("./docs"):
if filename.endswith(".md"):
text = open(f"./docs/{filename}").read()
scores = scorer.analyze(text)
results.append({
'file': filename,
'grade': scores['grade_level'],
'ease': scores['flesch_reading_ease']
})Sort by difficulty
按难度排序
results.sort(key=lambda x: x['grade'], reverse=True)
print("Documents by Difficulty:")
for r in results:
print(f" {r['file']}: Grade {r['grade']:.1f}")
undefinedresults.sort(key=lambda x: x['grade'], reverse=True)
print("文档难度排序:")
for r in results:
print(f" {r['file']}: 年级水平 {r['grade']:.1f}")
undefinedDependencies
依赖项
nltk>=3.8.0nltk>=3.8.0Limitations
局限性
- English language only
- Formulas designed for prose (may not work well for lists, code, etc.)
- Syllable counting is estimated (may have minor inaccuracies)
- Doesn't assess comprehension, only surface-level complexity
- 仅支持英语
- 公式专为散文设计(对列表、代码等内容的分析效果可能不佳)
- 音节计数为估算值(可能存在微小误差)
- 仅评估表面复杂度,不涉及理解能力评估