|
@@ -0,0 +1,56 @@
|
|
|
+package examples.dataloader;
|
|
|
+import com.google.common.collect.ArrayListMultimap;
|
|
|
+import com.google.common.collect.ListMultimap;
|
|
|
+import com.tzld.piaoquan.recommend.feature.domain.video.feature.BytesGroup;
|
|
|
+import com.tzld.piaoquan.recommend.feature.domain.video.feature.BytesUtils;
|
|
|
+import com.tzld.piaoquan.recommend.feature.gen.recommend.BaseFeature;
|
|
|
+import com.tzld.piaoquan.recommend.feature.gen.recommend.FeatureGroup;
|
|
|
+
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+public class OfflineVlogShareLRFeatureExtractor {
|
|
|
+
|
|
|
+ public ListMultimap<FeatureGroup, BaseFeature> featureMap = ArrayListMultimap.create();
|
|
|
+
|
|
|
+ private BytesUtils utils;
|
|
|
+ public OfflineVlogShareLRFeatureExtractor() {
|
|
|
+ BytesGroup[] groups = new BytesGroup[OfflineVlogFeatureGroup.values().length];
|
|
|
+ OfflineVlogFeatureGroup[] var2 = OfflineVlogFeatureGroup.values();
|
|
|
+ int var3 = var2.length;
|
|
|
+
|
|
|
+ for(int var4 = 0; var4 < var3; ++var4) {
|
|
|
+ OfflineVlogFeatureGroup g = var2[var4];
|
|
|
+ groups[g.ordinal()] = new BytesGroup(g.ordinal(), g.getGroupName(), g.getGroupNameBytes());
|
|
|
+ }
|
|
|
+ this.utils = new BytesUtils(groups);
|
|
|
+ }
|
|
|
+ public void makeFeature(Map<String, Object> maps){
|
|
|
+ for (Map.Entry<String, Object> entry : maps.entrySet()){
|
|
|
+ OfflineVlogFeatureGroup ovf = OfflineVlogFeatureGroup.valueOf(entry.getKey());
|
|
|
+ Object value = entry.getValue();
|
|
|
+ if (value instanceof String){
|
|
|
+ this.makeFea(ovf, ((String)value).getBytes());
|
|
|
+ }else if (value instanceof Double){
|
|
|
+ this.makeFea(ovf, String.valueOf((Double)value).getBytes());
|
|
|
+ }else if (value instanceof Integer){
|
|
|
+ //todo
|
|
|
+ }else{
|
|
|
+ //todo
|
|
|
+ this.makeFea(ovf, ((String)value).getBytes());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private FeatureGroup makeGroup(OfflineVlogFeatureGroup group) {
|
|
|
+ FeatureGroup.Builder g = FeatureGroup.newBuilder();
|
|
|
+ g.setType("1");
|
|
|
+ g.setName(group.getGroupName());
|
|
|
+ g.setId(group.ordinal());
|
|
|
+ return g.build();
|
|
|
+ }
|
|
|
+ void makeFea(OfflineVlogFeatureGroup group, byte[] value) {
|
|
|
+ FeatureGroup featureGroup = this.makeGroup(group);
|
|
|
+ BaseFeature feature = this.utils.makeFea(group.ordinal(), value);
|
|
|
+ this.featureMap.put(featureGroup, feature);
|
|
|
+ }
|
|
|
+}
|