mirror of
https://github.com/mii443/AzooKeyKanaKanjiConverter.git
synced 2025-12-03 02:58:27 +00:00
perf: shouldBeRemovedよりも単純なフィルターを前に配置することで高速化・単純化
This commit is contained in:
@@ -54,10 +54,7 @@ extension Kana2Kanji {
|
||||
let nextIndex: Int = node.inputRange.endIndex
|
||||
// 文字数がcountと等しい場合登録する
|
||||
if nextIndex == count {
|
||||
for index in node.prevs.indices {
|
||||
let newnode: RegisteredNode = node.getRegisteredNode(index, value: node.values[index])
|
||||
result.prevs.append(newnode)
|
||||
}
|
||||
self.updateResultNode(with: node, resultNode: result)
|
||||
} else {
|
||||
self.updateNextNodes(with: node, nextNodes: nodes[nextIndex], nBest: N_best)
|
||||
}
|
||||
@@ -66,6 +63,12 @@ extension Kana2Kanji {
|
||||
return (result: result, lattice: Lattice(nodes: nodes))
|
||||
}
|
||||
|
||||
func updateResultNode(with node: LatticeNode, resultNode: LatticeNode) {
|
||||
for index in node.prevs.indices {
|
||||
let newnode: RegisteredNode = node.getRegisteredNode(index, value: node.values[index])
|
||||
resultNode.prevs.append(newnode)
|
||||
}
|
||||
}
|
||||
/// N-Best計算を高速に実行しつつ、遷移先ノードを更新する
|
||||
func updateNextNodes(with node: LatticeNode, nextNodes: [LatticeNode], nBest: Int) {
|
||||
for nextnode in nextNodes {
|
||||
|
||||
@@ -58,15 +58,10 @@ extension Kana2Kanji {
|
||||
}
|
||||
// 変換した文字数
|
||||
let nextIndex = node.inputRange.endIndex
|
||||
// 文字数がcountと等しくない場合は先に進む
|
||||
if nextIndex != count {
|
||||
self.updateNextNodes(with: node, nextNodes: lattice.nodes[nextIndex], nBest: N_best)
|
||||
} else {
|
||||
// countと等しければ変換が完成したので終了する
|
||||
for index in node.prevs.indices {
|
||||
let newnode = node.getRegisteredNode(index, value: node.values[index])
|
||||
result.prevs.append(newnode)
|
||||
}
|
||||
self.updateResultNode(with: node, resultNode: result)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -88,11 +88,7 @@ extension Kana2Kanji {
|
||||
}
|
||||
let nextIndex = node.inputRange.endIndex
|
||||
if count == nextIndex {
|
||||
// 最後に至るので
|
||||
for index in node.prevs.indices {
|
||||
let newnode = node.getRegisteredNode(index, value: node.values[index])
|
||||
result.prevs.append(newnode)
|
||||
}
|
||||
self.updateResultNode(with: node, resultNode: result)
|
||||
} else {
|
||||
self.updateNextNodes(with: node, nextNodes: terminalNodes.nodes[nextIndex], nBest: N_best)
|
||||
}
|
||||
|
||||
@@ -31,21 +31,14 @@ extension Kana2Kanji {
|
||||
let result = LatticeNode.EOSNode
|
||||
|
||||
for nodeArray in previousResult.lattice.nodes {
|
||||
for node in nodeArray {
|
||||
for node in nodeArray where node.inputRange.endIndex == count {
|
||||
if node.prevs.isEmpty {
|
||||
continue
|
||||
}
|
||||
if self.dicdataStore.shouldBeRemoved(data: node.data) {
|
||||
continue
|
||||
}
|
||||
let nextIndex = node.inputRange.endIndex
|
||||
if nextIndex == count {
|
||||
// 変換した文字数
|
||||
for (index, value) in node.values.enumerated() {
|
||||
let newnode = node.getRegisteredNode(index, value: value)
|
||||
result.prevs.append(newnode)
|
||||
}
|
||||
}
|
||||
self.updateResultNode(with: node, resultNode: result)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user