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


##########
flink-ml-python/pyflink/ml/recommendation/swing.py:
##########
@@ -0,0 +1,209 @@
+################################################################################
+#  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.
+################################################################################
+import typing
+
+from pyflink.ml.common.param import HasOutputCol
+from pyflink.ml.param import Param, StringParam, IntParam, FloatParam, 
ParamValidators
+from pyflink.ml.recommendation.common import JavaRecommendationTransformer
+from pyflink.ml.wrapper import JavaWithParams
+
+
+class _SwingParams(
+    JavaWithParams,
+    HasOutputCol
+):
+    """
+    Params for :class:`Swing`.
+    """
+
+    USER_COL: Param[str] = StringParam(
+        "user_col",
+        "Name of user column.",
+        "user",
+        ParamValidators.not_null())
+
+    ITEM_COL: Param[str] = StringParam(
+        "item_col",
+        "Name of item column.",
+        "item",
+        ParamValidators.not_null())
+
+    K: Param[int] = IntParam(
+        "k",
+        "The max number of similar items to output for each item.",
+        100,
+        ParamValidators.gt(0))
+
+    MAX_USER_NUM_PER_ITEM: Param[int] = IntParam(
+        "max_user_num_per_item",
+        "The max number of users that has purchased for each item. If the 
number of users that have "
+        + "purchased this item is larger than this value, then only 
maxUserNumPerItem users will "
+        + "be sampled and used in the computation logic.",
+        1000,
+        ParamValidators.gt(0))
+
+    MIN_USER_BEHAVIOR: Param[int] = IntParam(
+        "min_user_behavior",
+        "The min number of interaction behavior between item and user.",
+        10,
+        ParamValidators.gt(0))
+
+    MAX_USER_BEHAVIOR: Param[int] = IntParam(
+        "max_user_behavior",
+        "The max number of interaction behavior between item and user."
+        + "The algorithm filters out activate users.",
+        1000,
+        ParamValidators.gt(0))
+
+    ALPHA1: Param[int] = IntParam(
+        "alpha2",
+        "This parameter is used to calculate weight of each user.",
+        15,
+        ParamValidators.gt_eq(0))
+
+    ALPHA2: Param[int] = IntParam(
+        "alpha2",
+        "This parameter is used to calculate similarity of users.",
+        0,
+        ParamValidators.gt_eq(0))
+
+    BETA: Param[float] = FloatParam(
+        "beta",
+        "This parameter is used to calculate weight of each user.",
+        0.3,
+        ParamValidators.gt_eq(0))
+
+    def __init__(self, java_params):
+        super(_SwingParams, self).__init__(java_params)
+
+    def set_user_col(self, value: str):
+        return typing.cast(_SwingParams, self.set(self.USER_COL, value))
+
+    def get_user_col(self) -> str:
+        return self.get(self.USER_COL)
+
+    def set_item_col(self, value: str):
+        return typing.cast(_SwingParams, self.set(self.ITEM_COL, value))
+
+    def get_item_col(self) -> str:
+        return self.get(self.ITEM_COL)
+
+    def set_k(self, value: int):
+        return typing.cast(_SwingParams, self.set(self.K, value))
+
+    def get_k(self) -> int:
+        return self.get(self.K)
+
+    def set_max_user_num_per_item(self, value: int):
+        return typing.cast(_SwingParams, self.set(self.MAX_USER_NUM_PER_ITEM, 
value))
+
+    def get_max_user_num_per_item(self) -> int:
+        return self.get(self.MAX_USER_NUM_PER_ITEM)
+
+    def set_min_user_behavior(self, value: int):
+        return typing.cast(_SwingParams, self.set(self.MIN_USER_BEHAVIOR, 
value))
+
+    def get_min_user_behavior(self) -> int:
+        return self.get(self.MIN_USER_BEHAVIOR)
+
+    def set_max_user_behavior(self, value: int):
+        return typing.cast(_SwingParams, self.set(self.MAX_USER_BEHAVIOR, 
value))
+
+    def get_max_user_behavior(self) -> int:
+        return self.get(self.MAX_USER_BEHAVIOR)
+
+    def set_alpha1(self, value: int):
+        return typing.cast(_SwingParams, self.set(self.ALPHA1, value))
+
+    def get_alpha1(self) -> int:
+        return self.get(self.ALPHA1)
+
+    def set_alpha2(self, value: int):
+        return typing.cast(_SwingParams, self.set(self.ALPHA2, value))
+
+    def get_alpha2(self) -> int:
+        return self.get(self.ALPHA2)
+
+    def set_beta(self, value: float):
+        return typing.cast(_SwingParams, self.set(self.BETA, value))
+
+    def get_beta(self) -> float:
+        return self.get(self.BETA)
+
+    @property
+    def user_col(self) -> str:
+        return self.get_user_col()
+
+    @property
+    def item_col(self) -> str:
+        return self.get_item_col()
+
+    @property
+    def k(self) -> int:
+        return self.get_k()
+
+    @property
+    def max_user_num_per_item(self) -> int:
+        return self.get_max_user_num_per_item()
+
+    @property
+    def min_user_behavior(self) -> int:
+        return self.get_min_user_behavior()
+
+    @property
+    def max_user_behavior(self) -> int:
+        return self.get_max_user_behavior()
+
+    @property
+    def alpha1(self) -> int:
+        return self.get_alpha1()
+
+    @property
+    def alpha2(self) -> float:
+        return self.get_alpha2()
+
+    @property
+    def beta(self) -> float:
+        return self.get_beta()
+
+
+class Swing(JavaRecommendationTransformer, _SwingParams):

Review Comment:
   In Java code, `Swing` is an implementation of `AlgoOperator`. So here 
`Swing` should extends corresponding Python class.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to