-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_mapreduce.sh
executable file
·63 lines (53 loc) · 1.82 KB
/
run_mapreduce.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
if [ -z ${1+x} ]
then
file="tech/ink-helps-drive-democracy-in-asia.txt"
else
file="$1"
fi
if [ ! -f "dataset/news/$file" ]; then
echo "File dataset/news/$file does not exists!"
exit 1
fi
echo "dataset/news/$file" > file_name.txt
printf "Calculating TF-IDF for $file\n"
printf "Running TF mapreduce...\n"
printf "Removing old results...\n"
rm tf_output.txt -f
hadoop fs -rm -r /temp
printf "Putting files to HDFS...\n"
hadoop fs -mkdir /temp
hadoop fs -mkdir /temp/input
# /temp/output must not exists beforehand
hadoop fs -put dataset/news/* /temp/input
printf "Counting files...\n"
hadoop fs -ls -R /temp/input | grep -E '^-' | wc -l > files_count.txt
printf "Running TF mapreduce on Hadoop...\n"
hadoop jar \
/usr/lib/hadoop-0.20-mapreduce/contrib/streaming/hadoop-streaming-2.0.0-mr1-cdh4.1.1.jar \
-mapper "tf_mapper.py $file" \
-reducer "tf_reducer.py $file" \
-file tf_mapper.py \
-file tf_reducer.py \
-file utils.py \
-input /temp/input/* \
-output /temp/output
# printf "Getting results back...\n"
# hadoop fs -get "/temp/output/part-00000"
# mv "part-00000" tf_output.txt
# printf "Results are written to file tf_output.txt\nTF Done! Computing DF...\n"
# printf "Copying from HDFS /temp/output/part-* to /temp/dfinput...\n"
# hadoop fs -mkdir /temp/dfinput
# hadoop fs -cp /temp/output/part-* /temp/dfinput
printf "Running DF mapreduce on Hadoop...\n"
hadoop jar \
/usr/lib/hadoop-0.20-mapreduce/contrib/streaming/hadoop-streaming-2.0.0-mr1-cdh4.1.1.jar \
-mapper "df_mapper.py $file" \
-reducer "df_reducer.py $file" \
-file df_mapper.py \
-file df_reducer.py \
-file utils.py \
-input /temp/output/part-* \
-output /temp/dfoutput
printf "Getting results into tf_df_output.txt...\n"
hadoop fs -get "/temp/dfoutput/part-00000"
mv "part-00000" tf_df_output.txt