jiangxin369 commented on code in PR #191: URL: https://github.com/apache/flink-ml/pull/191#discussion_r1060261023
########## flink-ml-examples/src/main/java/org/apache/flink/ml/examples/feature/MinHashLSHExample.java: ########## @@ -0,0 +1,155 @@ +/* + * 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.examples.feature; + +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.api.common.typeinfo.Types; +import org.apache.flink.ml.feature.lsh.MinHashLSH; +import org.apache.flink.ml.feature.lsh.MinHashLSHModel; +import org.apache.flink.ml.linalg.DenseVector; +import org.apache.flink.ml.linalg.SparseVector; +import org.apache.flink.ml.linalg.Vector; +import org.apache.flink.ml.linalg.Vectors; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.table.api.Table; +import org.apache.flink.table.api.bridge.java.StreamTableEnvironment; +import org.apache.flink.types.Row; + +import org.apache.commons.collections.IteratorUtils; + +import java.util.Arrays; +import java.util.List; + +import static org.apache.flink.table.api.Expressions.$; + +/** + * Simple program that trains a MinHashLSH model and uses it for approximate nearest neighbors and + * similarity join. + */ +public class MinHashLSHExample { + public static void main(String[] args) throws Exception { + + // Creates a new StreamExecutionEnvironment + StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); + + // Creates a StreamTableEnvironment + StreamTableEnvironment tEnv = StreamTableEnvironment.create(env); + + // Generates two datasets + Table data = + tEnv.fromDataStream( + env.fromCollection( + Arrays.asList( + Row.of( + 0, + Vectors.sparse( + 6, + new int[] {0, 1, 2}, + new double[] {1., 1., 1.})), + Row.of( + 1, + Vectors.sparse( + 6, + new int[] {2, 3, 4}, + new double[] {1., 1., 1.})), + Row.of( + 2, + Vectors.sparse( + 6, + new int[] {0, 2, 4}, + new double[] {1., 1., 1.}))), + Types.ROW_NAMED( + new String[] {"id", "vec"}, + Types.INT, + TypeInformation.of(SparseVector.class)))); + + Table dataB = Review Comment: As the examples are expected to be the best practice for users, the variable naming should be more strict. Would it be better if rename the `data` to `inputTable`, `dataB` to `similarityJoinTable`? `dataA` and `dataB` are also acceptable. So as in the python example. -- 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]
