Files
AzooKeyKanaKanjiConverter/Tests/KanaKanjiConverterModuleTests/LOUDSTests.swift
Miwa 55ffe3c708 [Experimental] Zenzai (#92)
* 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>
2024-05-15 01:36:45 +09:00

49 lines
1.9 KiB
Swift

//
// LOUDSTests.swift
// KanaKanjiConverterModuleTests
//
// Created by ensan on 2023/02/02.
// Copyright © 2023 ensan. All rights reserved.
//
@testable import KanaKanjiConverterModule
import XCTest
final class LOUDSTests: XCTestCase {
static let resourceURL = Bundle.module.resourceURL!.standardizedFileURL.appendingPathComponent("DictionaryMock", isDirectory: true)
func requestOptions() -> ConvertRequestOptions {
var options: ConvertRequestOptions = .default
options.dictionaryResourceURL = Self.resourceURL
return options
}
func loadCharIDs() -> [Character: UInt8] {
do {
let string = try String(contentsOf: Self.resourceURL.appendingPathComponent("louds/charID.chid", isDirectory: false), encoding: String.Encoding.utf8)
return [Character: UInt8](uniqueKeysWithValues: string.enumerated().map {($0.element, UInt8($0.offset))})
} catch {
print("ファイルが見つかりませんでした")
return [:]
}
}
func testSearchNodeIndex() throws {
//
print("Options: ", requestOptions())
let louds = LOUDS.load("", option: requestOptions())
XCTAssertNotNil(louds)
guard let louds else { return }
let charIDs = loadCharIDs()
let key = "シカイ"
let chars = key.map {charIDs[$0, default: .max]}
let index = louds.searchNodeIndex(chars: chars)
XCTAssertNotNil(index)
guard let index else { return }
let dicdata: [DicdataElement] = LOUDS.getDataForLoudstxt3("" + "\(index >> 11)", indices: [index & 2047], option: requestOptions())
XCTAssertTrue(dicdata.contains {$0.word == "司会"})
XCTAssertTrue(dicdata.contains {$0.word == "視界"})
XCTAssertTrue(dicdata.contains {$0.word == "死界"})
}
}