Skip to content
operational 7.57 KiB
Newer Older
* COMMENT -*- mode: org -*-
#+Date: 2019-04-05
Time-stamp: <2019-10-23>
#+STARTUP: content
* notes                                                               :entry:
** 2019-08-31 ibus-pinyin userdb inference notice.
zero-pinyin-service reuse ibus-pinyin's userdb at
~/.cache/ibus/pinyin/user-1.0.db

This is generally not a problem. But if ibus-pinyin changed their table schema
in the future, zero-pinyin-service may require update.

zero-pinyin-service also store user phrase in this db. So user phrases are
shared between zero-pinyin and ibus-pinyin.

** 2019-04-05 zero-pinyin-service file structure			:doc:
- zero-pinyin-service
  - main.c
    a console application based on glib and gio.
    provides dbus service. see the zero-pinyin-service spec at
    ~/c/gtk-im-module/operational :id001:
  - zero-pinyin-service.h
    zero-pinyin-service.c
    zero-pinyin-service-test.c

    contains the zero-pinyin-service dbus method C based implementation.
  - parse-pinyin.h
    parse-pinyin.cpp
    parse-pinyin-test.cpp

    contains utility functions based on code from libpyzyz. This should be
    replaced eventually. I don't want to depend on libpyzy source code.

- utilities
  - test-sql.sh
    a shell script to experiment SQL commands

- data files
  - meson.build

    build script. used to create executable.

  - com.emacsos.zero.ZeroPinyinService.service

    dbus service definition file.

    Should be copied to dbus service file dir /usr/share/dbus-1/services/

    When dbus client try to talk to service, dbus session bus will start the
    service app automatically.

* later                                                               :entry:
* current                                                             :entry:
** 
** 2019-10-23 bug: type "zhey" doesn't show 这样 candidate.
** 2019-10-22 handle a an o en etc differently. only match exactly the character.
no fuzzy matching or incomplete pinyin matching.

if shengmu is 0, always strict match it.
do not allow omit shengmu in zero.

ao men
澳门
e nuo
婀娜

- DONE use different FLAGS for them.
  FLAGS doesn't affect pinyin parsing.
  if flag support is to be added, just add it in appdata, as property.
  then use the property when building SQL.
- DONE test in bogon VM.
- DONE git push
- build on debian 9 and release deb. later.

- problems
  - result = parse_pinyin("an", 15, PINYIN_FUZZY_ALL);
    this only return 1 result.
    not an and ang.
    why?

  - maybe flag is not used when parsing pinyin string. only used when building
    the SQL statement.

    build_sql_for_n_pinyin()
    build_where_clause(pylist, n);
    yes. here. I should pass the flags around.

  - 

** 2019-08-31 how to format C code? do it before git commit.
see ~/c/gtk-im-module/, it uses myastyle-pre-commit-check in git pre-commit
~/bin/myastyle-pre-commit-check

** 2019-08-31 honor XDG cache dir.
~/.cache/ibus
** 2019-04-17 make flags configurable at runtime.
- add dbus method to set flags.
- make the method work. use gobject property maybe.
- set default flags to my flags. reflect this in UI/config file.
** 2019-10-22 support fuzzy pinyin.
- 0 no fuzzy
- 1 (0b1)
  z <-> zh
  c <-> ch
  s <-> sh
- 2 (0b10)
  l <-> n
- I won't implement other flags at this time.
- default is no fuzzy.
- test case:
  ru chi 如此
  ci di 此地
  e nuo 婀娜
  e luo
  ci yu 词语
  song 宋
  shong

- implementation
  - WONTFIX add a property in appdata.
    use a guint flag.
    only support 0b0 and 0b10 for now.

    Not necessary.
  - DONE add dbus interface to allow change the property at run time.
    property is added in dbus interface directly.
    app just read the property there. there is no network round trip.
    data is stored in the dbus service server side. not in dbus daemon.
  - DONE add flags in zero-el.
    this flag is NOT buffer local.
    (setq zero-pinyin-fuzzy-flag 3)
    it will set fuzzy mode when zero-pinyin-reset or zero-pinyin-init.
    (zero-pinyin-service-set-fuzzy-flag 3)
    it works.
- problems
  - can I make this change backward compatible?

    TODO what will happen when zero asks dbus to set FuzzyFlag property, if
    running an old zero-pinyin-service?
  - property generated code is okay.
  - how to access that property in zero-pinyin-service.c?
    guint zero_pinyin_service_get_fuzzy_flag (ZeroPinyinService *object);

    this is not the right way.
    because flag doesn't change much.
    should query once at start up, then listen to change event and update
    in-ram data. do not query dbus every time FuzzyFlag is needed.

    WONTFIX add event handler to update appdata->fuzzy_flag when property is
    changed.  // generated code handle set event and update g_object data in
    RAM automatically.

    signal org.freedesktop.DBus.Properties.PropertiesChanged

    see example in
    https://developer.gnome.org/gio/2.26/GDBusProxy.html

  - how to set the property in zero-el?
    call some dbus built-in service.

    (zero-pinyin-service-quit)
    run zero-pinyin-service in console
    (dbus-set-property :session "com.emacsos.zero.ZeroPinyinService1"
       "/com/emacsos/zero/ZeroPinyinService1"
       "com.emacsos.zero.ZeroPinyinService1.ZeroPinyinServiceInterface"
       "FuzzyFlag" 3)
    (dbus-set-property :session "com.emacsos.zero.ZeroPinyinService1"
       "/com/emacsos/zero/ZeroPinyinService1"
       "com.emacsos.zero.ZeroPinyinService1.ZeroPinyinServiceInterface"
       "FuzzyFlag" 0)

    I think generated code will handle set/get call.
    maybe just always get the value from
    zero_pinyin_service_get_fuzzy_flag(ZeroPinyinService *object)

    https://developer.gnome.org/gio/2.60/gdbus-codegen.html
    Server-side usage
    just use g_object_get() in server side. it will not talk to dbus.
    property change should be handled by generated code.

  - set property from emacs and read property in zero-pinyin-service.c
    works. but the fuzzy SQL logic is not working.

    when set to 3, shong can't produce 宋.

    enabled debug log.
    I see the problem.
    shong is not a valid py if fuzzy flag is not used during parsing.

    use correct parsing flag from FuzzyFlag when parsing.
  - now it works.

** 2019-08-31 choose maindb like my patched libpyzy.
- here is patched libpyzy maindb logic:
  files.push_back (m_user_data_dir + "/main.db");
  files.push_back (PKGDATADIR"/db/local.db");
  files.push_back (PKGDATADIR"/db/open-phrase.db");
  files.push_back (PKGDATADIR"/db/android.db");
  return first_existing_file (files);

  m_user_data_dir default is ~/.cache/ibus/pinyin/
  PKGDATADIR default is /usr/share/pyzy/

  in zero-pinyin-service, just use the first existing file:
  ~/.cache/ibus/pinyin/main.db
  /usr/share/pyzy/db/open-phrase.db
  /usr/share/pyzy/db/android.db

- should I reuse the ibus-pinyin userdb file?
  ~/.cache/ibus/pinyin/user-1.0.db

  yes. ibus-pinyin is not going away.

  DONE document this behavior in zero-el and zero-pinyin-service.

- init_userdb()
  sqlite3_mprintf()
  https://www.sqlite.org/c3ref/mprintf.html

  additional non-standard formats (%q, %Q, %w, and %z).
  |    | in   | out     | used for                                                 |
  |----+------+---------+----------------------------------------------------------|
  | %q | ab'c | ab''c   | SQL string literal                                       |
  | %Q | ab'c | 'ab''c' | SQL string literal                                       |
  | %w | ab"c | ab""c   | SQL identifier name                                      |
  | %z | abc  | abc     | like %s, but sqlite3_free() is called on param after use |