|
@@ -1,25 +1,18 @@
|
|
|
package com.tzld.longarticle.recommend.server.service.rank;
|
|
|
|
|
|
|
|
|
-import com.tzld.longarticle.recommend.server.model.Content;
|
|
|
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;
|
|
|
import com.tzld.longarticle.recommend.server.service.score.ScoreStrategy;
|
|
|
import com.tzld.longarticle.recommend.server.service.score.strategy.ContentPoolStrategy;
|
|
|
import com.tzld.longarticle.recommend.server.service.score.strategy.SimilarityStrategy;
|
|
|
-import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-<<<<<<< HEAD
|
|
|
-import java.util.*;
|
|
|
-=======
|
|
|
import java.util.Collections;
|
|
|
-import java.util.List;
|
|
|
import java.util.Map;
|
|
|
->>>>>>> 432e804 (init)
|
|
|
|
|
|
/**
|
|
|
* @author dyp
|
|
@@ -80,48 +73,4 @@ public class RankService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- 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;
|
|
|
- }
|
|
|
-
|
|
|
}
|