小编Sha*_*uqi的帖子

使用 python Natural Language Toolkit 阅读孟加拉语

我想在 NLTK 的 CategorizedPlainCorpusReader 中阅读孟加拉语文本。对于我在 gedit 文本编辑器中的孟加拉语文本文件的这个快照:

在此处输入图片说明

崇高文本编辑器中的文件快照:

在此处输入图片说明

从快照中可以看出问题所在。问题是 Unicode 组合问题(虚线环是一个死的赠品)。这是用于阅读文本的代码段:

>>> path = os.path.expanduser('~/nltk_data/corpora/Bangla')
>>> from nltk.corpus.reader import CategorizedPlaintextCorpusReader
>>> from nltk import RegexpTokenizer
>>> word_tokenize = RegexpTokenizer("[\w']+")
>>> reader = CategorizedPlaintextCorpusReader(path,r'.*\.txt',cat_pattern=r'(.*)_.*',word_tokenizer=word_tokenize)
>>> reader.sents(categories='pos')
Run Code Online (Sandbox Code Playgroud)

输出是:

在此处输入图片说明

输出应该是'?????' 而不是 '???' '?'。可以做什么??提前致谢。

python text-processing nlp

4
推荐指数
1
解决办法
2278
查看次数

标签 统计

nlp ×1

python ×1

text-processing ×1