资源简介
常用推荐算法java实现~涉及多种相似度计算,比如cosine相似度,欧氏距离等~
(recommand algirithm )
代码片段和文件信息
package iweb2.ch3.collaborative.cache;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.objectInputStream;
import java.io.objectOutputStream;
/**
* Implementation of Store
interface. Uses files to store objects
* using java serialization. Each object instance is stored in a separate file.
*/
public class FileStore implements Store {
private File dataDir;
/**
* Creates a new instance that will use specified directory to store objects.
*
* @param dir directory that should be used to store/retrieve objects.
*/
public FileStore(String dir) {
this(new File(dir));
}
public FileStore(File dir) {
if( !dir.exists() ) {
dir.mkdirs();
}
this.dataDir = dir;
}
public boolean exists(String key) {
File f = getFile(key);
return f.exists();
}
public object get(String key) {
object o = null;
try {
File f = getFile(key);
if( f.exists() ) {
FileInputStream fInStream = new FileInputStream(f);
BufferedInputStream bufInStream = new BufferedInputStream(fInStream);
objectInputStream objInStream = new objectInputStream(bufInStream);
o = objInStream.readobject();
objInStream.close();
}
}
catch(Exception e) {
throw new RuntimeException(“Error while loading data from file (dir: ‘“ + dataDir + “‘ filename: ‘“ + key +“‘).“ e);
}
return o;
}
public void put(String key object o) {
try {
File f = getFile(key);
FileOutputStream foutStream = new FileOutputStream(f);
BufferedOutputStream boutStream = new BufferedOutputStream(foutStream);
objectOutputStream objOutputStream = new objectOutputStream(boutStream);
objOutputStream.writeobject(o);
objOutputStream.flush();
boutStream.close();
}
catch(IOException e) {
throw new RuntimeException(“Error while saving data into file (dir: ‘“ + dataDir + “‘ filename: ‘“ + key +“‘).“ e);
}
}
public void remove(String key) {
File f = getFile(key);
if( f.exists() ) {
f.delete();
}
}
/*
* Derives filename from the key and returns instance of File
*/
private File getFile(String key) {
// key is used as a filename
return new File(dataDir key + “.tmp“);
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-03-23 21:12 Recommend\
目录 0 2014-03-23 21:12 Recommend\src\
目录 0 2014-03-23 21:11 Recommend\src\collaborative\
目录 0 2014-03-23 21:11 Recommend\src\collaborative\cache\
文件 2770 2010-04-30 10:42 Recommend\src\collaborative\cache\FileStore.java
文件 898 2010-04-30 10:42 Recommend\src\collaborative\cache\Store.java
目录 0 2014-03-23 21:11 Recommend\src\collaborative\data\
文件 11755 2010-04-30 10:42 Recommend\src\collaborative\data\ba
文件 702 2010-04-30 10:42 Recommend\src\collaborative\data\ContentItem.java
文件 12550 2010-04-30 10:42 Recommend\src\collaborative\data\DiggData.java
文件 2174 2010-04-30 10:42 Recommend\src\collaborative\data\HTMLContent.java
文件 1745 2011-01-19 14:34 Recommend\src\collaborative\data\MovieLensData.java
文件 11574 2010-04-30 10:42 Recommend\src\collaborative\data\MovieLensDataset.java
文件 9630 2010-04-30 10:42 Recommend\src\collaborative\data\MusicData.java
文件 707 2010-04-30 10:42 Recommend\src\collaborative\data\MusicItem.java
文件 393 2010-04-30 10:42 Recommend\src\collaborative\data\MusicRating.java
文件 7160 2010-10-07 16:06 Recommend\src\collaborative\data\MusicUser.java
文件 6370 2010-04-30 10:42 Recommend\src\collaborative\data\NewsData.java
文件 549 2010-04-30 10:42 Recommend\src\collaborative\data\NewsItem.java
文件 875 2010-04-30 10:42 Recommend\src\collaborative\data\NewsUser.java
文件 1718 2010-04-30 10:42 Recommend\src\collaborative\data\RatingBuilder.java
目录 0 2014-03-23 21:11 Recommend\src\collaborative\evaluation\
文件 379 2010-04-30 10:42 Recommend\src\collaborative\evaluation\EvaluationDataProvider.java
文件 8477 2010-04-30 10:42 Recommend\src\collaborative\evaluation\MovieLensEvaluationDataProvider.java
文件 2202 2011-01-19 18:17 Recommend\src\collaborative\evaluation\MovieLensRMSE.java
文件 5521 2011-01-19 11:04 Recommend\src\collaborative\evaluation\RMSEEstimator.java
文件 1353 2010-04-30 10:42 Recommend\src\collaborative\evaluation\RMSEResult.java
目录 0 2014-03-23 21:11 Recommend\src\collaborative\model\
文件 4787 2010-04-30 10:42 Recommend\src\collaborative\model\Content.java
文件 2517 2010-04-30 10:42 Recommend\src\collaborative\model\Dataset.java
文件 3888 2010-04-30 10:42 Recommend\src\collaborative\model\Item.java
............此处省略41个文件信息
评论
共有 条评论