From b5f634f45e14e95d11de181e1a8d122293be720b Mon Sep 17 00:00:00 2001 From: Miwa / Ensan <63481257+ensan-hcl@users.noreply.github.com> Date: Mon, 22 Apr 2024 00:30:51 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20temporary=20memory=E3=81=AE=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E3=83=AD=E3=82=B8=E3=83=83=E3=82=AF=E3=81=AE=E3=83=90?= =?UTF-8?q?=E3=82=B0=E3=82=92=E4=BF=AE=E6=AD=A3=20(#81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: temporary memoryの更新ロジックのバグを修正 * unnecessary diff --- .../DicdataStore/LearningMemory.swift | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Sources/KanaKanjiConverterModule/DicdataStore/LearningMemory.swift b/Sources/KanaKanjiConverterModule/DicdataStore/LearningMemory.swift index 5911045..0ed147e 100644 --- a/Sources/KanaKanjiConverterModule/DicdataStore/LearningMemory.swift +++ b/Sources/KanaKanjiConverterModule/DicdataStore/LearningMemory.swift @@ -524,14 +524,16 @@ struct TemporalLearningMemoryTrie { if let dataIndex = nodes[index].dataIndices.first(where: {Self.sameDicdataIfRubyIsEqual(left: self.dicdata[$0], right: dicdataElement)}) { withMutableValue(&self.metadata[dataIndex]) { $0.count += min(.max - $0.count, 1) - // 雑な設定だが200年くらいは持つのでヨシ。 $0.lastUsedDay = day } + // adjustを更新する + self.dicdata[dataIndex].adjust = LongTermLearningMemory.valueForData(metadata: self.metadata[dataIndex], dicdata: dicdataElement) - dicdataElement.baseValue } else { let dataIndex = self.dicdata.endIndex var dicdataElement = dicdataElement let metadataElement = MetadataElement(day: day, count: 1) - dicdataElement.baseValue = LongTermLearningMemory.valueForData(metadata: metadataElement, dicdata: dicdataElement) + // adjustを更新する + dicdataElement.adjust = LongTermLearningMemory.valueForData(metadata: metadataElement, dicdata: dicdataElement) - dicdataElement.baseValue self.dicdata.append(dicdataElement) self.metadata.append(metadataElement) nodes[index].dataIndices.append(dataIndex) @@ -723,6 +725,10 @@ final class LearningManager { if var newFirstClause = firstClause { if var newSecondClause = secondClause { if DicdataStore.isClause(newFirstClause.rcid, datum.lcid) { + // 更新対象のindexでなければcontinueする + guard data.endIndex <= index else { + continue + } // firstClauseとsecondClauseがあって文節境界である場合, bigramを作って学習に入れる let element = DicdataElement( word: newFirstClause.word + newSecondClause.word, @@ -735,10 +741,6 @@ final class LearningManager { // firstClauseを押し出す firstClause = secondClause secondClause = datum - // 更新対象のindexでなければcontinueする - guard data.endIndex <= index else { - continue - } guard let chars = Self.keyToChars(element.ruby, char2UInt8: char2UInt8) else { continue }