vacaly commented on code in PR #192:
URL: https://github.com/apache/flink-ml/pull/192#discussion_r1053893147


##########
flink-ml-lib/src/main/java/org/apache/flink/ml/recommendation/SwingModel.java:
##########
@@ -0,0 +1,251 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.ml.recommendation;
+
+import org.apache.flink.api.common.functions.RichFlatMapFunction;
+import org.apache.flink.api.common.serialization.Encoder;
+import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.common.typeutils.base.FloatSerializer;
+import org.apache.flink.api.common.typeutils.base.ListSerializer;
+import org.apache.flink.api.common.typeutils.base.StringSerializer;
+import org.apache.flink.api.java.typeutils.RowTypeInfo;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.connector.file.src.reader.SimpleStreamFormat;
+import org.apache.flink.core.fs.FSDataInputStream;
+import org.apache.flink.core.memory.DataInputView;
+import org.apache.flink.core.memory.DataInputViewStreamWrapper;
+import org.apache.flink.core.memory.DataOutputView;
+import org.apache.flink.core.memory.DataOutputViewStreamWrapper;
+import org.apache.flink.ml.api.Model;
+import org.apache.flink.ml.clustering.kmeans.KMeans;
+import org.apache.flink.ml.common.broadcast.BroadcastUtils;
+import org.apache.flink.ml.common.datastream.TableUtils;
+import org.apache.flink.ml.param.Param;
+import org.apache.flink.ml.recommendation.SwingModelData.ModelDataDecoder;
+import org.apache.flink.ml.util.ParamUtils;
+import org.apache.flink.ml.util.ReadWriteUtils;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
+import org.apache.flink.table.api.internal.TableImpl;
+import org.apache.flink.types.Row;
+import org.apache.flink.util.Collector;
+import org.apache.flink.util.Preconditions;
+
+import org.apache.commons.lang3.ArrayUtils;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A Model which recommends item for top-N similar items using the model data 
computed by {@link Swing} .
+ */
+public class SwingModel implements Model <SwingModel>, SwingModelParams 
<SwingModel> {
+       private final Map <Param <?>, Object> paramMap = new HashMap <>();
+       private Table modelDataTable;
+       private final String SWING_ITEM_NAME = "SWING_ITEM_NAME";
+       private final String SWING_ITEM_RANK = "SWING_ITEM_RANK";
+       private final String SWING_ITEM_SCORE = "SWING_ITEM_SCORE";
+
+       public SwingModel() {
+               ParamUtils.initializeMapWithDefaultValues(paramMap, this);
+       }
+
+       @Override
+       public SwingModel setModelData(Table... inputs) {
+               modelDataTable = inputs[0];
+               return this;
+       }
+
+       @Override
+       public Table[] getModelData() {
+               return new Table[] {modelDataTable};
+       }
+
+       @Override
+       public Table[] transform(Table... inputs) {
+               Preconditions.checkArgument(inputs.length == 1);
+               final String predictItemCol = getItemCol();
+               final String broadcastModelKey = "broadcastModelKey";
+
+               StreamTableEnvironment tEnv =
+                       (StreamTableEnvironment) ((TableImpl) 
inputs[0]).getTableEnvironment();
+               DataStream <Row> data = tEnv.toDataStream(inputs[0]);
+               DataStream <SwingModelData> model 
=SwingModelData.getDataStream(tEnv,modelDataTable);
+
+               RowTypeInfo inputTypeInfo = 
TableUtils.getRowTypeInfo(inputs[0].getResolvedSchema());
+               RowTypeInfo outputTypeInfo =
+                       new RowTypeInfo(
+                               ArrayUtils.addAll(
+                                       inputTypeInfo.getFieldTypes(),
+                                       BasicTypeInfo.STRING_TYPE_INFO,
+                                       BasicTypeInfo.INT_TYPE_INFO,
+                                       BasicTypeInfo.FLOAT_TYPE_INFO),
+                               ArrayUtils.addAll(inputTypeInfo.getFieldNames(),
+                                       SWING_ITEM_NAME,

Review Comment:
   No, It's better to be a parameter set by user. Should I use `HasOutputCol` 
and combine a sequence of recommendation items, rank and score?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to