mirror of
https://github.com/mii443/AzooKeyKanaKanjiConverter.git
synced 2025-12-03 02:58:27 +00:00
Introduce anco cli tool
This commit is contained in:
13
Sources/CliTool/Anco.swift
Normal file
13
Sources/CliTool/Anco.swift
Normal file
@@ -0,0 +1,13 @@
|
||||
import KanaKanjiConverterModuleWithDefaultDictionary
|
||||
import ArgumentParser
|
||||
|
||||
@main
|
||||
public struct Anco: ParsableCommand {
|
||||
public static var configuration = CommandConfiguration(
|
||||
abstract: "Anco is A(zooKey) Kana-Ka(n)ji (co)nverter",
|
||||
subcommands: [Subcommands.Run.self],
|
||||
defaultSubcommand: Subcommands.Run.self
|
||||
)
|
||||
|
||||
public init() {}
|
||||
}
|
||||
2
Sources/CliTool/Subcommands/Commands.swift
Normal file
2
Sources/CliTool/Subcommands/Commands.swift
Normal file
@@ -0,0 +1,2 @@
|
||||
/// namespace for subcommands
|
||||
enum Subcommands {}
|
||||
50
Sources/CliTool/Subcommands/RunCommand.swift
Normal file
50
Sources/CliTool/Subcommands/RunCommand.swift
Normal file
@@ -0,0 +1,50 @@
|
||||
import KanaKanjiConverterModuleWithDefaultDictionary
|
||||
import ArgumentParser
|
||||
import Foundation
|
||||
|
||||
extension Subcommands {
|
||||
struct Run: ParsableCommand {
|
||||
@Argument(help: "ひらがなで表記された入力")
|
||||
var input: String = ""
|
||||
|
||||
@Option(name: [.customLong("config_n_best")], help: "The parameter n (n best parameter) for internal viterbi search.")
|
||||
var configNBest: Int = 10
|
||||
@Option(name: [.customShort("n"), .customLong("top_n")], help: "Display top n candidates.")
|
||||
var displayTopN: Int = 1
|
||||
|
||||
@Flag(name: [.customLong("disable_prediction")], help: "Disable producing prediction candidates.")
|
||||
var disablePrediction = false
|
||||
|
||||
static var configuration = CommandConfiguration(commandName: "run", abstract: "Show help for this utility.")
|
||||
|
||||
@MainActor mutating func run() {
|
||||
let converter = KanaKanjiConverter()
|
||||
var composingText = ComposingText()
|
||||
composingText.insertAtCursorPosition(input, inputStyle: .direct)
|
||||
let result = converter.requestCandidates(composingText, options: requestOptions())
|
||||
for candidate in result.mainResults.prefix(self.displayTopN) {
|
||||
print(candidate.text)
|
||||
}
|
||||
}
|
||||
|
||||
func requestOptions() -> ConvertRequestOptions {
|
||||
.withDefaultDictionary(
|
||||
N_best: configNBest,
|
||||
requireJapanesePrediction: !disablePrediction,
|
||||
requireEnglishPrediction: false,
|
||||
keyboardLanguage: .ja_JP,
|
||||
typographyLetterCandidate: false,
|
||||
unicodeCandidate: true,
|
||||
englishCandidateInRoman2KanaInput: true,
|
||||
fullWidthRomanCandidate: false,
|
||||
halfWidthKanaCandidate: false,
|
||||
learningType: .nothing,
|
||||
maxMemoryCount: 0,
|
||||
shouldResetMemory: false,
|
||||
memoryDirectoryURL: URL(fileURLWithPath: ""),
|
||||
sharedContainerURL: URL(fileURLWithPath: ""),
|
||||
metadata: .init(appVersionString: "anco")
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user