All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jpmml.sparkml.WeightedTermFeature Maven / Gradle / Ivy

There is a newer version: 3.1.0
Show newest version
/*
 * Copyright (c) 2017 Villu Ruusmann
 *
 * This file is part of JPMML-SparkML
 *
 * JPMML-SparkML is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * JPMML-SparkML is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with JPMML-SparkML.  If not, see .
 */
package org.jpmml.sparkml;

import java.util.Objects;

import org.dmg.pmml.Apply;
import org.dmg.pmml.DefineFunction;
import org.jpmml.converter.ExpressionUtil;
import org.jpmml.converter.Feature;
import org.jpmml.converter.PMMLEncoder;
import org.jpmml.model.ToStringHelper;

public class WeightedTermFeature extends TermFeature {

	private Number weight = null;


	public WeightedTermFeature(PMMLEncoder encoder, DefineFunction defineFunction, Feature feature, String value, Number weight){
		super(encoder, defineFunction, feature, value);

		setWeight(weight);
	}

	@Override
	public Apply createApply(){
		Number weight = getWeight();

		Apply apply = super.createApply()
			.addExpressions(ExpressionUtil.createConstant(weight));

		return apply;
	}

	@Override
	public int hashCode(){
		return (31 * super.hashCode()) + Objects.hashCode(this.getWeight());
	}

	@Override
	public boolean equals(Object object){

		if(object instanceof WeightedTermFeature){
			WeightedTermFeature that = (WeightedTermFeature)object;

			return super.equals(object) && Objects.equals(this.getWeight(), that.getWeight());
		}

		return false;
	}

	@Override
	protected ToStringHelper toStringHelper(){
		return super.toStringHelper()
			.add("weight", getWeight());
	}

	public Number getWeight(){
		return this.weight;
	}

	private void setWeight(Number weight){
		this.weight = Objects.requireNonNull(weight);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy