Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
search_tips
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rank
search_tips
Commits
2007a2e9
Commit
2007a2e9
authored
Jan 29, 2019
by
段英荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify
parent
352a4ba9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
12 deletions
+32
-12
commons.py
trans2es/commons/commons.py
+31
-12
type_info.py
trans2es/type_info.py
+1
-0
No files found.
trans2es/commons/commons.py
View file @
2007a2e9
...
@@ -21,22 +21,22 @@ def uuid4():
...
@@ -21,22 +21,22 @@ def uuid4():
def
get_tips_suggest_list
(
instance_cn_name
):
def
get_tips_suggest_list
(
instance_cn_name
):
try
:
try
:
ch_full_weight
=
6.0
*
1000
0
ch_full_weight
=
6.0
*
1000
py_full_weight
=
3.0
*
1000
0
py_full_weight
=
3.0
*
1000
py_acronym_full_weight
=
3.0
*
1000
0
py_acronym_full_weight
=
3.0
*
1000
py_acronym_prefix_weight
=
2
py_acronym_prefix_weight
=
2
ch_prefix_weight
=
1.5
ch_prefix_weight
=
1.5
py_prefix_weight
=
1.0
py_prefix_weight
=
1.0
# 命中开始部分加权
# 命中开始部分加权
begin_prefix_weight
=
1.2
*
1000
0
begin_prefix_weight
=
1.2
*
1000
ch_full_word
=
instance_cn_name
.
strip
()
ch_full_word
=
instance_cn_name
.
strip
()
py_full_word
=
''
.
join
(
lazy_pinyin
(
ch_full_word
))
py_full_word
=
''
.
join
(
lazy_pinyin
(
ch_full_word
))
py_acronym_full_word
=
''
.
join
(
lazy_pinyin
(
ch_full_word
,
style
=
pypinyin
.
FIRST_LETTER
))
py_acronym_full_word
=
''
.
join
(
lazy_pinyin
(
ch_full_word
,
style
=
pypinyin
.
FIRST_LETTER
))
suggest_
list
=
lis
t
()
suggest_
dict
=
dic
t
()
cur_index
=
0
cur_index
=
0
# 中文
# 中文
for
i
in
range
(
len
(
ch_full_word
)):
for
i
in
range
(
len
(
ch_full_word
)):
...
@@ -50,10 +50,16 @@ def get_tips_suggest_list(instance_cn_name):
...
@@ -50,10 +50,16 @@ def get_tips_suggest_list(instance_cn_name):
"input"
:
[
ch_name_term
],
"input"
:
[
ch_name_term
],
"word_weight"
:
(
1.0
*
len
(
ch_name_term
)
/
len
((
ch_full_word
)))
*
prefix_weight
,
"word_weight"
:
(
1.0
*
len
(
ch_name_term
)
/
len
((
ch_full_word
)))
*
prefix_weight
,
"suggest_type"
:
suggest_type
,
"suggest_type"
:
suggest_type
,
"cur_index"
:
cur_index
}
}
if
ch_name_term
[
0
]
not
in
suggest_dict
:
cur_index
+=
1
cur_index
+=
1
suggest_list
.
append
(
suggest_item
)
suggest_item
[
"cur_index"
]
=
cur_index
suggest_dict
[
ch_name_term
[
0
]]
=
suggest_item
else
:
suggest_dict
[
ch_name_term
[
0
]][
"input"
]
.
append
(
ch_name_term
)
if
suggest_item
[
"word_weight"
]
>
suggest_dict
[
ch_name_term
[
0
]][
"word_weight"
]:
suggest_dict
[
ch_name_term
[
0
]][
"word_weight"
]
=
suggest_item
[
"word_weight"
]
suggest_dict
[
ch_name_term
[
0
]][
"suggest_type"
]
=
suggest_item
[
"suggest_type"
]
# 拼音
# 拼音
for
i
in
range
(
len
(
py_full_word
)):
for
i
in
range
(
len
(
py_full_word
)):
...
@@ -67,11 +73,17 @@ def get_tips_suggest_list(instance_cn_name):
...
@@ -67,11 +73,17 @@ def get_tips_suggest_list(instance_cn_name):
suggest_item
=
{
suggest_item
=
{
"input"
:
[
py_name_term
],
"input"
:
[
py_name_term
],
"word_weight"
:
(
1.0
*
len
(
py_name_term
)
/
len
(
py_full_word
))
*
prefix_weight
,
"word_weight"
:
(
1.0
*
len
(
py_name_term
)
/
len
(
py_full_word
))
*
prefix_weight
,
"suggest_type"
:
suggest_type
,
"suggest_type"
:
suggest_type
"cur_index"
:
cur_index
}
}
if
py_name_term
[
0
]
not
in
suggest_dict
:
cur_index
+=
1
cur_index
+=
1
suggest_list
.
append
(
suggest_item
)
suggest_item
[
"cur_index"
]
=
cur_index
suggest_dict
[
py_name_term
[
0
]]
=
suggest_item
else
:
suggest_dict
[
py_name_term
[
0
]][
"input"
]
.
append
(
py_name_term
)
if
suggest_item
[
"word_weight"
]
>
suggest_dict
[
py_name_term
[
0
]][
"word_weight"
]:
suggest_dict
[
py_name_term
[
0
]][
"word_weight"
]
=
suggest_item
[
"word_weight"
]
suggest_dict
[
py_name_term
[
0
]][
"suggest_type"
]
=
suggest_item
[
"suggest_type"
]
# 简写
# 简写
for
i
in
range
(
len
(
py_acronym_full_word
)):
for
i
in
range
(
len
(
py_acronym_full_word
)):
...
@@ -89,10 +101,17 @@ def get_tips_suggest_list(instance_cn_name):
...
@@ -89,10 +101,17 @@ def get_tips_suggest_list(instance_cn_name):
"suggest_type"
:
suggest_type
,
"suggest_type"
:
suggest_type
,
"cur_index"
:
cur_index
"cur_index"
:
cur_index
}
}
if
py_acronym_term
[
0
]
not
in
suggest_dict
:
cur_index
+=
1
cur_index
+=
1
suggest_list
.
append
(
suggest_item
)
suggest_item
[
"cur_index"
]
=
cur_index
suggest_dict
[
py_acronym_term
[
0
]]
=
suggest_item
else
:
suggest_dict
[
py_acronym_term
[
0
]][
"input"
]
.
append
(
py_acronym_term
)
if
suggest_item
[
"word_weight"
]
>
suggest_dict
[
py_acronym_term
[
0
]][
"word_weight"
]:
suggest_dict
[
py_acronym_term
[
0
]][
"word_weight"
]
=
suggest_item
[
"word_weight"
]
suggest_dict
[
py_acronym_term
[
0
]][
"suggest_type"
]
=
suggest_item
[
"suggest_type"
]
return
suggest_
list
return
suggest_
dict
.
values
()
except
:
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
list
()
return
list
()
...
...
trans2es/type_info.py
View file @
2007a2e9
...
@@ -133,6 +133,7 @@ class TypeInfo(object):
...
@@ -133,6 +133,7 @@ class TypeInfo(object):
continue
continue
data
=
self
.
get_data_func
(
instance
)
data
=
self
.
get_data_func
(
instance
)
(
item_dict
,
suggest_list
)
=
data
(
item_dict
,
suggest_list
)
=
data
for
suggest_item
in
suggest_list
:
for
suggest_item
in
suggest_list
:
suggest_dict
=
copy
.
deepcopy
(
item_dict
)
suggest_dict
=
copy
.
deepcopy
(
item_dict
)
suggest_dict
[
"suggest_type"
]
=
suggest_item
[
"suggest_type"
]
suggest_dict
[
"suggest_type"
]
=
suggest_item
[
"suggest_type"
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment