From 7b520e57931fa79693df19f09826cd4286e89544 Mon Sep 17 00:00:00 2001 From: Miwa / Ensan Date: Mon, 21 Jul 2025 18:01:05 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20possibleNexts=E3=82=92=E6=89=8B?= =?UTF-8?q?=E5=8B=95=E3=81=A7=E5=88=97=E6=8C=99=E3=81=9B=E3=81=9A=E3=80=81?= =?UTF-8?q?=E8=87=AA=E5=8B=95=E3=81=A7=E5=88=97=E6=8C=99=E3=81=A7=E3=81=8D?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DictionaryManagement/DicdataStore.swift | 64 +++---------------- .../DicdataStoreTests/DicdataStoreTests.swift | 7 ++ 2 files changed, 17 insertions(+), 54 deletions(-) diff --git a/Sources/KanaKanjiConverterModule/DictionaryManagement/DicdataStore.swift b/Sources/KanaKanjiConverterModule/DictionaryManagement/DicdataStore.swift index f72db8c..772f7db 100644 --- a/Sources/KanaKanjiConverterModule/DictionaryManagement/DicdataStore.swift +++ b/Sources/KanaKanjiConverterModule/DictionaryManagement/DicdataStore.swift @@ -1028,58 +1028,14 @@ public final class DicdataStore { return true } - static let possibleNexts: [String: [String]] = [ - "x": ["ァ", "ィ", "ゥ", "ェ", "ォ", "ッ", "ャ", "ュ", "ョ", "ヮ"], - "l": ["ァ", "ィ", "ゥ", "ェ", "ォ", "ッ", "ャ", "ュ", "ョ", "ヮ"], - "xt": ["ッ"], - "lt": ["ッ"], - "xts": ["ッ"], - "lts": ["ッ"], - "xy": ["ャ", "ュ", "ョ"], - "ly": ["ャ", "ュ", "ョ"], - "xw": ["ヮ"], - "lw": ["ヮ"], - "v": ["ヴ"], - "k": ["カ", "キ", "ク", "ケ", "コ"], - "q": ["クァ", "クィ", "クゥ", "クェ", "クォ"], - "qy": ["クャ", "クィ", "クュ", "クェ", "クョ"], - "qw": ["クヮ", "クィ", "クゥ", "クェ", "クォ"], - "ky": ["キャ", "キィ", "キュ", "キェ", "キョ"], - "g": ["ガ", "ギ", "グ", "ゲ", "ゴ"], - "gy": ["ギャ", "ギィ", "ギュ", "ギェ", "ギョ"], - "s": ["サ", "シ", "ス", "セ", "ソ"], - "sy": ["シャ", "シィ", "シュ", "シェ", "ショ"], - "sh": ["シャ", "シィ", "シュ", "シェ", "ショ"], - "z": ["ザ", "ジ", "ズ", "ゼ", "ゾ"], - "zy": ["ジャ", "ジィ", "ジュ", "ジェ", "ジョ"], - "j": ["ジ"], - "t": ["タ", "チ", "ツ", "テ", "ト"], - "ty": ["チャ", "チィ", "チュ", "チェ", "チョ"], - "ts": ["ツ"], - "th": ["テャ", "ティ", "テュ", "テェ", "テョ"], - "tw": ["トァ", "トィ", "トゥ", "トェ", "トォ"], - "cy": ["チャ", "チィ", "チュ", "チェ", "チョ"], - "ch": ["チ"], - "d": ["ダ", "ヂ", "ヅ", "デ", "ド"], - "dy": ["ヂャ", "ヂィ", "ヂュ", "ヂェ", "ヂョ"], - "dh": ["デャ", "ディ", "デュ", "デェ", "デョ"], - "dw": ["ドァ", "ドィ", "ドゥ", "ドェ", "ドォ"], - "n": ["ナ", "ニ", "ヌ", "ネ", "ノ", "ン"], - "ny": ["ニャ", "ニィ", "ニュ", "ニェ", "ニョ"], - "h": ["ハ", "ヒ", "フ", "ヘ", "ホ"], - "hy": ["ヒャ", "ヒィ", "ヒュ", "ヒェ", "ヒョ"], - "hw": ["ファ", "フィ", "フェ", "フォ"], - "f": ["フ"], - "b": ["バ", "ビ", "ブ", "ベ", "ボ"], - "by": ["ビャ", "ビィ", "ビュ", "ビェ", "ビョ"], - "p": ["パ", "ピ", "プ", "ペ", "ポ"], - "py": ["ピャ", "ピィ", "ピュ", "ピェ", "ピョ"], - "m": ["マ", "ミ", "ム", "メ", "モ"], - "my": ["ミャ", "ミィ", "ミュ", "ミェ", "ミョ"], - "y": ["ヤ", "ユ", "イェ", "ヨ"], - "r": ["ラ", "リ", "ル", "レ", "ロ"], - "ry": ["リャ", "リィ", "リュ", "リェ", "リョ"], - "w": ["ワ", "ウィ", "ウェ", "ヲ"], - "wy": ["ヰ", "ヱ"] - ] + static let possibleNexts: [String: [String]] = { + var results: [String: [String]] = [:] + for (key, value) in Roman2Kana.katakanaChanges { + for prefixCount in 0 ..< key.count where 0 < prefixCount { + let prefix = String(key.prefix(prefixCount)) + results[prefix, default: []].append(value) + } + } + return results + }() } diff --git a/Tests/KanaKanjiConverterModuleWithDefaultDictionaryTests/DicdataStoreTests/DicdataStoreTests.swift b/Tests/KanaKanjiConverterModuleWithDefaultDictionaryTests/DicdataStoreTests/DicdataStoreTests.swift index 185fea5..3b8d0fb 100644 --- a/Tests/KanaKanjiConverterModuleWithDefaultDictionaryTests/DicdataStoreTests/DicdataStoreTests.swift +++ b/Tests/KanaKanjiConverterModuleWithDefaultDictionaryTests/DicdataStoreTests/DicdataStoreTests.swift @@ -329,4 +329,11 @@ final class DicdataStoreTests: XCTestCase { XCTAssertEqual(dynamicUserDictResult?.data.metadata, .isFromUserDictionary) } } + + func testPossibleNexts() throws { + let possibleNexts = DicdataStore.possibleNexts + XCTAssertEqual(Set(possibleNexts["f", default: []]).symmetricDifference(["ファ", "フィ", "フ", "フェ", "フォ", "フャ", "フュ", "フョ", "フゥ"]), []) + XCTAssertEqual(Set(possibleNexts["xy", default: []]).symmetricDifference(["ャ", "ョ", "ュ"]), []) + XCTAssertEqual(possibleNexts["", default: []], []) + } }