@@ -0,0 +1,2554 @@
+/**%0A * Licensed to the Apache Software Foundation (ASF) under one%0A * or more contributor license agreements.  See the NOTICE file%0A * distributed with this work for additional information%0A * regarding copyright ownership.  The ASF licenses this file%0A * to you under the Apache License, Version 2.0 (the%0A * %22License%22); you may not use this file except in compliance%0A * with the License.  You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage com.dataartisans.flink.dataflow;%0A%0Aimport com.google.cloud.dataflow.examples.TfIdf;%0Aimport com.google.cloud.dataflow.sdk.Pipeline;%0Aimport com.google.cloud.dataflow.sdk.coders.StringDelegateCoder;%0Aimport com.google.cloud.dataflow.sdk.io.TextIO;%0Aimport com.google.cloud.dataflow.sdk.transforms.Create;%0Aimport com.google.cloud.dataflow.sdk.transforms.Keys;%0Aimport com.google.cloud.dataflow.sdk.transforms.RemoveDuplicates;%0Aimport com.google.cloud.dataflow.sdk.values.KV;%0Aimport com.google.cloud.dataflow.sdk.values.PCollection;%0Aimport com.google.common.base.Joiner;%0Aimport org.apache.flink.test.util.JavaProgramTestBase;%0A%0Aimport java.net.URI;%0A%0A%0Apublic class TfIdfITCase extends JavaProgramTestBase %7B%0A%0A%09protected String resultPath;%0A%0A%09public TfIdfITCase()%7B%0A%09%7D%0A%0A%09static final String%5B%5D EXPECTED_RESULT = new String%5B%5D %7B%0A%09%09%09%22a%22, %22m%22, %22n%22, %22b%22, %22c%22, %22d%22%7D;%0A%0A%09@Override%0A%09protected void preSubmit() throws Exception %7B%0A%09%09resultPath = getTempDirPath(%22result%22);%0A%09%7D%0A%0A%09@Override%0A%09protected void postSubmit() throws Exception %7B%0A%09%09compareResultsByLinesInMemory(Joiner.on('%5Cn').join(EXPECTED_RESULT), resultPath);%0A%09%7D%0A%0A%09@Override%0A%09protected void testProgram() throws Exception %7B%0A%0A%09%09Pipeline pipeline = FlinkTestPipeline.create();%0A%0A%09%09pipeline.getCoderRegistry().registerCoder(URI.class, StringDelegateCoder.of(URI.class));%0A%0A%09%09PCollection%3CKV%3CString, KV%3CURI, Double%3E%3E%3E wordToUriAndTfIdf = pipeline%0A%09%09%09%09.apply(Create.of(%0A%09%09%09%09%09%09KV.of(new URI(%22x%22), %22a b c d%22),%0A%09%09%09%09%09%09KV.of(new URI(%22y%22), %22a b c%22),%0A%09%09%09%09%09%09KV.of(new URI(%22z%22), %22a m n%22)))%0A%09%09%09%09.apply(new TfIdf.ComputeTfIdf());%0A%0A%09%09PCollection%3CString%3E words = wordToUriAndTfIdf%0A%09%09%09%09.apply(Keys.%3CString%3Ecreate())%0A%09%09%09%09.apply(RemoveDuplicates.%3CString%3Ecreate());%0A%0A%09%09words.apply(TextIO.Write.to(resultPath));%0A%0A%09%09pipeline.run();%0A%09%7D%0A%7D%0A%0A

Add TfIdfITCase