mirror of
https://github.com/mii443/AzooKeyKanaKanjiConverter.git
synced 2025-12-03 02:58:27 +00:00
refactor: apiを追加
This commit is contained in:
@@ -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)})
|
||||
// 「i文字目から始まるnodes」に対して
|
||||
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) {
|
||||
|
||||
@@ -61,7 +61,7 @@ extension Kana2Kanji {
|
||||
Array(($0.data.reduce(into: "") { $0.append(contentsOf: $1.word)} + node.data.word).utf8)
|
||||
}
|
||||
// nodeの繋がる次にあり得る全てのnextnodeに対して
|
||||
for nextnode in lattice.nodes[nextIndex] {
|
||||
for nextnode in lattice[inputIndex: nextIndex] {
|
||||
// クラスの連続確率を計算する。
|
||||
let ccValue: PValue = self.dicdataStore.getCCValue(node.data.rcid, nextnode.data.lcid)
|
||||
// nodeの持っている全てのprevnodeに対して
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,4 +25,10 @@ struct Lattice {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
subscript(inputIndex i: Int) -> [LatticeNode] {
|
||||
get {
|
||||
self.nodes[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user