Skip to content

Commit

Permalink
Merge pull request #243 from mtgto/vu
Browse files Browse the repository at this point in the history
辞書の読みの「う゛」を「ゔ」に変換して読み込む
  • Loading branch information
mtgto authored Nov 4, 2024
2 parents 0e13612 + 42aa1ab commit ebb7267
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
5 changes: 4 additions & 1 deletion SKKServClient/SKKServClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ class SKKServClient: NSObject, SKKServClientProtocol {
logger.error("skkservへの接続ができていません")
return reply(nil, SKKServClientError.unexpected)
}
guard let encoded = yomi.data(using: .japaneseEUC) else {
// "ゔ" は Encoding.japaneseEUC では変換できないので「う゛」にしてから参照する。
// EUC-JIS-2004形式なら変換するのでそうしてもいいかも?
// ただSKK-JISYO.Lも「う゛」で登録されているので固定でいい気がする
guard let encoded = yomi.replacing("", with: "う゛").data(using: .japaneseEUC) else {
logger.error("見出しをDataに変換できませんでした")
return reply(nil, SKKServClientError.unexpected)
}
Expand Down
3 changes: 2 additions & 1 deletion macSKK/Entry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct Entry: Sendable {
/**
* SKK辞書の一行を受け取り、パースする
*
* 読みの「う゛」は「ゔ」に変換して返す。
* スラッシュで終わらないなど、変換候補エントリとして壊れている場合はnilを返す。
* 空文字列の変換候補を含む場合、現状の実装では除外して返す。
* 空文字列の変換候補には今後対応する予定。
Expand All @@ -30,7 +31,7 @@ struct Entry: Sendable {
if words.count != 2 || words[0].last == " " {
return nil
}
yomi = String(words[0])
yomi = String(words[0]).replacing("う゛", with: "")
guard let candidates = Self.parseWords(words[1], dictId: dictId) else { return nil }
// TODO: いまは空の変換候補をスキップしているが扱えるようにしたい
self.candidates = candidates.filter { !$0.word.isEmpty }
Expand Down
3 changes: 2 additions & 1 deletion macSKK/StateMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1304,8 +1304,9 @@ final class StateMachine {
}

/// 見出し語で辞書を引く。同じ文字列である変換候補が複数の辞書にある場合は最初の1つにまとめる。
/// 「う゛」は「ゔ」にしてから引く
@MainActor func candidates(for yomi: String, option: DictReferringOption? = nil) -> [Candidate] {
return Global.dictionary.referDicts(yomi, option: option)
return Global.dictionary.referDicts(yomi.replacing("う゛", with: ""), option: option)
}

/**
Expand Down
12 changes: 6 additions & 6 deletions macSKK/kana-rule.conf
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ whi,うぃ
wi,うぃ
whe,うぇ
we,うぇ
va,う゛ぁ,ヴァ,ヴァ
vi,う゛ぃ,ヴィ,ヴィ
vu,う゛,ヴ,ヴ
ve,う゛ぇ,ヴェ,ヴェ
vo,う゛ぉ,ヴォ,ヴォ
vyu,う゛ゅ,ヴュ,ヴュ
va,ゔぁ,ヴァ,ヴァ
vi,ゔぃ,ヴィ,ヴィ
vu,,ヴ,ヴ
ve,ゔぇ,ヴェ,ヴェ
vo,ゔぉ,ヴォ,ヴォ
vyu,ゔゅ,ヴュ,ヴュ
kwa,くぁ
qa,くぁ
kwi,くぃ
Expand Down
3 changes: 3 additions & 0 deletions macSKKTests/EntryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ final class EntryTests: XCTestCase {
// 送り仮名ブロックが閉じていない
entry = Entry(line: "いt /[った/行/", dictId: "")
XCTAssertEqual(entry?.candidates, [Word("[った"), Word("")])
// 読みにある「う゛」は「ゔ」として扱う
entry = Entry(line: "しう゛ぁ /湿婆/", dictId: "")
XCTAssertEqual(entry?.yomi, "しゔぁ")
}

func testInvalidLine() {
Expand Down
6 changes: 3 additions & 3 deletions macSKKTests/StateMachineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ final class StateMachineTests: XCTestCase {
expectation.expectedFulfillmentCount = 2
stateMachine.inputMethodEvent.collect(6).sink { events in
XCTAssertEqual(events[0], .markedText(MarkedText([.markerCompose, .plain("v")])))
XCTAssertEqual(events[1], .markedText(MarkedText([.markerCompose, .plain("う゛")])))
XCTAssertEqual(events[1], .markedText(MarkedText([.markerCompose, .plain("")])))
XCTAssertEqual(events[2], .fixedText(""))
XCTAssertEqual(events[3], .modeChanged(.katakana, .zero))
XCTAssertEqual(events[4], .markedText(MarkedText([.markerCompose, .plain("v")])))
Expand All @@ -626,9 +626,9 @@ final class StateMachineTests: XCTestCase {
}.store(in: &cancellables)
stateMachine.yomiEvent.collect(4).sink { events in
XCTAssertEqual(events[0], "")
XCTAssertEqual(events[1], "う゛")
XCTAssertEqual(events[1], "")
XCTAssertEqual(events[2], "")
XCTAssertEqual(events[3], "う゛")
XCTAssertEqual(events[3], "")
expectation.fulfill()
}.store(in: &cancellables)
XCTAssertTrue(stateMachine.handle(printableKeyEventAction(character: "v", withShift: true)))
Expand Down

0 comments on commit ebb7267

Please sign in to comment.