feat: ARI.

This commit is contained in:
Shibo Lyu 2022-05-21 01:00:36 +08:00
parent 5f0d996c91
commit 2f4cb84050
3 changed files with 38 additions and 3 deletions

View 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
}
}

View file

@ -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: "ColemanLiau 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."
)

View file

@ -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>