|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +package org.apache.wayang.basic.operators; |
| 20 | + |
| 21 | +import com.fasterxml.jackson.core.type.TypeReference; |
| 22 | +import org.apache.wayang.basic.data.Tuple2; |
| 23 | +import org.apache.wayang.basic.model.Model; |
| 24 | +import org.apache.wayang.core.api.Configuration; |
| 25 | +import org.apache.wayang.core.optimizer.cardinality.CardinalityEstimator; |
| 26 | +import org.apache.wayang.core.plan.wayangplan.BinaryToUnaryOperator; |
| 27 | +import org.apache.wayang.core.types.DataSetType; |
| 28 | +import org.apache.wayang.core.util.TypeConverter; |
| 29 | + |
| 30 | +import java.util.Optional; |
| 31 | + |
| 32 | +public class ModelTransformOperator<X, Y> extends BinaryToUnaryOperator<Model<X, Y>, X, Tuple2<X, Y>> { |
| 33 | + |
| 34 | + public static ModelTransformOperator<double[], Integer> kMeans() { |
| 35 | + // The type of TypeReference cannot be omitted, to avoid the following error. |
| 36 | + // error: cannot infer type arguments for TypeReference<T>, reason: cannot use '<>' with anonymous inner classes |
| 37 | + return new ModelTransformOperator<>(new TypeReference<double[]>() {}, new TypeReference<Tuple2<double[], Integer>>() {}); |
| 38 | + } |
| 39 | + |
| 40 | + public static ModelTransformOperator<double[], Double> linearRegression() { |
| 41 | + return new ModelTransformOperator<>(new TypeReference<double[]>() {}, new TypeReference<Tuple2<double[], Double>>() {}); |
| 42 | + } |
| 43 | + |
| 44 | + public static ModelTransformOperator<double[], Integer> decisionTreeClassification() { |
| 45 | + return new ModelTransformOperator<>(new TypeReference<double[]>() {}, new TypeReference<Tuple2<double[], Integer>>() {}); |
| 46 | + } |
| 47 | + |
| 48 | + public ModelTransformOperator(DataSetType<X> inType, DataSetType<Tuple2<X, Y>> outType) { |
| 49 | + // TODO createDefaultUnchecked or createDefault? |
| 50 | + super(DataSetType.createDefaultUnchecked(Model.class), inType, outType, false); |
| 51 | + } |
| 52 | + |
| 53 | + public ModelTransformOperator(Class<X> inType, Class<Tuple2<X, Y>> outType) { |
| 54 | + this(DataSetType.createDefault(inType), DataSetType.createDefault(outType)); |
| 55 | + } |
| 56 | + |
| 57 | + public ModelTransformOperator(TypeReference<X> inType, TypeReference<Tuple2<X, Y>> outType) { |
| 58 | + this(TypeConverter.convert(inType), TypeConverter.convert(outType)); |
| 59 | + } |
| 60 | + |
| 61 | + public ModelTransformOperator(ModelTransformOperator<X, Y> that) { |
| 62 | + super(that); |
| 63 | + } |
| 64 | + |
| 65 | + @Override |
| 66 | + public Optional<CardinalityEstimator> createCardinalityEstimator(int outputIndex, Configuration configuration) { |
| 67 | + // TODO |
| 68 | + return super.createCardinalityEstimator(outputIndex, configuration); |
| 69 | + } |
| 70 | +} |
0 commit comments