Skip to content

feat: add lightweight user word registration (単語登録) tab#25

Open
presire wants to merge 1 commit into
7ka-Hiira:mainfrom
presire:feature/user-word-registration
Open

feat: add lightweight user word registration (単語登録) tab#25
presire wants to merge 1 commit into
7ka-Hiira:mainfrom
presire:feature/user-word-registration

Conversation

@presire

@presire presire commented Apr 14, 2026

Copy link
Copy Markdown

単語登録機能 ([単語登録]タブ) の追加

本PRはhazkey-settingshazkey-serverに単語登録機能を追加します。
AzooKeyKanaKanjiConverterには一切手を入れず、hazkey-server側の後処理レイヤとして実装しているため、上流コンバータへの変更は不要です。

既存の[辞書]タブ (プレースホルダ) が将来実装する本格的なユーザ辞書機能とは競合せず、棲み分け可能な設計にしています。

既存の[辞書]タブとの関係

[辞書]タブは、AzooKeyKanaKanjiConverter本体に組み込まれる本格的なユーザ辞書機能 (品詞情報・コスト・連接情報を持ち、文法解析や学習に参加する) のプレースホルダであり、
実現には上流コンバータへの変更が必要です。

一方、本PRで追加する[単語登録]タブは異なる、ミニマルなアプローチを取っています。

辞書 (プレースホルダ) 単語登録 (本PR)
実装層 AzooKeyKanaKanjiConverter内部 hazkey-serverの後処理
品詞・文法情報 あり (予定) なし
文中変換 可能 (予定) 不可 (完全一致のみ)
学習との連携 あり (予定) なし
上流変更の要否 必要 不要
主な用途 一般的な単語追加 メールアドレス・定型文・絵文字スニペット

両者は排他的ではありません。
将来、[辞書]タブに本格的なユーザ辞書機能が実装された後も、[単語登録]タブは単純な文字列置換用途の軽量な代替手段として残すことも、
役割を終えて削除することも可能です。

本PRで実装した内容

  • 新規ファイル:
    ~/.config/hazkey/user_dictionary.tsvよみ<TAB>単語<TAB>コメント 形式でエントリを保存
  • hazkey-server:
    起動時にTSVを読み込み、ファイルのmtimeを監視して自動リロード (サーバ再起動不要)
    候補生成時、入力よみと完全一致するエントリを候補リストの先頭に差し込みます。
    ユーザ辞書由来の候補を確定した場合は学習ストアをバイパスします。
  • hazkey-settings:
    [入力スタイル]タブと[辞書]タブの間に[単語登録]タブを追加。
    テーブルビューと追加・編集・削除ボタン、エントリ編集ダイアログを備えます。
    このタブはTSVファイルを直接読み書きするため、新しいIPCメッセージは一切導入していません。
  • protocol変更なし:
    protocol/*.protoは一切変更していないため、.pb.swiftの再生成も不要です。
  • 新しい文字列すべてに日本語訳を追加済み

既知の制限事項 (意図的なトレードオフ)

  1. 完全一致のみ:
    登録したよみの前方一致では候補に出ません。
  2. 品詞情報なし:
    文中変換には参加しません。
  3. 学習連携なし:
    登録語を選択しても変換頻度学習には影響しません。

これらはいずれも、機能を自己完結させAzooKeyKanaKanjiConverterに手を加えないための意図的な設計判断です。
本格的な辞書機能は、将来[辞書]タブで上流コンバータと統合する形で実装されることを想定しています。

Introduce a simple user-word registration feature that lets users register
(reading → word) pairs and have them surfaced at the top of the conversion
candidate list. The feature is implemented as a thin post-processing layer
in hazkey-server and a new tab in hazkey-settings, intentionally kept
independent from AzooKeyKanaKanjiConverter so that no upstream converter
changes are required.

This is complementary to — not a replacement for — the existing placeholder
"辞書" tab, which is reserved for a future full user dictionary that would
be integrated into the converter with part-of-speech, cost, and connection
information. The new "単語登録" tab covers the common "I just want my email
address to come up when I type an alias" use case today, without blocking
the proper dictionary work.

Storage
-------
Entries are stored in ~/.config/hazkey/user_dictionary.tsv as plain TSV:

    reading<TAB>word<TAB>comment

Lines starting with '#' and empty lines are ignored. Readings are
normalized to NFC for matching.

hazkey-server
-------------
* New userDictionary.swift: loads the TSV on startup and reloads it
  automatically when the file's mtime changes. No server restart or IPC
  round-trip is required after editing the file.
* state.swift: introduces a DisplayedCandidate enum so each displayed
  candidate is tagged as either .fromConverter(Candidate) or
  .fromUserDict(word:). During getCandidates(), entries whose reading
  exactly matches the current hiragana input are prepended to the
  candidate list. On commit, user-dictionary entries clear the composing
  text directly and bypass the converter's learning store.

hazkey-settings
---------------
* New UserDictTab (userdicttab.h / userdicttab.cpp): QTableWidget-based UI
  with Add / Edit / Delete buttons and a modal entry dialog. The tab reads
  and writes the TSV file directly — no new IPC messages are introduced.
* mainwindow.cpp: inserts the tab between "入力スタイル" and "辞書" using
  ui_->dictionaryTab as an anchor, so it stays correctly placed even if
  tab order changes later.
* CMakeLists.txt: registers the new sources.
* hazkey-settings_ja_JP.ts: Japanese translations for all new strings
  (tab label "単語登録", column headers, buttons, dialogs, error messages).

Protocol
--------
No changes to protocol/*.proto. The generated .pb.swift files are not
regenerated, so builds do not require protoc-gen-swift.

Known limitations (by design)
-----------------------------
* Exact full-reading match only; prefix matches are not surfaced.
* No part-of-speech information, so entries do not participate in
  mid-sentence conversion.
* Not integrated with the learning store; selecting a registered word
  does not influence conversion frequency.

These trade-offs keep the feature self-contained and allow it to ship
without touching AzooKeyKanaKanjiConverter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant