[英]How do I read CFG from a file encoded in UTF-8 using nltk.data.load() ? ASCII files works fine but UTF-8 encoded file gives an error
我正在嘗試通過使用nltk.data.load()加載上下文無關的語法。 語法由英語以外的其他文字組成,必須以UTF-8格式編碼。 nltk.data.load()適用於ASCII格式的文件,但不適用於UTF-8格式的文件。
您檢查了幫助嗎?
>>> help(nltk.data.load)
會向您顯示以下內容:
加載(resource_url,format ='auto',cache = True,verbose = False,logic_parser = None,fstruct_reader = None, encoding = None )
從NLTK數據包中加載給定資源。 當前支持以下資源格式:
...
因此,在您對nltk.data.load()
調用中添加encoding="utf-8"
。 (我什至在檢查幫助之前都會嘗試過,因為您還要如何指定編碼?)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.