1
 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 所以我的命令是:

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

请告诉我哪里错了

谢谢你们

4

2 回答 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]
于 2013-07-15T18:27:18.230 回答
0

I'm not entirely clear what your problem / error is, but if you want the contents of stopwords-flat.zip to be available in the current working directory at runtime use the -archives flag rather than -files (which could be your problem as you're using -file).

Hadoop will unpack the named archive file (zip), and the contents will be available as if they were in the local directory of your running mapper:

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
于 2012-05-23T10:45:02.923 回答