首页 文章

当我使用hadoop流时,如何在HDFS中导入nltk语料库

提问于
浏览
0
I got a little problem I want to use nltk corpus in hdfs,But failed.For example I want to load nltk.stopwords in my python code.
 I use this http://eigenjoy.com/2009/11/18/how-to-use-cascading-with-hadoop-streaming/

我尽力说,但我不知道如何在我的工作中改变它 . 我的nltk文件名是nltk-2.0.1.rc1我的pyam文件名是PyYAML.3.0.1所以我的commad是:

zip -r nltkandyaml.zip nltk-2.0.1.rc1 PyYAML.3.0.1

然后它说“mv ntlkandyaml.zip /path/to/where/your/mapper/will/be/nltkandyaml.mod”

我的mapper.py保存在/home/mapreduce/mapper.py中,所以我的命令是:

mv ntlkandyaml.zip /home/mapreduce/nltkandyaml.mod

是对的吗?

然后我压缩我的语料库停用词:

zip -r /nltk_data/corpora/stopwords-flat.zip *

在我的代码中我使用:

importer = zipimport.zipimporter('nltkandyaml.mod')
yaml = importer.load_module('PyYAML-3.09')
nltk = importer.load_module('nltk-2.1.0.1rc1')
from nltk.corpus.reader import stopwords
from nltk.corpus.reader import StopWordsCorpusReader
nltk.data.path+=["."]
stopwords = StopWordsCorpusReader(nltk.data.find('lib/stopwords-flat.zip'))

最后我使用命令:

bin/hadoop jar /home/../streaming/hadoop-0.21.0-streaming.jar -input  
/user/root/input/voa.txt -output /user/root/output -mapper /home/../mapper.py -reducer  
/home/../reducer.py -file /home/../nltkandyaml.mod -file /home/../stopwords-flat.zip

请告诉我我哪里错了

谢谢你们

2 回答

  • 0
    zip -r [your-nltk-package-name/nltk] nltk.zip
    
        zip -r [your-yaml-package-name/lib/yaml] yaml.zip
    

    然后在你的脚本中添加:

    importer = zipimport.zipimporter('nltk.zip')
        importer2=zipimport.zipimporter('yaml.zip')
        yaml = importer2.load_module('yaml')
        nltk = importer.load_module('nltk')
    

    在您的命令中,添加:

    -file [path-to-your-zip-file]
    
  • 0

    我不完全清楚你的问题/错误是什么,但如果你想在运行时在当前工作目录中使用stopwords-flat.zip的内容,请使用 -archives 标志而不是 -files (这可能是你的问题,因为你'正在使用 -file ) .

    Hadoop将解压缩命名的归档文件(zip),并且内容将像在运行的映射器的本地目录中一样可用:

    bin/hadoop jar /home/../streaming/hadoop-0.21.0-streaming.jar \
      -input  /user/root/input/voa.txt 
      -output /user/root/output \
      -mapper /home/../mapper.py \
      -reducer /home/../reducer.py \
      -files /home/../nltkandyaml.mod \
      -archives /home/../stopwords-flat.zip
    

相关问题