mirror of
https://github.com/laosb/ReadabilityFramework.git
synced 2025-04-30 12:41:08 +00:00
feat: ARI.
This commit is contained in:
parent
5f0d996c91
commit
2f4cb84050
3 changed files with 38 additions and 3 deletions
33
Sources/Readability/Scorers/AutomatedReadabilityIndex.swift
Normal file
33
Sources/Readability/Scorers/AutomatedReadabilityIndex.swift
Normal file
|
@ -0,0 +1,33 @@
|
|||
//
|
||||
// AutomatedReadabilityIndex.swift
|
||||
//
|
||||
//
|
||||
// Created by Shibo Lyu on 2022/5/21.
|
||||
//
|
||||
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct RAAutomatedReadabilityIndexScorer: RAScorer {
|
||||
public static let requiresCommonMetrics: Set<RACommonMetric>? = [
|
||||
.wordCount,
|
||||
.characterCount,
|
||||
.sentenceCount
|
||||
]
|
||||
|
||||
public static let meta = RAScorerMeta(
|
||||
name: "Automated Readability Index",
|
||||
creator: "RJ Senter & EA Smith",
|
||||
citation: "Senter, R. J., & Smith, E. A. (1967). Automated readability index. Cincinnati Univ OH."
|
||||
)
|
||||
|
||||
public init() {}
|
||||
|
||||
public func score(_ text: String, metrics: RACommonMetricsCalculator.Results?) -> Double {
|
||||
let wordCount = metrics![.wordCount]!
|
||||
let characterCount = metrics![.characterCount]!
|
||||
let sentenceCount = metrics![.sentenceCount]!
|
||||
|
||||
return 4.71 * (characterCount / wordCount) + 0.5 * (wordCount / sentenceCount) - 21.43
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// File.swift
|
||||
// ColemanLiauIndex.swift
|
||||
//
|
||||
//
|
||||
// Created by Shibo Lyu on 2022/5/20.
|
||||
|
@ -15,7 +15,7 @@ public struct RAColemanLiauIndexScorer: RAScorer {
|
|||
]
|
||||
|
||||
public static let meta = RAScorerMeta(
|
||||
name: "Coleman–Liau Index",
|
||||
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."
|
||||
)
|
||||
|
|
|
@ -14,12 +14,14 @@ public class RAScoringTask {
|
|||
case fleschReadingEase
|
||||
case fleschKincaidGrade
|
||||
case colemanLiauIndex
|
||||
case automatedReadabilityIndex
|
||||
}
|
||||
|
||||
public static let availableScorers: [Scorer: RAScorer.Type] = [
|
||||
.fleschReadingEase: RAFleschReadingEaseScorer.self,
|
||||
.fleschKincaidGrade: RAFleschKincaidGradeScorer.self,
|
||||
.colemanLiauIndex: RAColemanLiauIndexScorer.self
|
||||
.colemanLiauIndex: RAColemanLiauIndexScorer.self,
|
||||
.automatedReadabilityIndex: RAAutomatedReadabilityIndexScorer.self
|
||||
]
|
||||
|
||||
public var scorersToRun: Set<Scorer>
|
||||
|
|
Loading…
Add table
Reference in a new issue