代码优化

This commit is contained in:
tarzan
2023-02-07 15:42:01 +08:00
parent b924b78dbd
commit a686940f88
2 changed files with 4 additions and 3 deletions

View File

@@ -1,11 +1,9 @@
package com.tarzan.recommend.core;
import com.tarzan.recommend.dto.RelateDTO;
import org.assertj.core.util.Lists;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
/**
* 核心算法

View File

@@ -32,7 +32,10 @@ public class UserCF {
double maxValue=Collections.max(userDisMap.values());
Set<Integer> userIds=userDisMap.entrySet().stream().filter(e->e.getValue()==maxValue).map(Map.Entry::getKey).collect(Collectors.toSet());
//取关系最近的用户
Integer nearestUserId = userIds.stream().findAny().get();
Integer nearestUserId = userIds.stream().findAny().orElse(null);
if(nearestUserId==null){
return Collections.emptyList();
}
//最近邻用户看过电影列表
List<Integer> neighborItems = userMap.get(nearestUserId).stream().map(RelateDTO::getItemId).collect(Collectors.toList());
//指定用户看过电影列表