mirror of
https://github.com/mii443/AzooKeyKanaKanjiConverter.git
synced 2025-08-22 15:05:26 +00:00
feat: add forget memory test
This commit is contained in:
@ -226,7 +226,7 @@ public final class DicdataStore {
|
||||
}
|
||||
}
|
||||
|
||||
private func perfectMatchLOUDS(query: String, charIDs: [UInt8]) -> [Int] {
|
||||
func perfectMatchLOUDS(query: String, charIDs: [UInt8]) -> [Int] {
|
||||
guard let louds = self.loadLOUDS(query: query) else {
|
||||
return []
|
||||
}
|
||||
|
@ -626,7 +626,7 @@ final class LearningManager {
|
||||
debug("Error: louds/charID.chidが存在しません。このエラーは深刻ですが、テスト時には無視できる場合があります。Description: \(error)")
|
||||
}
|
||||
}
|
||||
private var char2UInt8: [Character: UInt8] = [:]
|
||||
var char2UInt8: [Character: UInt8] = [:]
|
||||
|
||||
static var today: UInt16 {
|
||||
UInt16(Int(Date().timeIntervalSince1970) / 86400) - 19000
|
||||
@ -662,6 +662,13 @@ final class LearningManager {
|
||||
self.options = newOptions
|
||||
return false
|
||||
}
|
||||
// 変更があったら`char2Int8`を読み込み直す
|
||||
if newOptions.dictionaryResourceURL != self.options.dictionaryResourceURL {
|
||||
Self.updateChar2Int8(bundleURL: newOptions.dictionaryResourceURL, target: &self.char2UInt8)
|
||||
}
|
||||
// ここで更新
|
||||
self.options = newOptions
|
||||
|
||||
// 学習の壊れ状態を確認
|
||||
self.memoryCollapsed = LongTermLearningMemory.memoryCollapsed(directoryURL: newOptions.memoryDirectoryURL)
|
||||
if self.memoryCollapsed && newOptions.learningType.needUsingMemory {
|
||||
@ -670,7 +677,7 @@ final class LearningManager {
|
||||
tempTrie: TemporalLearningMemoryTrie(),
|
||||
directoryURL: newOptions.memoryDirectoryURL,
|
||||
maxMemoryCount: newOptions.maxMemoryCount,
|
||||
char2UInt8: char2UInt8
|
||||
char2UInt8: self.char2UInt8
|
||||
)
|
||||
} catch {
|
||||
debug(#file, #function, "automatic merge failed", error)
|
||||
@ -681,12 +688,6 @@ final class LearningManager {
|
||||
// 学習データが壊れている状態であることを警告する
|
||||
debug(#file, #function, "LearningManager init: Memory Collapsed")
|
||||
}
|
||||
// 変更があったら`char2Int8`を読み込み直す
|
||||
if newOptions.dictionaryResourceURL != self.options.dictionaryResourceURL {
|
||||
Self.updateChar2Int8(bundleURL: newOptions.dictionaryResourceURL, target: &char2UInt8)
|
||||
}
|
||||
// ここで更新
|
||||
self.options = newOptions
|
||||
|
||||
switch self.options.learningType {
|
||||
case .inputAndOutput, .onlyOutput: break
|
||||
|
Binary file not shown.
@ -69,5 +69,42 @@ final class LearningMemoryTests: XCTestCase {
|
||||
let filesAfter = try FileManager.default.contentsOfDirectory(at: dir, includingPropertiesForKeys: nil)
|
||||
XCTAssertTrue(filesAfter.isEmpty)
|
||||
}
|
||||
|
||||
func testForgetMemory() throws {
|
||||
let dir = FileManager.default.temporaryDirectory.appendingPathComponent("LearningManagerPersistence-\(UUID().uuidString)", isDirectory: true)
|
||||
try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
|
||||
defer { try? FileManager.default.removeItem(at: dir) }
|
||||
|
||||
let options = self.getOptionsForMemoryTest(memoryDirectoryURL: dir)
|
||||
let manager = LearningManager()
|
||||
_ = manager.setRequestOptions(options)
|
||||
let element = DicdataElement(word: "テスト", ruby: "テスト", cid: CIDData.一般名詞.cid, mid: MIDData.一般.mid, value: -10)
|
||||
manager.update(data: [element])
|
||||
manager.save()
|
||||
|
||||
let dicdataStore = DicdataStore(requestOptions: options)
|
||||
dicdataStore.sendToDicdataStore(.setRequestOptions(options))
|
||||
let charIDs = "テスト".map { dicdataStore.character2charId($0) }
|
||||
let indices = dicdataStore.perfectMatchLOUDS(query: "memory", charIDs: charIDs)
|
||||
let dicdata = dicdataStore.getDicdataFromLoudstxt3(identifier: "memory", indices: indices)
|
||||
XCTAssertFalse(dicdata.isEmpty)
|
||||
XCTAssertTrue(dicdata.contains { $0.word == element.word && $0.ruby == element.ruby })
|
||||
|
||||
dicdataStore.sendToDicdataStore(
|
||||
.forgetMemory(
|
||||
Candidate(
|
||||
text: element.word,
|
||||
value: element.value(),
|
||||
correspondingCount: 3,
|
||||
lastMid: element.mid,
|
||||
data: [element]
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
let indices2 = dicdataStore.perfectMatchLOUDS(query: "memory", charIDs: charIDs)
|
||||
let dicdata2 = dicdataStore.getDicdataFromLoudstxt3(identifier: "memory", indices: indices2)
|
||||
XCTAssertFalse(dicdata2.contains { $0.word == element.word && $0.ruby == element.ruby })
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user