* experimental rinna integration * Update impl * update * Bump swift-actions/setup-swift from 1 to 2 Bumps [swift-actions/setup-swift](https://github.com/swift-actions/setup-swift) from 1 to 2. - [Release notes](https://github.com/swift-actions/setup-swift/releases) - [Commits](https://github.com/swift-actions/setup-swift/compare/v1...v2) --- updated-dependencies: - dependency-name: swift-actions/setup-swift dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * change test * change impl * take gpt2 weight as option * don't use async * support status check * enhance error * avoid percent encode * update * GPT-2 based kana-kanji conversion is now perfectly workinggit statusgit status * fix a bug * Rename gpt2/llama -> zenz * cleanup * internal apiを綺麗にした * cleanup experimental commands * update * partially support incremental input using cache * fix names * fix bug * support roman2kana * cleanup * fix minor bugs * improve logic * fix minor bug * fix minor bug * fix minor bug * optimize * optimize performance * Optimize cache hit * cli: add anco session command * fix cache hit bugs * improve session commands * maybe this will work better for incremental input environment * speed up zenzai by using n_best alternatives * update zenz context * adding no_typo api * add inference limit * fix bug * reset install_cli * make package buildable -- but llama.cpp features just do not work at this point because metal is not preprocessed * add proper availability checks * change macOS minimum version * fix several problems * code cleanup * enable ubuntu build * fix build error * fix ubuntu build * fix borrowing * update install_cli.sh --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
AzooKeyKanaKanjiConverter
AzooKeyKanaKanjiConverterはazooKeyのために開発したかな漢字変換エンジンです。数行のコードでかな漢字変換をiOS / macOS / visionOSのアプリケーションに組み込むことができます。
動作環境
iOS 14以降, macOS 11以降, visionOS 1以降, Ubuntu 22.04以降で動作を確認しています。
AzooKeyKanaKanjiConverterの開発については開発ガイドをご覧ください。
KanaKanjiConverterModule
かな漢字変換を受け持つモジュールです。
セットアップ
-
Xcodeprojの場合、XcodeでAdd Packageしてください。
-
Swift Packageの場合、Package.swiftの
Package
の引数にdependencies
以下の記述を追加してください。dependencies: [ .package(url: "https://github.com/ensan-hcl/AzooKeyKanaKanjiConverter", .upToNextMinor(from: "0.7.0")) ],
また、ターゲットの
dependencies
にも同様に追加してください。.target( name: "MyPackage", dependencies: [ .product(name: "KanaKanjiConverterModuleWithDefaultDictionary", package: "AzooKeyKanaKanjiConverter") ], ),
Important
AzooKeyKanaKanjiConverterはバージョン1.0のリリースまで開発版として運用するため、マイナーバージョンの変更で破壊的変更を実施する可能性があります。バージョンを指定する際にはマイナーバージョンが上がらないよう、
.upToNextMinor(from: "0.7.0")
のように指定することを推奨します。
使い方
// デフォルト辞書つきの変換モジュールをインポート
import KanaKanjiConverterModuleWithDefaultDictionary
// 変換器を初期化する
let converter = KanaKanjiConverter()
// 入力を初期化する
var c = ComposingText()
// 変換したい文章を追加する
c.insertAtCursorPosition("あずーきーはしんじだいのきーぼーどあぷりです", inputStyle: .direct)
// 変換のためのオプションを指定して、変換を要求
let results = converter.requestCandidates(c, options: .withDefaultDictionary(...))
// 結果の一番目を表示
print(results.mainResults.first!.text) // azooKeyは新時代のキーボードアプリです
options: .withDefaultDictionary(...)
は、ConvertRequestOptions
を生成し、変換リクエストに必要な情報を指定します。詳しくはコード内のドキュメントコメントを参照してください。
ConvertRequestOptions
ConvertRequestOptions
は変換リクエストに必要な設定値です。例えば以下のように設定します。
let options = ConvertRequestOptions.withDefaultDictionary(
// 日本語予測変換
requireJapanesePrediction: true,
// 英語予測変換
requireEnglishPrediction: false,
// 入力言語
keyboardLanguage: .ja_JP,
// 学習タイプ
learningType: .nothing,
// 学習データを保存するディレクトリのURL(書類フォルダを指定)
memoryDirectoryURL: .documentsDirectory,
// ユーザ辞書データのあるディレクトリのURL(書類フォルダを指定)
sharedContainerURL: .documentsDirectory,
// メタデータ
metadata: .init(versionString: "You App Version X")
)
ComposingText
ComposingText
は入力管理を行いつつ変換をリクエストするためのAPIです。ローマ字入力などを適切にハンドルするために利用できます。詳しくはドキュメントを参照してください。
辞書データ
AzooKeyKanaKanjiConverterのデフォルト辞書としてazooKey_dictionary_storageがサブモジュールとして指定されています。過去のバージョンの辞書データはGoogle Driveからもダウンロードすることができます。
また、以下のフォーマットであれば自前で用意した辞書データを利用することもできます。カスタム辞書データのサポートは限定的なので、ソースコードを確認の上ご利用ください。
- Dictionary/
- louds/
- charId.chid
- X.louds
- X.loudschars2
- X.loudstxt3
- ...
- p/
- X.csv
- cb/
- 0.binary
- 1.binary
- ...
- mm.binary
デフォルト以外の辞書データを利用する場合、ターゲットのdependencies
に以下を追加してください。
.target(
name: "MyPackage",
dependencies: [
.product(name: "KanaKanjiConverterModule", package: "AzooKeyKanaKanjiConverter")
],
),
利用時に、辞書データのディレクトリを明示的に指定する必要があります。
// デフォルト辞書を含まない変換モジュールを指定
import KanaKanjiConverterModule
let options = ConvertRequestOptions(
// 日本語予測変換
requireJapanesePrediction: true,
// 英語予測変換
requireEnglishPrediction: false,
// 入力言語
keyboardLanguage: .ja_JP,
// 学習タイプ
learningType: .nothing,
// ここが必要
// 辞書データのURL(先ほど追加した辞書リソースを指定)
dictionaryResourceURL: Bundle.main.bundleURL.appending(path: "Dictionary", directoryHint: .isDirectory),
// 学習データを保存するディレクトリのURL(書類フォルダを指定)
memoryDirectoryURL: .documentsDirectory,
// ユーザ辞書データのあるディレクトリのURL(書類フォルダを指定)
sharedContainerURL: .documentsDirectory,
// メタデータ
metadata: .init(versionString: "You App Version X")
)
dictionaryResourceURL
のオプションはKanaKanjiConverterModuleWithDefaultDictionary
モジュールでも利用できますが、バンドルに含まれる辞書リソースが利用されないため、アプリケーションサイズが不必要に大きくなります。デフォルトでない辞書データを利用する場合はKanaKanjiConverterModule
を利用してください。
SwiftUtils
Swift一般に利用できるユーティリティのモジュールです。