在python中使用langdetect时出错:“文本中没有特性”

2024-09-22 22:22:35 发布

您现在位置:Python中文网/ 问答频道 /正文

嘿,我有一个多语言文本的csv。我只需要一列附加一个检测到的语言。所以我编码如下

from langdetect import detect 
import csv
with open('C:\\Users\\dell\\Downloads\\stdlang.csv') as csvinput:
with open('C:\\Users\\dell\\Downloads\\stdlang.csv') as csvoutput:
writer = csv.writer(csvoutput, lineterminator='\n')
reader = csv.reader(csvinput)

    all = []
    row = next(reader)
    row.append('Lang')
    all.append(row)

    for row in reader:
        row.append(detect(row[0]))
        all.append(row)

    writer.writerows(all)

但是我得到的错误是LangDetectException: No features in text

回溯如下

runfile('C:/Users/dell/.spyder2-py3/temp.py', wdir='C:/Users/dell/.spyder2-py3')
Traceback (most recent call last):

  File "<ipython-input-25-5f98f4f8be50>", line 1, in <module>
    runfile('C:/Users/dell/.spyder2-py3/temp.py', wdir='C:/Users/dell/.spyder2-py3')

  File "C:\Users\dell\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 714, in runfile
    execfile(filename, namespace)

  File "C:\Users\dell\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 89, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/dell/.spyder2-py3/temp.py", line 21, in <module>
    row.append(detect(row[0]))

  File "C:\Users\dell\Anaconda3\lib\site-packages\langdetect\detector_factory.py", line 130, in detect
    return detector.detect()

  File "C:\Users\dell\Anaconda3\lib\site-packages\langdetect\detector.py", line 136, in detect
    probabilities = self.get_probabilities()

  File "C:\Users\dell\Anaconda3\lib\site-packages\langdetect\detector.py", line 143, in get_probabilities
    self._detect_block()

  File "C:\Users\dell\Anaconda3\lib\site-packages\langdetect\detector.py", line 150, in _detect_block
    raise LangDetectException(ErrorCode.CantDetectError, 'No features in text.')

LangDetectException:文本中没有特征。

这就是我的csv的样子 1) 最臭鼬的烟熏最美味的紧张止痛药和情绪提振剂 2) 放松,快感,苏莱夫,嗜睡,注意力集中,住宿,拉普蒂特增强,傻笑,体格,精神支柱 3) 雷德齐耶特·安格斯特、鲁厄、格霍贝纳·斯廷穆格、泽雷布雷·恩格尔、科尔珀·塞迪隆 4) 冷静,肌肉放松,精神放松,精神分裂 5) 重いӣルーティーな幸せ非常に強な頭石のバースト

请帮帮我。


Tags: csvinpylibpackageslinesiteusers