Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Nltk 如何使用PlaintextCorpusReader模块加载一个文本文件语料库_Nltk - Fatal编程技术网

Nltk 如何使用PlaintextCorpusReader模块加载一个文本文件语料库

Nltk 如何使用PlaintextCorpusReader模块加载一个文本文件语料库,nltk,Nltk,我只能这样做: `从nltk.corpus导入PlaintextCorpusReader 语料库_root='/usr/share/dict' WordList=PlaintextCorpusReader(语料库_根'.*') wordlists.fileids()` 如果我的语料库只有一个文件,那么有没有一个有效的代码可以直接选择该文件而不是这种方法,即对于一个语料库,许多文本文件创建一个目录,只在其中放置一个文件?是的,我就是这么做的!为什么需要明文微粒读取器?如果您只需要标记文本,那么您可

我只能这样做:

`从nltk.corpus导入PlaintextCorpusReader

语料库_root='/usr/share/dict' WordList=PlaintextCorpusReader(语料库_根'.*') wordlists.fileids()`


如果我的语料库只有一个文件,那么有没有一个有效的代码可以直接选择该文件而不是这种方法,即对于一个语料库,许多文本文件

创建一个目录,只在其中放置一个文件?是的,我就是这么做的!为什么需要
明文微粒读取器
?如果您只需要标记文本,那么您可以轻松地执行
[word\u-tokenize(sent)for-sent\u-tokenize(open(filename,'r').read())]
,这将为您提供一个句子列表,每个句子都是一个单词列表。