com.fluxtion.runtime.ml.PropertyToFeature Maven / Gradle / Ivy
package com.fluxtion.runtime.ml;
import com.fluxtion.runtime.annotations.builder.AssignToField;
import com.fluxtion.runtime.dataflow.FlowSupplier;
import com.fluxtion.runtime.partition.LambdaReflection;
import com.fluxtion.runtime.partition.LambdaReflection.SerializableToDoubleFunction;
/**
* uses a lambda {@link SerializableToDoubleFunction} to extract a property from an incoming FlowSupplier and use that as
* the value for a feature.
*
* @param
*/
public class PropertyToFeature extends FlowSuppliedFeature {
private final SerializableToDoubleFunction propertyExtractor;
public static PropertyToFeature build(
String name,
FlowSupplier dataFlowSupplier,
SerializableToDoubleFunction propertyExtractor) {
return new PropertyToFeature<>(name, dataFlowSupplier, propertyExtractor);
}
public static MapPropertyToFeature build(
String name,
FlowSupplier dataFlowSupplier,
LambdaReflection.SerializableFunction propertyExtractor,
SerializableToDoubleFunction propertyMapper) {
return new MapPropertyToFeature<>(name, dataFlowSupplier, propertyExtractor, propertyMapper);
}
public PropertyToFeature(
@AssignToField("name") String name,
@AssignToField("dataFlowSupplier") FlowSupplier dataFlowSupplier,
@AssignToField("propertyExtractor") SerializableToDoubleFunction propertyExtractor) {
super(name, name, dataFlowSupplier);
this.propertyExtractor = propertyExtractor;
}
@Override
public double extractFeatureValue() {
return propertyExtractor.applyAsDouble(data());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy