Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a9e86a4

Browse files
committed
Fixed chatopera#51 return editor distance with empty vectors
1 parent 81c5800 commit a9e86a4

5 files changed

Lines changed: 30 additions & 17 deletions

File tree

VALUATION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# synonyms 分数评测 [(v3.3.7)](https://pypi.python.org/pypi/synonyms/3.3.7)
1+
# synonyms 分数评测 [(v3.3.9)](https://pypi.python.org/pypi/synonyms/3.3.9)
22
| 词1 | 词2 | synonyms | 人工评定 |
33
| --- | --- | --- | --- |
44
| 轿车 | 汽车 | 1.0 | 0.98 |

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
setup(
1515
name='synonyms',
16-
version='3.3.8',
16+
version='3.3.9',
1717
description='Chinese Synonyms for Natural Language Processing and Understanding',
1818
long_description=LONGDOC,
1919
author='Hai Liang Wang, Hu Ying Xi',

synonyms/__init__.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
__all__ = ["seg", "nearby", "compare", "display", "KeyedVectors", "__version__"]
1+
__all__ = ["seg",
2+
"nearby",
3+
"compare",
4+
"display",
5+
"KeyedVectors",
6+
"any2utf8",
7+
"sigmoid",
8+
"cosine",
9+
"any2unicode",
10+
"__version__"]
211

3-
from synonyms.word2vec import *
4-
from synonyms.synonyms import *
5-
from synonyms.synonyms import __version__
12+
from .word2vec import *
13+
from .synonyms import *
14+
import jieba
15+
from .synonyms import __version__

synonyms/synonyms.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
__copyright__ = "Copyright (c) 2017 . All Rights Reserved"
2121
__author__ = "Hu Ying Xi<>, Hai Liang Wang<[email protected]>"
2222
__date__ = "2017-09-27"
23-
__version__ = "3.3.8"
23+
__version__ = "3.3.9"
2424

2525
import os
2626
import sys
@@ -48,13 +48,13 @@
4848
import gzip
4949
import shutil
5050
from absl import logging
51-
from synonyms.word2vec import KeyedVectors
52-
from synonyms.utils import any2utf8
53-
from synonyms.utils import any2unicode
54-
from synonyms.utils import sigmoid
55-
from synonyms.utils import cosine
56-
from synonyms import jieba
57-
from synonyms.jieba import posseg as _tokenizer
51+
from .word2vec import KeyedVectors
52+
from .utils import any2utf8
53+
from .utils import any2unicode
54+
from .utils import sigmoid
55+
from .utils import cosine
56+
import jieba
57+
from .jieba import posseg as _tokenizer
5858

5959
'''
6060
globals
@@ -226,7 +226,10 @@ def _similarity_distance(s1, s2):
226226
'''
227227
compute similarity with distance measurement
228228
'''
229-
g = cosine(_flat_sum_array(_get_wv(s1)), _flat_sum_array(_get_wv(s2)))
229+
g = 0.0
230+
try:
231+
g = cosine(_flat_sum_array(_get_wv(s1)), _flat_sum_array(_get_wv(s2)))
232+
except: pass
230233
u = _nearby_levenshtein_distance(s1, s2)
231234
# print("g: %s, u: %s" % (g, u))
232235
if u >= 0.99:
@@ -240,7 +243,7 @@ def _similarity_distance(s1, s2):
240243
elif u > 0.2:
241244
r = _similarity_smooth(g, 0.5, u, 0.1)
242245
else:
243-
r = g
246+
r = _similarity_smooth(g, 1, u, 0)
244247

245248
if r < 0: r = abs(r)
246249
r = min(r, 1.0)

synonyms/word2vec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
from absl import logging
3232

33-
import synonyms.utils as utils
33+
import utils
3434
from numpy import dot, zeros, dtype, float32 as REAL,\
3535
double, array, vstack, fromstring, sqrt, newaxis,\
3636
ndarray, sum as np_sum, prod, ascontiguousarray,\

0 commit comments

Comments
 (0)