feat: support roman version of pruning

This commit is contained in:
Miwa / Ensan
2025-06-29 14:16:25 +09:00
parent eb4e669b2b
commit 763b059a45
3 changed files with 37 additions and 2 deletions

View File

@@ -52,9 +52,21 @@ struct TypoCorrectionGenerator {
stablePrefix.append(contentsOf: item.string)
case .roman2kana:
// TODO: impl
break loop
var stableIndex = item.string.endIndex
for suffix in Roman2Kana.unstableSuffixes {
if item.string.hasSuffix(suffix) {
stableIndex = min(stableIndex, item.string.endIndex - suffix.count)
}
}
if stableIndex == item.string.endIndex {
stablePrefix.append(contentsOf: item.string)
} else {
// break
stablePrefix.append(contentsOf: item.string[0 ..< stableIndex])
break loop
}
}
// prefix
// prefixtargetprefixstackunreachable
if stablePrefix.hasPrefix(target) {
return false
}

View File

@@ -10,6 +10,11 @@ import Foundation
import SwiftUtils
enum Roman2Kana {
static let unstableSuffixes: Set<[Character]> = hiraganaChanges.keys.flatMapSet { characters in
characters.indices.map { i in
Array(characters[...i])
}
}
static let katakanaChanges: [String: String] = Dictionary(uniqueKeysWithValues: hiraganaChanges.map { (String($0.key), String($0.value).toKatakana()) })
static let hiraganaChanges: [[Character]: [Character]] = Dictionary(uniqueKeysWithValues: [
"a": "",