Skip to content

Commit 0a488a1

Browse files
committed
Improve deinflector
1 parent ea20cfc commit 0a488a1

File tree

8 files changed

+434
-226
lines changed

8 files changed

+434
-226
lines changed

Makefile

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ SDIR=src
99
LDIR=lib
1010

1111
CPPFLAGS += -D_POSIX_C_SOURCE=200809L -DNOTIFICATIONS -I$(IDIR)
12-
LDLIBS += -ffunction-sections -fdata-sections -Wl,--gc-sections \
13-
-lcurl -lmecab -pthread $(shell pkg-config --libs gtk+-3.0) $(shell pkg-config --libs libnotify) -llmdb
12+
LDLIBS +=-lcurl -lmecab -pthread $(shell pkg-config --libs gtk+-3.0) $(shell pkg-config --libs libnotify) -llmdb
13+
# LDLIBS+=-ffunction-sections -fdata-sections -Wl,--gc-sections
1414

1515
O_HAVEX11 := 1 # X11 integration
1616
ifeq ($(strip $(O_HAVEX11)),1)
1717
CPPFLAGS += -DHAVEX11
1818
LDLIBS += -lXfixes -lX11
1919
endif
2020

21-
CFLAGS := -Werror $(shell pkg-config --cflags gtk+-3.0) $(shell pkg-config --cflags libnotify) $(CFLAGS)
21+
CFLAGS := -Werror $(shell pkg-config --cflags gtk+-3.0) $(shell pkg-config --cflags libnotify)
2222
DEBUG_CFLAGS=-DDEBUG \
2323
-Wall -Wextra -Wpedantic -Wstrict-prototypes -Wdouble-promotion -Wshadow \
2424
-Wno-unused-parameter -Wno-sign-conversion -Wno-unused-function -Wpointer-arith \
2525
-Wmissing-prototypes -Wstrict-prototypes -Wstrict-overflow -Wcast-align \
2626
-fsanitize=leak,address,undefined -fsanitize-undefined-trap-on-error -fstack-protector-strong \
27-
-Og -ggdb
27+
-O0 -ggdb
2828
RELEASE_CFLAGS=-O3 -flto -march=native -Wmaybe-uninitialized
2929

3030
FILES=dictpopup.c util.c platformdep.c deinflector.c settings.c db.c ankiconnectc.c database.c jppron.c pdjson.c
@@ -33,12 +33,11 @@ SRC=$(addprefix $(SDIR)/,$(FILES))
3333
SRC_H=$(addprefix $(IDIR)/,$(FILES_H))
3434

3535

36-
CFLAGS_CREATE=-I$(IDIR) -isystem$(LIBDIR)/lmdb/libraries/liblmdb -D_POSIX_C_SOURCE=200809L $(shell pkg-config --cflags glib-2.0)
37-
LDLIBS_CREATE=-ffunction-sections -fdata-sections -Wl,--gc-sections \
38-
-lzip $(shell pkg-config --libs glib-2.0) -llmdb
36+
CFLAGS_CREATE=-I$(IDIR) -D_POSIX_C_SOURCE=200809L $(shell pkg-config --cflags glib-2.0)
37+
LDLIBS_CREATE=-lzip $(shell pkg-config --libs glib-2.0) -llmdb
3938

40-
FILES_CREATE=db.c pdjson.c util.c settings.c
41-
FILES_H_CREATE=db.h pdjson.h util.h buf.h settings.h
39+
FILES_CREATE=db.c pdjson.c util.c
40+
FILES_H_CREATE=db.h pdjson.h util.h buf.h
4241

4342
SRC_CREATE=$(addprefix $(SDIR)/,$(FILES_CREATE)) $(LMDB_FILES)
4443
SRC_H_CREATE=$(addprefix $(IDIR)/,$(FILES_H_CREATE))
@@ -57,6 +56,11 @@ dictpopup: $(SRC) $(SRC_H)
5756
dictpopup-create: $(SRC_CREATE) $(SRC_H_CREATE)
5857
$(CC) $(CFLAGS_CREATE) -o $@ $(SDIR)/dictpopup_create.c $(SRC_CREATE) $(LDLIBS_CREATE)
5958

59+
cli: $(SRC) $(SRC_H)
60+
$(CC) $(CFLAGS) $(DEBUG_CFLAGS) $(CPPFLAGS) -o $@ $(SDIR)/cli.c $(SRC) $(LDLIBS)
61+
deinflector: $(SRC) $(SRC_H)
62+
$(CC) $(CFLAGS) $(DEBUG_CFLAGS) -I$(IDIR) -DDEINFLECTOR_MAIN -o $@ $(SDIR)/deinflector.c $(SDIR)/util.c $(LDLIBS)
63+
6064
release:
6165
version=$$(git describe); prefix=dictpopup-$${version#v}; \
6266
git archive --prefix=$$prefix/ HEAD | gzip -9 >$$prefix.tar.gz
@@ -86,7 +90,7 @@ uninstall:
8690
$(CONFIG_DIR)/config.ini
8791

8892
clean:
89-
rm -f dictpopup dictpopup-create tests
93+
rm -f dictpopup dictpopup-create tests cli deinflector
9094

9195
tests: $(SRC) $(SRC_H)
9296
$(CC) $(CFLAGS) $(DEBUG_CFLAGS) $(CPPFLAGS) -o $@ $(SDIR)/tests.c $(SRC) $(LDLIBS)

TODO

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
## dictpopup
2-
High priority
3-
- Refactor
4-
- Allow for an easier replacement of the frontend
5-
- Expose API to frontend like init() and end()?
6-
-> Write a "Yomichan search"-like window application reusing the same backend
7-
- Create config file in ~/.config if not existent
2+
- Fix formating for JMDict and Jitendex
3+
- Write a "Yomichan search"-like window application
4+
- Include a small default dictionary (.mdb file)
5+
- Add ながら deinflection
86

97
Mid priority
108
- Implement the reading label as a text view to allow for editing -> initiate new search on Enter press
119
- Group terms by reading, allow for switching between different readings
1210
- Implement a small window to manually enter a search string instead of selecting
13-
- Expand deinflection list
1411
- Kanjify the word in the copied sentence according to the dictionary entry
1512
- Remove trailing spaces from user settings
1613
- Write a gui config tool
@@ -47,7 +44,6 @@ Low priority
4744
- Skip certain lines on definition add (without selection), e.g.:
4845
- しず か (しづ—) [1]【静か・▽閑か】
4946
-(形動)〔文〕ナリ
50-
- Add unit tests and do fuzzy testing
5147
- Put length of longest entry into the database under LENGTH_OF_LONGEST_ENTRY. Then limit the lookup by that length
5248
- Only important for an auto scan implementation though
5349

@@ -59,21 +55,15 @@ Low priority
5955
### Misc
6056
- If there is a dictionary entry for 恭しく even though 恭しい is present in the collection, then a red dot will be shown
6157
### Deinflection
62-
- 与ろうとする missing
6358
- やった gets deinflected to やつ
6459
- This can be fixed by reading in the 4th string of a Yomichan term-bank entry, which is:
6560
"String of space-separated rule identifiers for the definition which is used to validate deinflection.
6661
An empty string should be used for words which aren't inflected."
67-
- たいそう gets deinflected to たいい
68-
- 懐から becomes 懐く
69-
- 白けた gets deinflected to 白い
70-
- 目した only gets deinflected to 目す
71-
- はたきながら (should become はたく)
72-
- 挿げ(変わる)
7362
- に looks broken
63+
64+
Mecab problems:
7465
- 大正門 pulls 大誓文
75-
- Can't definlect 眠ろうとする, 粘ろうとする
76-
- 失われ、
66+
- 家名だ
7767

7868
freq:
7969
- いじらしい not present in all

src/cli.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "dictpopup.h"
2+
#include "util.h"
3+
4+
int main(int argc, char **argv) {
5+
dictpopup_t d = dictpopup_init(argc, argv);
6+
dictentry *dict = create_dictionary(&d);
7+
8+
for (size i = 0; i < dictlen(dict); i++) {
9+
dictentry_print(dict[i]);
10+
putchar('\n');
11+
}
12+
}

src/db.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ database_t db_open(char *dbpath, bool readonly) {
2727
unsigned int mapsize = 2097152000; // 2Gb
2828
C(mdb_env_set_mapsize(db.env, mapsize));
2929

30+
dbg("Opening db in path: %s", dbpath);
3031
C(mdb_env_open(db.env, dbpath, 0, 0664));
3132
C(mdb_txn_begin(db.env, NULL, 0, &db.txn));
3233

@@ -154,6 +155,7 @@ static s8 getdata(database_t *db, u32 id) {
154155
}
155156

156157
void db_get_dictents(database_t *db, s8 headword, dictentry *dict[static 1]) {
158+
dbg("Looking up: %.*s", (int)headword.len, (char *)headword.s);
157159

158160
size_t n_ids = 0;
159161
u32 *ids = get_ids(db, headword, &n_ids);

0 commit comments

Comments
 (0)