mirror of
https://github.com/mii443/AzooKeyKanaKanjiConverter.git
synced 2025-08-22 15:05:26 +00:00
feat: add session CLI for dynamic user dictionary
This commit is contained in:
@ -146,15 +146,15 @@ extension Subcommands {
|
|||||||
|
|
||||||
/// ユーザ辞書
|
/// ユーザ辞書
|
||||||
var user_dictionary: [InputUserDictionaryItem]? = nil
|
var user_dictionary: [InputUserDictionaryItem]? = nil
|
||||||
|
}
|
||||||
|
|
||||||
struct InputUserDictionaryItem: Codable {
|
struct InputUserDictionaryItem: Codable {
|
||||||
/// 漢字
|
/// 漢字
|
||||||
var word: String
|
var word: String
|
||||||
/// 読み
|
/// 読み
|
||||||
var reading: String
|
var reading: String
|
||||||
/// ヒント
|
/// ヒント
|
||||||
var hint: String? = nil
|
var hint: String? = nil
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct EvaluateResult: Codable {
|
struct EvaluateResult: Codable {
|
||||||
|
@ -30,6 +30,8 @@ extension Subcommands {
|
|||||||
var reportScore = false
|
var reportScore = false
|
||||||
@Flag(name: [.customLong("roman2kana")], help: "Use roman2kana input.")
|
@Flag(name: [.customLong("roman2kana")], help: "Use roman2kana input.")
|
||||||
var roman2kana = false
|
var roman2kana = false
|
||||||
|
@Option(name: [.customLong("config_user_dictionary")], help: "User Dictionary JSON file path")
|
||||||
|
var configUserDictionary: String? = nil
|
||||||
@Option(name: [.customLong("config_zenzai_inference_limit")], help: "inference limit for zenzai.")
|
@Option(name: [.customLong("config_zenzai_inference_limit")], help: "inference limit for zenzai.")
|
||||||
var configZenzaiInferenceLimit: Int = .max
|
var configZenzaiInferenceLimit: Int = .max
|
||||||
@Flag(name: [.customLong("config_zenzai_rich_n_best")], help: "enable rich n_best generation for zenzai.")
|
@Flag(name: [.customLong("config_zenzai_rich_n_best")], help: "enable rich n_best generation for zenzai.")
|
||||||
@ -70,6 +72,15 @@ extension Subcommands {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func parseUserDictionaryFile() throws -> [InputUserDictionaryItem] {
|
||||||
|
guard let configUserDictionary else {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
let url = URL(fileURLWithPath: configUserDictionary)
|
||||||
|
let data = try Data(contentsOf: url)
|
||||||
|
return try JSONDecoder().decode([InputUserDictionaryItem].self, from: data)
|
||||||
|
}
|
||||||
|
|
||||||
@MainActor mutating func run() async {
|
@MainActor mutating func run() async {
|
||||||
if self.zenzV1 || self.zenzV2 {
|
if self.zenzV1 || self.zenzV2 {
|
||||||
print("\(bold: "We strongly recommend to use zenz-v3 models")")
|
print("\(bold: "We strongly recommend to use zenz-v3 models")")
|
||||||
@ -80,6 +91,11 @@ extension Subcommands {
|
|||||||
if !self.zenzWeightPath.isEmpty && (!self.zenzV1 && !self.zenzV2 && !self.zenzV3) {
|
if !self.zenzWeightPath.isEmpty && (!self.zenzV1 && !self.zenzV2 && !self.zenzV3) {
|
||||||
print("zenz version is not specified. By default, zenz-v3 will be used.")
|
print("zenz version is not specified. By default, zenz-v3 will be used.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let userDictionary = try! self.parseUserDictionaryFile().map {
|
||||||
|
DicdataElement(word: $0.word, ruby: $0.reading.toKatakana(), cid: CIDData.固有名詞.cid, mid: MIDData.一般.mid, value: -10)
|
||||||
|
}
|
||||||
|
|
||||||
let learningType: LearningType = if self.readOnlyMemoryPath != nil {
|
let learningType: LearningType = if self.readOnlyMemoryPath != nil {
|
||||||
// 読み取りのみ
|
// 読み取りのみ
|
||||||
.onlyOutput
|
.onlyOutput
|
||||||
@ -107,6 +123,7 @@ extension Subcommands {
|
|||||||
converter.sendToDicdataStore(
|
converter.sendToDicdataStore(
|
||||||
.setRequestOptions(requestOptions(learningType: learningType, memoryDirectory: memoryDirectory, leftSideContext: nil))
|
.setRequestOptions(requestOptions(learningType: learningType, memoryDirectory: memoryDirectory, leftSideContext: nil))
|
||||||
)
|
)
|
||||||
|
converter.sendToDicdataStore(.importDynamicUserDict(userDictionary))
|
||||||
var composingText = ComposingText()
|
var composingText = ComposingText()
|
||||||
let inputStyle: InputStyle = self.roman2kana ? .roman2kana : .direct
|
let inputStyle: InputStyle = self.roman2kana ? .roman2kana : .direct
|
||||||
var lastCandidates: [Candidate] = []
|
var lastCandidates: [Candidate] = []
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
//
|
||||||
|
// File.swift
|
||||||
|
// AzooKeyKanakanjiConverter
|
||||||
|
//
|
||||||
|
// Created by miwa on 2025/07/21.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
Reference in New Issue
Block a user