-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor Vertex and VertexSpans. * Deprecating NodeAnchor, removing unnecessary stable-sorts. * Add unit tests for fetchCandidates().
- Loading branch information
Showing
7 changed files
with
129 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Swiftified and further development by (c) 2022 and onwards The vChewing Project (MIT License). | ||
// Was initially rebranded from (c) Lukhnos Liu's C++ library "Gramambular 2" (MIT License). | ||
// ==================== | ||
// This code is released under the MIT license (SPDX-License-Identifier: MIT) | ||
|
||
import Megrez | ||
|
||
// MARK: - Megrez Extensions for Test Purposes Only. | ||
|
||
public extension Megrez.Compositor { | ||
/// 返回在當前位置的所有候選字詞(以詞音配對的形式)。如果組字器內有幅位、且游標 | ||
/// 位於組字器的(文字輸入順序的)最前方(也就是游標位置的數值是最大合規數值)的 | ||
/// 話,那麼這裡會用到 location - 1、以免去在呼叫該函式後再處理的麻煩。 | ||
/// - Remark: 該函式已被淘汰,因為有「無法徹底清除 node-crossing 內容」的故障。 | ||
/// 現僅用於單元測試、以確認其繼任者是否有給出所有該給出的正常結果。 | ||
/// - Parameter location: 游標位置。 | ||
/// - Returns: 候選字音配對陣列。 | ||
func fetchCandidatesDeprecated(at location: Int, filter: CandidateFetchFilter = .all) -> [Megrez.KeyValuePaired] { | ||
var result = [Megrez.KeyValuePaired]() | ||
guard !keys.isEmpty else { return result } | ||
let location = max(min(location, keys.count - 1), 0) // 防呆 | ||
let anchors: [(location: Int, node: Megrez.Node)] = fetchOverlappingNodes(at: location) | ||
let keyAtCursor = keys[location] | ||
anchors.map(\.node).forEach { theNode in | ||
theNode.unigrams.forEach { gram in | ||
switch filter { | ||
case .all: | ||
// 得加上這道篩選,不然會出現很多無效結果。 | ||
if !theNode.keyArray.contains(keyAtCursor) { return } | ||
case .beginAt: | ||
if theNode.keyArray[0] != keyAtCursor { return } | ||
case .endAt: | ||
if theNode.keyArray.reversed()[0] != keyAtCursor { return } | ||
} | ||
result.append(.init(keyArray: theNode.keyArray, value: gram.value)) | ||
} | ||
} | ||
return result | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters