mirror of
https://github.com/mii443/AzooKeyKanaKanjiConverter.git
synced 2025-12-03 02:58:27 +00:00
feat: add tests for typo
This commit is contained in:
@@ -28,8 +28,9 @@ public struct ConvertRequestOptions: Sendable {
|
||||
/// - textReplacer: 予測変換のための置換機を指定します。
|
||||
/// - specialCandidateProviders: 特殊変換を実施する変換関数を挿入します
|
||||
/// - metadata: メタデータを指定します。詳しくは`ConvertRequestOptions.Metadata`を参照してください。
|
||||
public init(N_best: Int = 10, requireJapanesePrediction: Bool, requireEnglishPrediction: Bool, keyboardLanguage: KeyboardLanguage, englishCandidateInRoman2KanaInput: Bool = false, fullWidthRomanCandidate: Bool = false, halfWidthKanaCandidate: Bool = false, learningType: LearningType, maxMemoryCount: Int = 65536, shouldResetMemory: Bool = false, dictionaryResourceURL: URL, memoryDirectoryURL: URL, sharedContainerURL: URL, textReplacer: TextReplacer, specialCandidateProviders: [any SpecialCandidateProvider]?, zenzaiMode: ZenzaiMode = .off, preloadDictionary: Bool = false, metadata: ConvertRequestOptions.Metadata?) {
|
||||
public init(N_best: Int = 10, needTypoCorrection: Bool? = nil, requireJapanesePrediction: Bool, requireEnglishPrediction: Bool, keyboardLanguage: KeyboardLanguage, englishCandidateInRoman2KanaInput: Bool = false, fullWidthRomanCandidate: Bool = false, halfWidthKanaCandidate: Bool = false, learningType: LearningType, maxMemoryCount: Int = 65536, shouldResetMemory: Bool = false, dictionaryResourceURL: URL, memoryDirectoryURL: URL, sharedContainerURL: URL, textReplacer: TextReplacer, specialCandidateProviders: [any SpecialCandidateProvider]?, zenzaiMode: ZenzaiMode = .off, preloadDictionary: Bool = false, metadata: ConvertRequestOptions.Metadata?) {
|
||||
self.N_best = N_best
|
||||
self.needTypoCorrection = needTypoCorrection
|
||||
self.requireJapanesePrediction = requireJapanesePrediction
|
||||
self.requireEnglishPrediction = requireEnglishPrediction
|
||||
self.keyboardLanguage = keyboardLanguage
|
||||
@@ -86,6 +87,7 @@ public struct ConvertRequestOptions: Sendable {
|
||||
specialCandidateProviders.append(.commaSeparatedNumber)
|
||||
|
||||
self.N_best = N_best
|
||||
self.needTypoCorrection = nil
|
||||
self.requireJapanesePrediction = requireJapanesePrediction
|
||||
self.requireEnglishPrediction = requireEnglishPrediction
|
||||
self.keyboardLanguage = keyboardLanguage
|
||||
@@ -157,6 +159,7 @@ public struct ConvertRequestOptions: Sendable {
|
||||
public var requireJapanesePrediction: Bool
|
||||
public var requireEnglishPrediction: Bool
|
||||
public var keyboardLanguage: KeyboardLanguage
|
||||
public var needTypoCorrection: Bool?
|
||||
// KeyboardSettingのinjection用途
|
||||
public var englishCandidateInRoman2KanaInput: Bool
|
||||
public var fullWidthRomanCandidate: Bool
|
||||
@@ -183,6 +186,7 @@ public struct ConvertRequestOptions: Sendable {
|
||||
static var `default`: Self {
|
||||
Self(
|
||||
N_best: 10,
|
||||
needTypoCorrection: nil,
|
||||
requireJapanesePrediction: true,
|
||||
requireEnglishPrediction: true,
|
||||
keyboardLanguage: .ja_JP,
|
||||
|
||||
@@ -605,7 +605,7 @@ import EfficientNGram
|
||||
/// - N_best: 計算途中で保存する候補数。実際に得られる候補数とは異なる。
|
||||
/// - Returns:
|
||||
/// 結果のラティスノードと、計算済みノードの全体
|
||||
private func convertToLattice(_ inputData: ComposingText, N_best: Int, zenzaiMode: ConvertRequestOptions.ZenzaiMode) -> (result: LatticeNode, lattice: Lattice)? {
|
||||
private func convertToLattice(_ inputData: ComposingText, N_best: Int, zenzaiMode: ConvertRequestOptions.ZenzaiMode, needTypoCorrection: Bool) -> (result: LatticeNode, lattice: Lattice)? {
|
||||
if inputData.convertTarget.isEmpty {
|
||||
return nil
|
||||
}
|
||||
@@ -625,11 +625,6 @@ import EfficientNGram
|
||||
self.previousInputData = inputData
|
||||
return (result, nodes)
|
||||
}
|
||||
#if os(iOS)
|
||||
let needTypoCorrection = true
|
||||
#else
|
||||
let needTypoCorrection = false
|
||||
#endif
|
||||
|
||||
guard let previousInputData else {
|
||||
debug("\(#function): 新規計算用の関数を呼びますA")
|
||||
@@ -698,7 +693,14 @@ import EfficientNGram
|
||||
// DicdataStoreにRequestOptionを通知する
|
||||
self.sendToDicdataStore(.setRequestOptions(options))
|
||||
|
||||
guard let result = self.convertToLattice(inputData, N_best: options.N_best, zenzaiMode: options.zenzaiMode) else {
|
||||
#if os(iOS)
|
||||
let needTypoCorrection = options.needTypoCorrection ?? true
|
||||
#else
|
||||
let needTypoCorrection = options.needTypoCorrection ?? false
|
||||
#endif
|
||||
|
||||
|
||||
guard let result = self.convertToLattice(inputData, N_best: options.N_best, zenzaiMode: options.zenzaiMode, needTypoCorrection: needTypoCorrection) else {
|
||||
return ConversionResult(mainResults: [], firstClauseResults: [])
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ public import Foundation
|
||||
public extension ConvertRequestOptions {
|
||||
static func withDefaultDictionary(
|
||||
N_best: Int = 10,
|
||||
needTypoCorrection: Bool? = nil,
|
||||
requireJapanesePrediction: Bool,
|
||||
requireEnglishPrediction: Bool,
|
||||
keyboardLanguage: KeyboardLanguage,
|
||||
@@ -29,13 +30,26 @@ public extension ConvertRequestOptions {
|
||||
#else
|
||||
let dictionaryDirectory = Bundle.module.resourceURL!.appendingPathComponent("Dictionary", isDirectory: true)
|
||||
#endif
|
||||
|
||||
var specialCandidateProviders = [any SpecialCandidateProvider]()
|
||||
if typographyLetterCandidate {
|
||||
specialCandidateProviders.append(.typography)
|
||||
}
|
||||
if unicodeCandidate {
|
||||
specialCandidateProviders.append(.unicode)
|
||||
}
|
||||
specialCandidateProviders.append(.emailAddress)
|
||||
specialCandidateProviders.append(.timeExpression)
|
||||
specialCandidateProviders.append(.calendar)
|
||||
specialCandidateProviders.append(.version)
|
||||
specialCandidateProviders.append(.commaSeparatedNumber)
|
||||
|
||||
return Self(
|
||||
N_best: N_best,
|
||||
needTypoCorrection: needTypoCorrection,
|
||||
requireJapanesePrediction: requireJapanesePrediction,
|
||||
requireEnglishPrediction: requireEnglishPrediction,
|
||||
keyboardLanguage: keyboardLanguage,
|
||||
typographyLetterCandidate: typographyLetterCandidate,
|
||||
unicodeCandidate: unicodeCandidate,
|
||||
englishCandidateInRoman2KanaInput: englishCandidateInRoman2KanaInput,
|
||||
fullWidthRomanCandidate: fullWidthRomanCandidate,
|
||||
halfWidthKanaCandidate: halfWidthKanaCandidate,
|
||||
@@ -44,8 +58,9 @@ public extension ConvertRequestOptions {
|
||||
shouldResetMemory: shouldResetMemory,
|
||||
dictionaryResourceURL: dictionaryDirectory,
|
||||
memoryDirectoryURL: memoryDirectoryURL,
|
||||
sharedContainerURL: sharedContainerURL,
|
||||
sharedContainerURL: sharedContainerURL,
|
||||
textReplacer: textReplacer,
|
||||
specialCandidateProviders: specialCandidateProviders,
|
||||
zenzaiMode: zenzaiMode,
|
||||
preloadDictionary: preloadDictionary,
|
||||
metadata: metadata
|
||||
|
||||
Reference in New Issue
Block a user