From 7af6d81ef6032099f4b5799b03460cf978cb6515 Mon Sep 17 00:00:00 2001 From: Miwa / Ensan Date: Sun, 1 Jun 2025 21:39:33 +0900 Subject: [PATCH] feat: add forget memory test --- .../DicdataStore/DicdataStore.swift | 2 +- .../DicdataStore/LearningMemory.swift | 17 ++++---- .../DictionaryMock/louds/charID.chid | Bin 552 -> 527 bytes .../LearningMemoryTests.swift | 37 ++++++++++++++++++ 4 files changed, 47 insertions(+), 9 deletions(-) diff --git a/Sources/KanaKanjiConverterModule/DicdataStore/DicdataStore.swift b/Sources/KanaKanjiConverterModule/DicdataStore/DicdataStore.swift index a8f7c28..eaf2104 100644 --- a/Sources/KanaKanjiConverterModule/DicdataStore/DicdataStore.swift +++ b/Sources/KanaKanjiConverterModule/DicdataStore/DicdataStore.swift @@ -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 [] } diff --git a/Sources/KanaKanjiConverterModule/DicdataStore/LearningMemory.swift b/Sources/KanaKanjiConverterModule/DicdataStore/LearningMemory.swift index 5bc14c7..fe0c6a0 100644 --- a/Sources/KanaKanjiConverterModule/DicdataStore/LearningMemory.swift +++ b/Sources/KanaKanjiConverterModule/DicdataStore/LearningMemory.swift @@ -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 diff --git a/Tests/KanaKanjiConverterModuleTests/DictionaryMock/louds/charID.chid b/Tests/KanaKanjiConverterModuleTests/DictionaryMock/louds/charID.chid index ad2392bb710cf3c30414273722e5d03c7a6bb1b8..2a6c2adce4e3c6d21a7cc5a74270cbd017ebf6fc 100644 GIT binary patch delta 22 dcmZ3%($BJhiQo2d`)&