wip: test is not passing, but commit/push it for

working in another env
This commit is contained in:
Miwa / Ensan
2025-07-14 00:42:53 +09:00
parent ee17b238a2
commit 02fcdd4dc1
6 changed files with 310 additions and 87 deletions

View File

@ -31,10 +31,35 @@ extension Kana2Kanji {
let inputCount: Int = inputData.input.count
let surfaceCount = inputData.convertTarget.count
let result: LatticeNode = LatticeNode.EOSNode
let i2sMap = inputData.inputIndexToSurfaceIndexMap()
var rawNodes = (.zero ..< inputCount).map {
let surfaceRange: (startIndex: Int, endIndexRange: Range<Int>?)? = if let sIndex = i2sMap[$0] {
(sIndex, nil)
} else {
nil
}
return dicdataStore.getLOUDSDataInRange(
inputData: inputData,
from: $0,
surfaceRange: surfaceRange,
needTypoCorrection: needTypoCorrection
)
}
for sIndex in 0 ..< inputData.convertTarget.count where !i2sMap.values.contains(sIndex) {
// inputIndexsIndexrawNodes
rawNodes.append(
dicdataStore.getLOUDSDataInRange(
inputData: inputData,
from: nil,
surfaceRange: (sIndex, nil),
needTypoCorrection: needTypoCorrection
)
)
}
let lattice: Lattice = Lattice(
inputCount: inputCount,
surfaceCount: surfaceCount,
rawNodes: (.zero ..< inputCount).map {dicdataStore.getLOUDSDataInRange(inputData: inputData, from: $0, needTypoCorrection: needTypoCorrection)}
rawNodes: rawNodes
)
// inodes
for (i, nodeArray) in lattice.indexedNodes() {
@ -55,8 +80,12 @@ extension Kana2Kanji {
// values
node.values = node.prevs.map {$0.totalValue + wValue}
}
//
let nextIndex = node.range.endIndex
// index
let nextIndex: Lattice.LatticeIndex = switch node.range.endIndex {
case .input(let index): if let sIndex = i2sMap[index] { .surface(sIndex) } else { node.range.endIndex }
case .surface: node.range.endIndex
}
print(nextIndex, node.data.word, node.data.ruby, lattice[index: nextIndex].count)
// count
if nextIndex == .input(inputCount) || nextIndex == .surface(surfaceCount) {
self.updateResultNode(with: node, resultNode: result)