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

TypeError: reduce() of empty sequence with no initial value

Open hustlrr opened this issue 8 years ago • 1 comments

import thulac
thu = thulac.thulac(seg_only=True)
def thu_segment(sent):
    '''
    :type sent: str
    :return:
    '''
    text = thu.cut(sent, text=True)
    return text  # 返回的编码是UTF-8
if __name__ == '__main__':
    sent = thu_segment(" ")  # 中文空格
    print(sent)

I run the above code, then I got following errors: Traceback (most recent call last): File "E:/python/text_classification/preprocess/segment.py", line 35, in sent = thu_segment(" ") File "E:/python/text_classification/preprocess/segment.py", line 20, in thu_segment text = thu.cut(sent, text=True) File "D:\Python27\lib\site-packages\thulac_init_.py", line 97, in cut return self.__cutWithOutMethod(oiraw, self._cutline, text = text) File "D:\Python27\lib\site-packages\thulac_init.py", line 80, in __cutWithOutMethod txt += reduce(lambda x, y: x + ' ' + y, cut_method(line)) + '\n' I think that you should add an initial value in the reduce function to solve the problem. THX~

hustlrr avatar Mar 15 '17 08:03 hustlrr

Thanks for your issue! We have fixed this bug.

MaJunhua avatar Mar 15 '17 13:03 MaJunhua