|
@@ -0,0 +1,52 @@
|
|
|
+package com.tzld.longarticle.recommend.server.service.score.strategy;
|
|
|
+
|
|
|
+import com.tzld.longarticle.recommend.server.remote.NLPRemoteService;
|
|
|
+import com.tzld.longarticle.recommend.server.service.score.Score;
|
|
|
+import com.tzld.longarticle.recommend.server.service.score.ScoreParam;
|
|
|
+import com.tzld.longarticle.recommend.server.service.score.ScoreStrategy;
|
|
|
+import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
|
|
|
+import com.tzld.longarticle.recommend.server.util.NormalizationUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author dyp
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class ViewMultiplierStrategy implements ScoreStrategy {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private NLPRemoteService nlpRemoteService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Score> score(ScoreParam param) {
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(param.getContents())) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ Map<String, Double> scoreMap = nlpRemoteService.score(param.getAccountName(), param.getContents());
|
|
|
+
|
|
|
+ double min = scoreMap.values().stream()
|
|
|
+ .min(Double::compareTo)
|
|
|
+ .orElse(0.0);
|
|
|
+ double max = scoreMap.values().stream()
|
|
|
+ .max(Double::compareTo)
|
|
|
+ .orElse(0.0);
|
|
|
+
|
|
|
+ List<Score> scores = CommonCollectionUtils.toList(param.getContents(), c -> {
|
|
|
+ Score score = new Score();
|
|
|
+ score.setContentId(c.getId());
|
|
|
+ double val = scoreMap.get(c.getId()) == null ? 0.0 : scoreMap.get(c.getId());
|
|
|
+ score.setScore(NormalizationUtils.minMax(val, min, max));
|
|
|
+ score.setStrategy(this);
|
|
|
+ return score;
|
|
|
+ });
|
|
|
+ return scores;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|