-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
202 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,7 @@ out | |
*.log | ||
target/ | ||
|
||
lib | ||
|
||
# 配置文件 | ||
src/main/resources/properties/jdbc-dev.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 6 additions & 4 deletions
10
src/main/java/com/kevin/mirs/dao/UserRecommendedFriendsDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
package com.kevin.mirs.dao; | ||
|
||
import com.google.common.collect.HashMultimap; | ||
import com.kevin.mirs.entity.UserRecommendedFriends; | ||
import org.apache.ibatis.annotations.Param; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.HashMap; | ||
|
||
|
||
@Repository | ||
public interface UserRecommendedFriendsDao { | ||
|
||
int addUserRecommendedFriends(@Param("uid") int uid, | ||
@Param("rfid") int rfid); | ||
@Param("rfids") long[] rfids); | ||
|
||
boolean clearUserRecommendedFriends(); | ||
Integer[] getUserRecommendedFriends(@Param("uid") int uid); | ||
|
||
int addFriends(@Param("u") int u, | ||
@Param("f") int f); | ||
boolean clearUserRecommendedFriends(@Param("uid") int uid); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/main/java/com/kevin/mirs/service/RecommendService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.kevin.mirs.service; | ||
|
||
import com.kevin.mirs.dao.UserRecommendedFriendsDao; | ||
import com.kevin.mirs.dao.UserRecommendedMoviesDao; | ||
import com.kevin.mirs.entity.UserRecommendedMovies; | ||
import com.kevin.mirs.recommendation.RecommendFriends; | ||
import com.kevin.mirs.recommendation.RecommendFriendsBySimilarity; | ||
import com.kevin.mirs.recommendation.RecommendMovies; | ||
import com.kevin.mirs.recommendation.RecommendMoviesByPerson; | ||
import java.util.List; | ||
import org.apache.mahout.cf.taste.impl.model.file.FileDataModel; | ||
import org.apache.mahout.cf.taste.model.DataModel; | ||
import org.apache.mahout.cf.taste.recommender.RecommendedItem; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.annotation.Resource; | ||
import java.io.*; | ||
|
||
@Service | ||
public class RecommendService{ | ||
DataModel data; | ||
@Resource | ||
UserRecommendedMoviesDao rm; | ||
|
||
@Resource | ||
UserRecommendedFriendsDao rf; | ||
|
||
RecommendService(){ | ||
try{ | ||
String data = "src/main/resources/recommendation/test.csv"; | ||
this.data = new FileDataModel(new File(data)); | ||
} catch(Exception e){ | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public List<RecommendedItem> getRealTimeRecommendedMovies(int uid){ | ||
RecommendMovies recommendMovies = new RecommendMoviesByPerson(data, 20); | ||
rm.clearUserRecommendedMovies(uid); | ||
rm.addUserRecommendedMovies(uid, recommendMovies.recommendMovies(uid,2)); | ||
return recommendMovies.recommendMovies(uid,2); | ||
} | ||
|
||
public int addRecommendedMovies(int uid){ | ||
List<RecommendedItem> recommendedMovies = getRealTimeRecommendedMovies(uid); | ||
rm.clearUserRecommendedMovies(uid); | ||
return rm.addUserRecommendedMovies(uid, recommendedMovies); | ||
} | ||
|
||
public List<UserRecommendedMovies> getRecommendedMoviesFromDB(int uid){ | ||
return rm.getUserRecommendedMovies(uid); | ||
} | ||
|
||
public long[] getRealTimeRecommendedFriends(int uid){ | ||
RecommendFriends recommendFriends = new RecommendFriendsBySimilarity(data); | ||
rf.clearUserRecommendedFriends(uid); | ||
rf.addUserRecommendedFriends(uid, recommendFriends.recommendFriends(uid, 10)); | ||
return recommendFriends.recommendFriends(uid, 10); | ||
} | ||
|
||
public int addRecommendedFriends(int uid){ | ||
long[] recommendedFriends = getRealTimeRecommendedFriends(uid); | ||
rf.clearUserRecommendedFriends(uid); | ||
return rf.addUserRecommendedFriends(uid, recommendedFriends); | ||
} | ||
|
||
public Integer[] getRecommendedFriendsFromDB(int uid){ | ||
return rf.getUserRecommendedFriends(uid); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.