mirror of
https://github.com/laosb/ReadabilityFramework.git
synced 2025-08-18 13:52:40 +00:00
feat: Coleman-Liau Index.
This commit is contained in:
parent
3a5ec5de50
commit
474c4c708d
3 changed files with 51 additions and 5 deletions
34
Sources/Readability/Scorers/ColemanLiauIndex.swift
Normal file
34
Sources/Readability/Scorers/ColemanLiauIndex.swift
Normal file
|
@ -0,0 +1,34 @@
|
|||
//
|
||||
// File.swift
|
||||
//
|
||||
//
|
||||
// Created by Shibo Lyu on 2022/5/20.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct RAColemanLiauIndexScorer: RAScorer {
|
||||
public static let requiresCommonMetrics: Set<RACommonMetric>? = [
|
||||
.wordCount,
|
||||
.characterCount,
|
||||
.sentenceCount
|
||||
]
|
||||
|
||||
public static let meta = RAScorerMeta(
|
||||
name: "Coleman–Liau Index",
|
||||
creator: "Meri Coleman & T. L. Liau",
|
||||
citation: "Coleman, M., & Liau, T. L. (1975). A computer readability formula designed for machine scoring. Journal of Applied Psychology, 60(2), 283."
|
||||
)
|
||||
|
||||
public init() {}
|
||||
|
||||
public func score(_ text: String, metrics: RACommonMetricsCalculator.Results?) -> Double {
|
||||
let wordCount = metrics![.wordCount]!
|
||||
|
||||
let l = metrics![.characterCount]! * 100 / wordCount
|
||||
let s = metrics![.sentenceCount]! * 100 / wordCount
|
||||
|
||||
let cloze = 141.8401 - (0.214590 * l) + (1.079812 * s)
|
||||
return (-27.4004 * cloze) + 23.06395
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue