refactor: apiを追加

This commit is contained in:
Miwa / Ensan
2025-07-09 00:01:25 +09:00
parent c55fd4925c
commit 632ce251c7
5 changed files with 14 additions and 8 deletions

View File

@@ -30,9 +30,9 @@ extension Kana2Kanji {
debug("新規に計算を行います。inputされた文字列は\(inputData.input.count)文字分の\(inputData.convertTarget)")
let count: Int = inputData.input.count
let result: LatticeNode = LatticeNode.EOSNode
let nodes: [[LatticeNode]] = (.zero ..< count).map {dicdataStore.getLOUDSDataInRange(inputData: inputData, from: $0, needTypoCorrection: needTypoCorrection)}
let lattice: Lattice = Lattice(nodes: (.zero ..< count).map {dicdataStore.getLOUDSDataInRange(inputData: inputData, from: $0, needTypoCorrection: needTypoCorrection)})
// inodes
for (i, nodeArray) in nodes.enumerated() {
for (i, nodeArray) in lattice.nodes.enumerated() {
// node
for node in nodeArray {
if node.prevs.isEmpty {
@@ -56,11 +56,11 @@ extension Kana2Kanji {
if nextIndex == count {
self.updateResultNode(with: node, resultNode: result)
} else {
self.updateNextNodes(with: node, nextNodes: nodes[nextIndex], nBest: N_best)
self.updateNextNodes(with: node, nextNodes: lattice[inputIndex: nextIndex], nBest: N_best)
}
}
}
return (result: result, lattice: Lattice(nodes: nodes))
return (result: result, lattice: lattice)
}
func updateResultNode(with node: LatticeNode, resultNode: LatticeNode) {

View File

@@ -61,7 +61,7 @@ extension Kana2Kanji {
Array(($0.data.reduce(into: "") { $0.append(contentsOf: $1.word)} + node.data.word).utf8)
}
// nodenextnode
for nextnode in lattice.nodes[nextIndex] {
for nextnode in lattice[inputIndex: nextIndex] {
//
let ccValue: PValue = self.dicdataStore.getCCValue(node.data.rcid, nextnode.data.lcid)
// nodeprevnode

View File

@@ -59,7 +59,7 @@ extension Kana2Kanji {
//
let nextIndex = node.inputRange.endIndex
if nextIndex != count {
self.updateNextNodes(with: node, nextNodes: lattice.nodes[nextIndex], nBest: N_best)
self.updateNextNodes(with: node, nextNodes: lattice[inputIndex: nextIndex], nBest: N_best)
} else {
self.updateResultNode(with: node, resultNode: result)
}

View File

@@ -57,7 +57,7 @@ extension Kana2Kanji {
}
//
let nextIndex = node.inputRange.endIndex
self.updateNextNodes(with: node, nextNodes: addedNodes.nodes[nextIndex], nBest: N_best)
self.updateNextNodes(with: node, nextNodes: addedNodes[inputIndex: nextIndex], nBest: N_best)
}
}
lattice.merge(addedNodes)
@@ -90,7 +90,7 @@ extension Kana2Kanji {
if count == nextIndex {
self.updateResultNode(with: node, resultNode: result)
} else {
self.updateNextNodes(with: node, nextNodes: terminalNodes.nodes[nextIndex], nBest: N_best)
self.updateNextNodes(with: node, nextNodes: terminalNodes[inputIndex: nextIndex], nBest: N_best)
}
}
}

View File

@@ -25,4 +25,10 @@ struct Lattice {
}
}
}
subscript(inputIndex i: Int) -> [LatticeNode] {
get {
self.nodes[i]
}
}
}