电影评分数据 先下个小的数据集
Small: 100,000 ratings and 3,600 tag applications applied to 9,000 movies by 600 users. Last updated 9/2018.
包含 4 个文件
- links.csv -----
movieId,imdbId,tmdbId
- movies.csv --
movieId,title,genres
- ratings.csv --
userId,movieId,rating,timestamp
- tags.csv -----
userId,movieId,tag,timestamp
到 easyrec-web
里创建一个 tenant
写代码导入
package com.ctrip.gs.cug.recommend.web;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import qunar.agile.Files;
import java.io.File;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
public class Test {
public static void main(String[] args) throws IOException {
String[] movies = Files.readLines(new File("~/Downloads/ml-latest-small/movies.csv"));
Map<String, String> movieMap = new HashMap<>(movies.length);
for (int i = 1; i < movies.length; i++) {
String[] strings = movies[i].split(",");
movieMap.put(strings[0], strings[1]);
}
OkHttpClient client = new OkHttpClient();
String[] ratings = Files.readLines(new File("~/Downloads/ml-latest-small/ratings.csv"));
for (int i = 1; i < ratings.length; i++) {
String[] rats = ratings[i].split(",");
String userId = rats[0];
String movieId = rats[1];
int rate = (int) (Double.parseDouble(rats[2]) / 0.5);
String url = "http://10.32.65.26:58888/easyrec-web/api/1.1/rate?apikey=4d87bec32ba283e1f0a87c59cc977ef7&tenantid=movie" +
"&itemid=" + movieId +
"&itemdescription=" + URLEncoder.encode(movieMap.get(movieId), "UTF-8") +
"&itemurl=/movie/" + movieId +
"&userid=" + userId +
"&ratingvalue=" + rate +
"&itemtype=MOVIES&sessionid=" + userId;
Request request = new Request.Builder().url(url).get().build();
String response = client.newCall(request).execute().body().string();
System.out.println(response);
}
}
}
网友评论