Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sfewfsaf
Synonyms
提交
73ccfdb1
S
Synonyms
项目概览
sfewfsaf
/
Synonyms
与 Fork 源项目一致
从无法访问的项目Fork
通知
6
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Synonyms
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
73ccfdb1
编写于
8月 31, 2020
作者:
H
Hai Liang Wang
提交者:
GitHub
8月 31, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #88 from cycorey/cycorey-patch-nearby-display-add-default-param-size-10
nearby, display add default param: size(=10)
上级
fe7450d5
6f6abdc8
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
7 addition
and
6 deletion
+7
-6
synonyms/synonyms.py
synonyms/synonyms.py
+7
-6
未找到文件。
synonyms/synonyms.py
浏览文件 @
73ccfdb1
...
...
@@ -287,22 +287,23 @@ Public Methods
'''
seg
=
_segment_words
# word segmenter
def
nearby
(
word
):
def
nearby
(
word
,
size
=
10
):
'''
Nearby word
'''
w
=
any2unicode
(
word
)
wk
=
w
+
'-'
+
str
(
size
)
# read from cache
if
w
in
_cache_nearby
:
return
_cache_nearby
[
w
]
if
w
k
in
_cache_nearby
:
return
_cache_nearby
[
wk
]
words
,
scores
=
[],
[]
try
:
for
x
in
_vectors
.
neighbours
(
w
):
for
x
in
_vectors
.
neighbours
(
w
,
size
):
words
.
append
(
x
[
0
])
scores
.
append
(
x
[
1
])
except
:
pass
# ignore key error, OOV
# put into cache
_cache_nearby
[
w
]
=
(
words
,
scores
)
_cache_nearby
[
w
k
]
=
(
words
,
scores
)
return
words
,
scores
def
compare
(
s1
,
s2
,
seg
=
True
,
ignore
=
False
,
stopwords
=
False
):
...
...
@@ -343,9 +344,9 @@ def compare(s1, s2, seg=True, ignore=False, stopwords=False):
assert
len
(
s1
)
>
0
and
len
(
s2
)
>
0
,
"The length of s1 and s2 should > 0."
return
_similarity_distance
(
s1_words
,
s2_words
,
ignore
)
def
display
(
word
):
def
display
(
word
,
size
=
10
):
print
(
"'%s'近义词:"
%
word
)
o
=
nearby
(
word
)
o
=
nearby
(
word
,
size
)
assert
len
(
o
)
==
2
,
"should contain 2 list"
if
len
(
o
[
0
])
==
0
:
print
(
" out of vocabulary"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录