The dictionary thread ran in imthread's own proc, so a lookup could only start once the engine blocked, and it was a trie probe anyway; the emoji and Hanja searches already called dictlookup directly. The request/result channels, sequence numbers, staleness checks and the second draw per Japanese key are gone; dictqjp fills the candidates in place. Emit.dict and Lang.dictq only ever triggered lookups for Vietnamese, which has no dictionary. dictlookup(Lang*, key, out, max) returns the count. The Hanja lookup no longer pre-checks for a single syllable; a reading either has an entry or it does not.
60 lines
1.1 KiB
C
60 lines
1.1 KiB
C
#include "dat.h"
|
|
#include "fn.h"
|
|
|
|
/*
|
|
* Fills out[] with up to max candidates for key: the space-separated words
|
|
* of the entry, minus the key itself except in the emoji dictionary, where
|
|
* a query may name its own answer.
|
|
*/
|
|
int
|
|
dictlookup(Lang *l, Str *key, Str *out, int max)
|
|
{
|
|
char *p, *e, *sp;
|
|
Str tmp;
|
|
int n, vlen;
|
|
|
|
if(l == nil || key->n == 0 ||
|
|
trielookup(l->dict, key, &p, &vlen) != TrieExact)
|
|
return 0;
|
|
n = 0;
|
|
e = p + vlen;
|
|
while(n < max && p < e){
|
|
while(p < e && *p == ' ')
|
|
p++;
|
|
sp = p;
|
|
while(p < e && *p != ' ')
|
|
p++;
|
|
if(sinit(&tmp, sp, p - sp) && tmp.n > 0 &&
|
|
(l->lang == LangEMOJI || scmp(&tmp, key) != 0))
|
|
out[n++] = tmp;
|
|
}
|
|
return n;
|
|
}
|
|
|
|
static Trie*
|
|
langopen(char *dir, char *name, char *ext)
|
|
{
|
|
char *path;
|
|
Trie *t;
|
|
|
|
path = smprint("%s/%s.%s", dir, name, ext);
|
|
if(path == nil)
|
|
die("out of memory");
|
|
t = trieopen(path);
|
|
free(path);
|
|
return t;
|
|
}
|
|
|
|
void
|
|
langinit(char *dir)
|
|
{
|
|
Lang *l;
|
|
|
|
for(l = langs; l < langs + nlang; l++){
|
|
if(l->mapname != nil)
|
|
l->map = langopen(dir, l->mapname, "map");
|
|
if(l->dictname != nil)
|
|
l->dict = langopen(dir, l->dictname, "dict");
|
|
}
|
|
}
|