資源簡介
本文檔主要是協(xié)同過濾算法實(shí)現(xiàn)的電影推薦系統(tǒng)源碼,對應(yīng)本人博客MapReduce基于物品的協(xié)同過濾算法實(shí)現(xiàn)電影推薦系統(tǒng)。歡迎大家關(guān)注數(shù)據(jù)科學(xué),關(guān)注我。謝謝

代碼片段和文件信息
package?com.paradeto.recommend;
import?java.io.IOException;
import?java.text.SimpleDateFormat;
import?org.apache.hadoop.conf.Configuration;
import?org.apache.hadoop.fs.FSDataInputStream;
import?org.apache.hadoop.fs.FSDataOutputStream;
import?org.apache.hadoop.fs.FileStatus;
import?org.apache.hadoop.fs.FileSystem;
import?org.apache.hadoop.fs.Path;
import?org.apache.hadoop.hdfs.DistributedFileSystem;
import?org.apache.hadoop.io.IOUtils;
/**
?*?HDFS文件操作
?*?@author?youxingzhi
?*
?*/
public?class?HDFSFile?{
Configuration?conf?=?new?Configuration();
private?FileSystem?hdfs;
/**
?*?構(gòu)造方法
?*?@param?hdfsPath
?*?@throws?IOException
?*/
public?HDFSFile(Path?hdfsPath)?throws?IOException{
hdfs?=?hdfsPath.getFileSystem(conf);
}
/**
?*?創(chuàng)建目錄
?*?@param?path
?*?@throws?IOException
?*/
public?void?mkDir(Path?path)?throws?IOException{
hdfs.mkdirs(path);
}
/**
?*?上傳文件
?*?@param?src
?*?@param?dst
?*?@throws?IOException
?*/
public?void?copyLocalToHdfs(Path?srcPath?dst)?throws?IOException{
hdfs.copyFromLocalFile(src?dst);
}
/**
?*?刪除文件
?*?@param?path
?*?@throws?IOException
?*/
@SuppressWarnings(“deprecation“)
public?void?delFile(Path?path)?throws?IOException{
hdfs.delete(path);
}
/**
?*?讀取文件內(nèi)容
?*?@param?path
?*?@throws?IOException
?*/
public?void?readFile(Path?path)?throws?IOException{
//獲取文件信息
FileStatus?filestatus?=?hdfs.getFileStatus(path);
//FS的輸入流
FSDataInputStream?in?=?hdfs.open(path);
//用Hadoop的IOUtils工具方法來讓這個(gè)文件的指定字節(jié)復(fù)制到標(biāo)準(zhǔn)輸出流上
IOUtils.copyBytes(inSystem.out(int)filestatus.getLen()false);
System.out.println();
}
/**
?*?得到文件的修改時(shí)間
?*?@param?path
?*?@throws?IOException
?*/
public?void?getModifyTime(Path?path)?throws?IOException{
FileStatus?files[]?=?hdfs.listStatus(path);
for(FileStatus?file:?files){
//time?=?file.getModificationTime().
SimpleDateFormat?sdf?=?new?SimpleDateFormat(“yyyy-MM-dd?hh:mm:ss“);
String?date?=?sdf.format(file.getModificationTime());
System.out.println(file.getPath()+“\t“+date);
}
}
/**
?*?在hdfs上創(chuàng)建文件并寫入內(nèi)容
?*?@param?path
?*?@param?content
?*?@throws?IOException
?*/
public?void?writeFile(Path?pathString?content)?throws?IOException{
FSDataOutputStream?os?=?hdfs.create(path);
//以utf-8的格式寫入文件
os.write(content.getBytes(“UTF-8“));
os.close();
}
/**
?*?列出某一路徑下所有的文件
?*?@param?path
?*?@throws?IOException
?*/
public?void?listFiles(Path?path)?throws?IOException{
hdfs?=?path.getFileSystem(conf);
FileStatus?files[]?=?hdfs.listStatus(path);
int?listlength=files.length;??
????????for?(int?i=0?;i ????????????if?(files[i].isDir()?==?false)?{??
????????????????System.out.println(“filename:“??
???????????????? +?files[i].getPath()??+?“\tsize:“??
????????????????????????+?files[i].getLen());??
????????????}?else?{??
????????????????Path?newpath?=?new?Path(files[i].getPath().toString());??
????????????????listFiles(newpath);??
????????????}??
????????}??
}
public?static?void?main?(String?arg[])?throws?Exception{
//
HDF
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2016-06-03?02:33??Recommend-master\
?????文件????????2379??2016-06-03?02:33??Recommend-master\README.md
?????目錄???????????0??2016-06-03?02:33??Recommend-master\code\
?????目錄???????????0??2016-06-03?02:33??Recommend-master\code\recommend\
?????文件????????5186??2016-06-03?02:33??Recommend-master\code\recommend\.classpath
?????文件?????????420??2016-06-03?02:33??Recommend-master\code\recommend\.project
?????目錄???????????0??2016-06-03?02:33??Recommend-master\code\recommend\bin\
?????目錄???????????0??2016-06-03?02:33??Recommend-master\code\recommend\bin\com\
?????目錄???????????0??2016-06-03?02:33??Recommend-master\code\recommend\bin\com\paradeto\
?????目錄???????????0??2016-06-03?02:33??Recommend-master\code\recommend\bin\com\paradeto\recommend\
?????文件????????4329??2016-06-03?02:33??Recommend-master\code\recommend\bin\com\paradeto\recommend\HDFSFile.class
?????文件????????3128??2016-06-03?02:33??Recommend-master\code\recommend\bin\com\paradeto\recommend\Recommend.class
?????文件????????1224??2016-06-03?02:33??Recommend-master\code\recommend\bin\com\paradeto\recommend\SortHashMap$1.class
?????文件????????2595??2016-06-03?02:33??Recommend-master\code\recommend\bin\com\paradeto\recommend\SortHashMap.class
?????文件????????2754??2016-06-03?02:33??Recommend-master\code\recommend\bin\com\paradeto\recommend\Step1$Step1_ToItemPreMapper.class
?????文件????????2801??2016-06-03?02:33??Recommend-master\code\recommend\bin\com\paradeto\recommend\Step1$Step1_ToUserVectorReducer.class
?????文件????????2567??2016-06-03?02:33??Recommend-master\code\recommend\bin\com\paradeto\recommend\Step1.class
?????文件????????2467??2016-06-03?02:33??Recommend-master\code\recommend\bin\com\paradeto\recommend\Step2$Step2_UserVectorToConoccurrenceReducer.class
?????文件????????2997??2016-06-03?02:33??Recommend-master\code\recommend\bin\com\paradeto\recommend\Step2$Step2_UserVectorToCooccurrenceMapper.class
?????文件????????2469??2016-06-03?02:33??Recommend-master\code\recommend\bin\com\paradeto\recommend\Step2.class
?????文件????????3040??2016-06-03?02:33??Recommend-master\code\recommend\bin\com\paradeto\recommend\Step3$Step31_UserVectorSplitterMapper.class
?????文件????????2595??2016-06-03?02:33??Recommend-master\code\recommend\bin\com\paradeto\recommend\Step3$Step32_CooccurrenceColumnWrapperMapper.class
?????文件????????2764??2016-06-03?02:33??Recommend-master\code\recommend\bin\com\paradeto\recommend\Step3.class
?????文件????????4087??2016-06-03?02:33??Recommend-master\code\recommend\bin\com\paradeto\recommend\Step4_Update$Step4_AggregateReducer.class
?????文件????????3703??2016-06-03?02:33??Recommend-master\code\recommend\bin\com\paradeto\recommend\Step4_Update$Step4_PartialMultiplyMapper.class
?????文件????????2701??2016-06-03?02:33??Recommend-master\code\recommend\bin\com\paradeto\recommend\Step4_Update.class
?????文件????????2503??2016-06-03?02:33??Recommend-master\code\recommend\bin\com\paradeto\recommend\Step4_Update2$Step4_RecommendMapper.class
?????文件????????3285??2016-06-03?02:33??Recommend-master\code\recommend\bin\com\paradeto\recommend\Step4_Update2$Step4_RecommendReducer.class
?????文件????????2624??2016-06-03?02:33??Recommend-master\code\recommend\bin\com\paradeto\recommend\Step4_Update2.class
?????文件????????3373??2016-06-03?02:33??Recommend-master\code\recommend\bin\com\paradeto\recommend\Step5$Step5_FilterSortMapper.class
?????文件????????4780??2016-06-03?02:33??Recommend-master\code\recommend\bin\com\paradeto\recommend\Step5$Step5_FilterSortReducer.class
............此處省略52個(gè)文件信息
- 上一篇:電子對抗課件
- 下一篇:基于STM32的模擬鼠標(biāo)移動(dòng)
評論
共有 條評論