THULAC-Python icon indicating copy to clipboard operation
THULAC-Python copied to clipboard

fast_cut在python3中出现decode error

Open elara7 opened this issue 7 years ago • 3 comments

在python3中使用fast_cut出现decode error错误,问题定位在 manage/SoExtention.py 的 line29 :return s.value.decode('utf-8')。排查原因发现是line 26:self._lib.freeResult();执行后,s.value乱码,不再是utf8。提前保存s.value.decode('utf-8'),再执行self._lib.freeResult();,然后返回提前保存的值,可解决。 2. init.py中,line 100:array += (reduce(lambda x, y: x + [[y[0], y[2]]], cut_method(line), [])) 当cut_method为__fast_cutline的时候,[y[0], y[2]]捕获的是第一个和第三个字,而非期望的下划线两边的词。

elara7 avatar Dec 12 '17 13:12 elara7

+1, 同样发现这个问题,python 2里面执行的结果 image 只有用fast_cut做包含词性的分词的时候有这个错误,定位是__fast_cutline在词性条件下返回和__cutline的返回不一致,返回的是字符串,而不是三元素的tuple

linhx13 avatar Dec 16 '17 10:12 linhx13

感谢对THULAC的支持,这个是我们之前有所忽略,同时非常感谢修改意见~

gzp9595 avatar Dec 16 '17 16:12 gzp9595

还是有错误,cut_method(line)返回的数据结果中可能是单个元素,没有tag结果。 我简单地对__init__.py:100行做了修改

ret = [x for x in cut_method(line)]
tmp = list()
for x in ret:
    if len(x) != 3:
        tmp += [[x[0], '']]
    else:
        tmp += [[x[0], x[2]]]
array += (tmp)
# array += (reduce(lambda x, y: x + [[y[0], y[2]]], cut_method(line), []))

这是出错的文本 error.txt(url)

xiejianhe avatar Dec 14 '18 08:12 xiejianhe