|
@@ -1,6 +1,11 @@
|
|
|
package com.tzld.longarticle.recommend.server.service.rank;
|
|
|
|
|
|
|
|
|
+<<<<<<< HEAD
|
|
|
+=======
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.tzld.longarticle.recommend.server.model.Content;
|
|
|
+>>>>>>> e5f14a8 (init)
|
|
|
import com.tzld.longarticle.recommend.server.service.score.ScoreParam;
|
|
|
import com.tzld.longarticle.recommend.server.service.score.ScoreResult;
|
|
|
import com.tzld.longarticle.recommend.server.service.score.ScoreService;
|
|
@@ -11,8 +16,12 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+<<<<<<< HEAD
|
|
|
import java.util.Collections;
|
|
|
import java.util.Map;
|
|
|
+=======
|
|
|
+import java.util.*;
|
|
|
+>>>>>>> e5f14a8 (init)
|
|
|
|
|
|
/**
|
|
|
* @author dyp
|
|
@@ -29,7 +38,9 @@ public class RankService {
|
|
|
ScoreResult result = scoreService.score(convertToScoreParam(param));
|
|
|
Map<String, Map<Class<? extends ScoreStrategy>, Double>> scoreMap = result.getScoreMap();
|
|
|
|
|
|
- Collections.sort(param.getContents(), (o1, o2) -> {
|
|
|
+ List<Content> contents = Lists.newArrayList(param.getContents());
|
|
|
+
|
|
|
+ Collections.sort(contents, (o1, o2) -> {
|
|
|
String o1Id = o1.getId();
|
|
|
String o2Id = o2.getId();
|
|
|
|
|
@@ -61,16 +72,62 @@ public class RankService {
|
|
|
return 0;
|
|
|
});
|
|
|
|
|
|
-
|
|
|
- // 标题相似过滤
|
|
|
- param.getContents();
|
|
|
-
|
|
|
return new RankResult(contents);
|
|
|
}
|
|
|
|
|
|
private ScoreParam convertToScoreParam(RankParam param) {
|
|
|
- return null;
|
|
|
+ ScoreParam scoreParam = new ScoreParam();
|
|
|
+ scoreParam.setAccountName(param.getAccountName());
|
|
|
+ scoreParam.setContents(param.getContents());
|
|
|
+ return scoreParam;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+<<<<<<< HEAD
|
|
|
+=======
|
|
|
+ private List<Content> removeDuplicateContent(List<Content> contentList, Set<String> existsContentTitle) {
|
|
|
+ List<Content> result = new ArrayList<>();
|
|
|
+ for (Content content : contentList) {
|
|
|
+ if (existsContentTitle.contains(content.getTitle())
|
|
|
+ || isDuplicateContent(content.getTitle(), existsContentTitle)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ result.add(content);
|
|
|
+ existsContentTitle.add(content.getTitle());
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static final double SIMILARITY_THRESHOLD = 0.8; // 相似度阈值
|
|
|
+
|
|
|
+ private boolean isDuplicateContent(String title, Set<String> existsContentTitle) {
|
|
|
+ boolean result = false;
|
|
|
+ for (String existsTitle : existsContentTitle) {
|
|
|
+ if (isSimilar(title, existsTitle, SIMILARITY_THRESHOLD)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
+ private boolean isSimilar(String titleA, String titleB, double threshold) {
|
|
|
+ if (titleA.isEmpty() || titleB.isEmpty()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Set<Character> setA = new HashSet<>();
|
|
|
+ for (char c : titleA.toCharArray()) {
|
|
|
+ setA.add(c);
|
|
|
+ }
|
|
|
+ Set<Character> setB = new HashSet<>();
|
|
|
+ for (char c : titleB.toCharArray()) {
|
|
|
+ setB.add(c);
|
|
|
+ }
|
|
|
+ Set<Character> setCross = new HashSet<>(setA);
|
|
|
+ setCross.retainAll(setB);
|
|
|
+ int minLen = Math.max(Math.min(setA.size(), setB.size()), 1);
|
|
|
+ double rate = (double) setCross.size() / minLen;
|
|
|
+ return rate >= threshold;
|
|
|
+ }
|
|
|
|
|
|
+>>>>>>> e5f14a8 (init)
|
|
|
}
|