Newer
Older
* COMMENT -*- mode: org -*-
#+Date: 2019-04-05
Time-stamp: <2023-08-15>
#+STARTUP: content
* notes :entry:
** 2020-02-02 documents
- Wrap best practices and tips
https://mesonbuild.com/Wrap-best-practices-and-tips.html
- meson build Reference manual
https://mesonbuild.com/Reference-manual.html
-
** 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.
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
** 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.
** 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
** 2023-08-15 how to build from source :doc:
- dependencies
- RHEL
sudo dnf install -y gcc-c++ libuuid-devel sqlite-devel gtk3-devel python3-pip
- Debian
sudo apt install -y g++ uuid-dev libsqlite3-dev libgtk-3-dev python3-pip
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
- meson build tool
python3 -m pip install --user meson ninja
- do a debug/release build
get source code. This project requires libpyzy.
mkdir ~/fromsource/
git clone git@gitlab.emacsos.com:sylecn/libpyzy.git
cd libpyzy/src/
git clone git@gitlab.emacsos.com:sylecn/zero-pinyin-service.git
cd zero-pinyin-service/
This is project root dir.
in project root dir,
# for debug build, do not include "--buildtype release" param
meson setup --buildtype release build/
cd build && ninja
- to run the built binary
get phrases db, they are available in libpyzy in debian.
you can download the deb and unpack it
https://packages.debian.org/bookworm/libpyzy-1.0-0v5
put your main phrase database at any of these position:
/usr/share/pyzy/db/open-phrase.db
~/.cache/ibus/pinyin/main.db
put your user phrase database at:
~/.cache/ibus/pinyin/user-1.0.db
now it's ready to run zero-pinyin-service.
in project root dir,
./build/zero-pinyin-service
** 2020-02-16 how to create deb for distribution on apt repo?
- on dev node, test deb, make sure it works.
git push
- on debian 9 x86 and x64 build server,
git pull
./create-deb.sh
- upload deb to aptly node using scp.
- create aptly distribution, snapshot and publish snapshot.
on aptly node,
aptly repo add d [FILE|DIR]...
aptly snapshot list
version=0.1
aptly snapshot create d-$version from repo d
# initial snapshot publish
# aptly publish snapshot \
# -batch -gpg-key=apt@emacsos.com -passphrase-file=/etc/aptly_pass \
# d-$version
# future publishes, switch publish to new snapshot
aptly publish switch \
-batch -gpg-key=apt@emacsos.com -passphrase-file=/etc/aptly_pass \
debian d-$version
* later :entry:
* current :entry:
**
** 2023-08-15 try build zero-pinyin-service for RHEL9
- problems
- maindb is empty. I need libpyzy's db.
on rh901,
mkdir -p ~/.cache/ibus/pinyin/
on lat21,
scp ~/.cache/ibus/pinyin/main.db rh901:.cache/ibus/pinyin/
also copy my user db. now that I am here.
scp ~/.cache/ibus/pinyin/user-1.0.db rh901:.cache/ibus/pinyin/
yes. it only needs the phrases db.
libpyzy lib is not needed at runtime.
- I should really get an alternative panel using emacs facility.
it's easier to test when I don't have access to GUI env.
** 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.
* done :entry:
** 2020-02-16 aptly publish fails
- ERROR: prefix/distribution already used by another published repo
#+BEGIN_SRC sh
root@gcpsgp01:~/d# aptly publish snapshot \
> -batch -gpg-key=apt@emacsos.com -passphrase-file=/etc/aptly_pass \
> d-$version
ERROR: prefix/distribution already used by another published repo: ./debian [amd64, i386] publishes {main: [d-0.1]: Snapshot from local repo [d]}
#+END_SRC
try unpublish old snapshot
aptly publish drop debian?
aptly publish switch -batch -gpg-key=apt@emacsos.com -passphrase-file=/etc/aptly_pass debian d-$version
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
** 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.
-
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
** 2020-02-02 how to use zero-pinyin-service dbus service using C client?
see example in ~/c/gtk-im-module/zero-pinyin.c
#include <zero-pinyin-service-generated.h>
- WONTFIX make zero-pinyin-generated a library.
- I choose to include the dbus xml in the project, and generated new header/C
files there. Still need to define a few const for object name etc though.
- problems
- only an so (libzero-pinyin-generated.so) is generated.
how to install header files?
search: meson library() how to install headers?
install_headers()
- search: meson install_headers from generated source file
Generated headers cannot be installed directly · Issue #705 · mesonbuild/meson
https://github.com/mesonbuild/meson/issues/705
foo.vapi files generated by Vala library() should be installed · Issue #891 · mesonbuild/meson
https://github.com/mesonbuild/meson/issues/891
use install_data to install header files myself.
#+BEGIN_SRC sh
install_data(meson.current_build_dir() + '/foo.vapi',
install_dir: 'share/vala/vapi')
install_data(meson.current_build_dir() + '/foo@sha/Foo-1.0.gir',
install_dir: 'share/gir-1.0')
#+END_SRC
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
** 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?
DONE what will happen when zero asks dbus to set FuzzyFlag property, if
dbus-set-property returns nil if the property doesn't exist.
I will show a warning.
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
- 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.
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
** 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 |
** 2019-10-23 bug: type "zhey" doesn't show 这样 candidate. :invalid:
- 2020-02-16 can't reproduce this.