mirror of
https://github.com/patarapolw/cjdic2.git
synced 2026-11-08 17:35:18 +00:00
word segmentation and clipboard first word detector
This commit is contained in:
1 parent
29a4d14893
commit
1614db6e99
19 files changed
+502
-13
No files matched your search
@@ -94,7 +94,9 @@ function SearchPage() {
|
||||
}
|
||||
|
||||
async function runSearch(isNew = true) {
|
||||
let norm_q = q.trim();
|
||||
let norm_q = q.split(" ")[0].trim();
|
||||
const isFromSplit = norm_q !== q.trim();
|
||||
|
||||
if (isAutoKana) {
|
||||
norm_q = norm_q.replace(/n$/i, "ん").replace(/[a-z]$/i, "");
|
||||
}
|
||||
@@ -132,6 +134,22 @@ function SearchPage() {
|
||||
});
|
||||
|
||||
if (isNew) {
|
||||
if (!result.length && !isFromSplit && ender === "" && q.length > 2) {
|
||||
const segs = await invoke<{ surface: string }[]>("tokenize", {
|
||||
text: q,
|
||||
});
|
||||
if (segs.length > 1) {
|
||||
const newQ =
|
||||
segs.shift()!.surface +
|
||||
" " +
|
||||
segs.map((s) => s.surface).join("") +
|
||||
" ";
|
||||
|
||||
setQ(newQ);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
setEntries(result);
|
||||
} else {
|
||||
setEntries([...entries, ...result]);
|
||||
|
||||
Reference in new issue
Block a user