在training_set
文件夹中,文件像这样存在
mv_000000
mv_000001
mv_000002
...
索引是可以在以下位置找到的电影ID movie_title.txt
movie_title.tx
文件就像:
1,2003,Dinosaur Planet
2,2004,Isle of Man TT 2004 Review
3,1997,Character
4,1994,Paula Abdul's Get Up & Dance
5,2004,The Rise and Fall of ECW
...
第一栏是特定电影名称的索引。
我根据netplix竞赛奖金数据集练习hadoop。我假设我插入了特定的电影标题,例如“ Sick”。然后转到movie_titles.txt
文件并搜索“ sick”的电影标题ID。最后设置输入路径电影标题ID。
例如,如果我以以下方式启动hadoop程序:
hadoop jar ~ [input path] [output path] [moiveA name]
比必须设置的输入路径training_set/mv_movieAIndex
。
正如我所说的,电影ID的信息存在于上movie_title.txt
。
请给我一些提示,以解决此问题。
您的要求似乎根本不相关Hadoop
。您所需id
要做的就是对照hadoop jar
命令的第3个参数指定的movieName查找。以下代码段将完成工作:
private static Map<String, Integer> getMovieMappings(String filePath)
throws IOException {
Map<String, Integer> movieMap = new HashMap<String, Integer>();
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(filePath));
String line;
while ((line = br.readLine()) != null) {
String[] temp = line.split(",");
movieMap.put(temp[2].trim(), Integer.parseInt(temp[0].trim()));
}
} finally {
if (br != null) br.close();
}
return movieMap;
}
现在在驱动程序中,只需获取地图并相应地设置inputPath即可:
Map<String, Integer> movieMap = getMovieMappings("/pathTo/movie_title.txt");
int movieId = movieMap.get(args[2]);
System.out.println(String.format("mv_%06d", movieId));
FileInputFormat.addInputPath( job,
new Path( "training_set",
String.format("mv_%06d", movieId)));
可能会有所帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句