use of org.dmg.pmml.Apply in project jpmml-r by jpmml.
the class ExpressionTranslatorTest method translateLogicalExpressionChain.
@Test
public void translateLogicalExpressionChain() {
String string = "(x == 0) | ((x == 1) | (x == 2)) | x == 3";
Apply apply = (Apply) ExpressionTranslator.translateExpression(string, false);
List<Expression> expressions = checkApply(apply, "or", Apply.class, Apply.class);
Expression left = expressions.get(0);
Expression right = expressions.get(1);
checkApply((Apply) left, "or", Apply.class, Apply.class);
checkApply((Apply) right, "equal", FieldRef.class, Constant.class);
apply = (Apply) ExpressionTranslator.translateExpression(string, true);
checkApply(apply, "or", Apply.class, Apply.class, Apply.class, Apply.class);
}
use of org.dmg.pmml.Apply in project jpmml-sparkml by jpmml.
the class TermFeature method toContinuousFeature.
@Override
public ContinuousFeature toContinuousFeature() {
PMMLEncoder encoder = ensureEncoder();
DerivedField derivedField = encoder.getDerivedField(getName());
if (derivedField == null) {
Apply apply = createApply();
derivedField = encoder.createDerivedField(getName(), OpType.CONTINUOUS, getDataType(), apply);
}
return new ContinuousFeature(encoder, derivedField);
}
use of org.dmg.pmml.Apply in project jpmml-sparkml by jpmml.
the class TermFeature method toWeightedTermFeature.
public WeightedTermFeature toWeightedTermFeature(double weight) {
PMMLEncoder encoder = ensureEncoder();
DefineFunction defineFunction = getDefineFunction();
String name = (defineFunction.getName()).replace("tf@", "tf-idf@");
DefineFunction weightedDefineFunction = encoder.getDefineFunction(name);
if (weightedDefineFunction == null) {
ParameterField weightField = new ParameterField(FieldName.create("weight"));
List<ParameterField> parameterFields = new ArrayList<>(defineFunction.getParameterFields());
parameterFields.add(weightField);
Apply apply = PMMLUtil.createApply("*", defineFunction.getExpression(), new FieldRef(weightField.getName()));
weightedDefineFunction = new DefineFunction(name, OpType.CONTINUOUS, parameterFields).setDataType(DataType.DOUBLE).setExpression(apply);
encoder.addDefineFunction(weightedDefineFunction);
}
return new WeightedTermFeature(encoder, weightedDefineFunction, getFeature(), getValue(), weight);
}
use of org.dmg.pmml.Apply in project jpmml-sparkml by jpmml.
the class RegexTokenizerConverter method encodeFeatures.
@Override
public List<Feature> encodeFeatures(SparkMLEncoder encoder) {
RegexTokenizer transformer = getTransformer();
if (!transformer.getGaps()) {
throw new IllegalArgumentException("Expected splitter mode, got token matching mode");
}
if (transformer.getMinTokenLength() != 1) {
throw new IllegalArgumentException("Expected 1 as minimum token length, got " + transformer.getMinTokenLength() + " as minimum token length");
}
Feature feature = encoder.getOnlyFeature(transformer.getInputCol());
Field<?> field = encoder.getField(feature.getName());
if (transformer.getToLowercase()) {
Apply apply = PMMLUtil.createApply("lowercase", feature.ref());
field = encoder.createDerivedField(FeatureUtil.createName("lowercase", feature), OpType.CATEGORICAL, DataType.STRING, apply);
}
return Collections.<Feature>singletonList(new DocumentFeature(encoder, field, transformer.getPattern()));
}
use of org.dmg.pmml.Apply in project jpmml-sparkml by jpmml.
the class BinarizerConverter method encodeFeatures.
@Override
public List<Feature> encodeFeatures(SparkMLEncoder encoder) {
Binarizer transformer = getTransformer();
Feature feature = encoder.getOnlyFeature(transformer.getInputCol());
ContinuousFeature continuousFeature = feature.toContinuousFeature();
Apply apply = new Apply("if").addExpressions(PMMLUtil.createApply("lessOrEqual", continuousFeature.ref(), PMMLUtil.createConstant(transformer.getThreshold()))).addExpressions(PMMLUtil.createConstant(0d), PMMLUtil.createConstant(1d));
DerivedField derivedField = encoder.createDerivedField(formatName(transformer), OpType.CATEGORICAL, DataType.DOUBLE, apply);
return Collections.<Feature>singletonList(new CategoricalFeature(encoder, derivedField, Arrays.asList("0", "1")));
}
Aggregations