mirror of
https://github.com/laosb/ReadabilityFramework.git
synced 2025-08-18 13:52:40 +00:00
Basics.
This commit is contained in:
parent
2640bebf90
commit
d3dcfc84de
13 changed files with 352 additions and 41 deletions
28
Sources/Readability/Scorers/FleschKincaidGrade.swift
Normal file
28
Sources/Readability/Scorers/FleschKincaidGrade.swift
Normal file
|
@ -0,0 +1,28 @@
|
|||
//
|
||||
// File.swift
|
||||
// Readability
|
||||
//
|
||||
// Created by Shibo Lyu on 2022/5/20.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct RAFleschKincaidGradeScorer: RAScorer {
|
||||
static let requiresCommonMetrics: Set<RACommonMetric>? = [
|
||||
.avgWordsPerSentence,
|
||||
.avgSyllablesPerWord
|
||||
]
|
||||
|
||||
static let meta = RAScorerMeta(
|
||||
name: "Flesch-Kincaid Grade",
|
||||
creator: "John P. Kincaid",
|
||||
citation: "Kincaid, J. P., Fishburne Jr, R. P., Rogers, R. L., & Chissom, B. S. (1975). Derivation of new readability formulas (automated readability index, fog count and flesch reading ease formula) for navy enlisted personnel. Naval Technical Training Command Millington TN Research Branch."
|
||||
)
|
||||
|
||||
func score(_ text: String, metrics: RACommonMetricsCalculator.Results?) -> Double {
|
||||
let asl = metrics![.avgWordsPerSentence]!
|
||||
let asw = metrics![.avgSyllablesPerWord]!
|
||||
|
||||
return (0.39 * asl) + (11.8 * asw) - 15.59
|
||||
}
|
||||
}
|
28
Sources/Readability/Scorers/FleschReadingEase.swift
Normal file
28
Sources/Readability/Scorers/FleschReadingEase.swift
Normal file
|
@ -0,0 +1,28 @@
|
|||
//
|
||||
// File.swift
|
||||
// Readability
|
||||
//
|
||||
// Created by Shibo Lyu on 2022/5/19.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct RAFleschReadingEaseScorer: RAScorer {
|
||||
static let requiresCommonMetrics: Set<RACommonMetric>? = [
|
||||
.avgWordsPerSentence,
|
||||
.avgSyllablesPerWord
|
||||
]
|
||||
|
||||
static let meta = RAScorerMeta(
|
||||
name: "Flesch Reading Ease",
|
||||
creator: "Rudolf Flesch",
|
||||
citation: "Flesch, R. (1948). A new readability yardstick. Journal of applied psychology, 32(3), 221."
|
||||
)
|
||||
|
||||
func score(_ text: String, metrics: RACommonMetricsCalculator.Results?) -> Double {
|
||||
let asl = metrics![.avgWordsPerSentence]!
|
||||
let asw = metrics![.avgSyllablesPerWord]!
|
||||
|
||||
return 206.835 - (1.015 * asl) - (84.6 * asw)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue