...
|
...
|
@@ -2,34 +2,42 @@ package com.yoho.search.service.recall.models.personal; |
|
|
|
|
|
import com.yoho.search.core.personalized.models.PersonalizedSearch;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
public class UserFeatureFactor {
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(UserFeatureFactor.class);
|
|
|
|
|
|
private List<Double> userFeatureVectorList = null;
|
|
|
private double userFeatureVectorNorm = 0.0D;
|
|
|
private String vectorFeatureVersion;
|
|
|
|
|
|
public UserFeatureFactor(PersonalizedSearch personalizedSearch) {
|
|
|
if (personalizedSearch == null) {
|
|
|
return;
|
|
|
}
|
|
|
this.vectorFeatureVersion = personalizedSearch.getVectorFeatureVersion();
|
|
|
String userVectorFeature = personalizedSearch.getUserVectorFeature();
|
|
|
if(StringUtils.isBlank(userVectorFeature)){
|
|
|
return;
|
|
|
}
|
|
|
String[] userFeatureFactorStrArr = userVectorFeature.split(",");
|
|
|
if(userFeatureFactorStrArr.length==0){
|
|
|
return;
|
|
|
}
|
|
|
userFeatureVectorList = new ArrayList<>(userFeatureFactorStrArr.length);
|
|
|
for (String userFeatureFactorStr : userFeatureFactorStrArr) {
|
|
|
double userFeatureVector = Double.parseDouble(userFeatureFactorStr.trim());
|
|
|
userFeatureVectorList.add(userFeatureVector);
|
|
|
userFeatureVectorNorm += userFeatureVector * userFeatureVector;
|
|
|
try {
|
|
|
if (personalizedSearch == null) {
|
|
|
return;
|
|
|
}
|
|
|
this.vectorFeatureVersion = personalizedSearch.getVectorFeatureVersion();
|
|
|
String userVectorFeature = personalizedSearch.getUserVectorFeature();
|
|
|
if(StringUtils.isBlank(userVectorFeature)){
|
|
|
return;
|
|
|
}
|
|
|
String[] userFeatureFactorStrArr = userVectorFeature.split(",");
|
|
|
if(userFeatureFactorStrArr.length==0){
|
|
|
return;
|
|
|
}
|
|
|
userFeatureVectorList = new ArrayList<>(userFeatureFactorStrArr.length);
|
|
|
for (String userFeatureFactorStr : userFeatureFactorStrArr) {
|
|
|
double userFeatureVector = Double.parseDouble(userFeatureFactorStr.trim());
|
|
|
userFeatureVectorList.add(userFeatureVector);
|
|
|
userFeatureVectorNorm += userFeatureVector * userFeatureVector;
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
logger.error(e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
|