FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
librime-lua-script/lua/conjunctive/filter.lua at main · shewer/librime-lua-script · GitHub
shewer
librime-lua-script
Repository navigation
Code
Issues
4
(4)
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
librime-lua-script
/
lua
/
conjunctive
/
filter.lua
Copy path
More file actions
More file actions
Latest commit
History
History
History
78 lines (75 loc) · 2 KB
Breadcrumbs
librime-lua-script
/
lua
/
conjunctive
/
filter.lua
Copy path
File metadata and controls
78 lines (75 loc) · 2 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!
/usr/bin/env lua
--
--
filter.lua
--
Copyright (C) 2022 Shewer Lu <shewer@gmail.com>
--
--
Distributed under terms of the MIT license.
--
local
Env
=
require
'
tools/env_api
'
local
List
=
require
'
tools/list
'
local
Dict
=
require
'
tools/dict
'
local
function
load_dict
(
filename
)
local
fpath
,
path
,
filename
=
get_full_path
(
filename
)
if
not
fpath
then
Log
(
ERROR
,
'
not found file from user_data or sharded_data
'
,
filename
)
return
end
Log
(
INFO
,
"
load dict .........
"
,
filename
)
local
t1
=
os.clock
()
local
dict
=
Dict
(
filename
,
path
)
Log
(
INFO
,
"
loaded dict .........
"
,
os.clock
()
-
t1
)
if
not
dict
then
Log
(
WARNING
,
__FILE__
(),
__LINE__
(),
"
open dict faild
"
,
filename
)
return
end
return
dict
end
local
F
=
{}
function
F
.
init
(
env
)
Env
(
env
)
local
files
=
env
:
Config_get
(
env
.
name_space
..
"
/files
"
)
local
files
=
type
(
files
)
==
"
table
"
and
files
or
{
"
essay.txt
"
,
"
essay_cn.txt
"
}
env
.
dict
=
load_dict
(
files
[
1
] )
env
.
preedit
=
"
[聯]
"
env
.
max
=
8
env
.
weight
=
100
end
function
F
.
fini
(
env
)
end
function
F
.
tags_match
(
seg
,
env
)
return
env
.
engine
.
context
:
get_option
(
env
.
name_space
)
end
function
F
.
func
(
input
,
env
)
local
context
=
env
.
engine
.
context
local
history
=
context
:
get_property
(
env
.
name_space
)
local
list
=
List
()
local
comp_cand
for
cand
in
input
:
iter
()
do
if
cand
.
type
==
"
completion
"
then
comp_cand
=
cand
break
end
if
cand
.
type
~=
"
history
"
and
#
cand
.
text
>
0
then
list
:
push
(
cand
)
end
yield
(
cand
)
end
--
conjunctive filter
list
:
each
(
function
(
elm
)
local
count
=
0
for
w
,
wt
in
env
.
dict
:
reduce_iter
(
history
..
elm
.
text
)
do
count
=
count
+
1
if
wt
>=
env
.
weight
and
count
<
env
.
max
then
--
weight
local
cand
=
Candidate
(
"
history
"
,
elm
.
start
,
elm
.
_end
,
elm
.
text
..
w
,
env
.
preedit
)
if
cand
then
cand
.
preedit
=
elm
.
text
..
w
..
env
.
preedit
yield
(
cand
)
end
end
end
end
)
--
campletion cand
if
comp_cand
then
yield
(
comp_cand
)
end
for
ccand
in
input
:
iter
()
do
yield
(
ccand
)
end
end
return
F
Back
|
FazBrowse Home
|
New Git URL