Skip to content

Commit

Permalink
Improved support for boolean features
Browse files Browse the repository at this point in the history
  • Loading branch information
vruusmann committed Feb 27, 2023
1 parent f26c515 commit 523b772
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import com.google.common.collect.Iterables;
Expand All @@ -36,12 +37,10 @@
import org.dmg.pmml.InlineTable;
import org.dmg.pmml.MapValues;
import org.dmg.pmml.OpType;
import org.dmg.pmml.PMMLAttributes;
import org.jpmml.evaluator.FieldValue;
import org.jpmml.evaluator.FieldValueUtil;
import org.jpmml.evaluator.InlineTableUtil;
import org.jpmml.evaluator.TypeUtil;
import org.jpmml.model.InvalidAttributeException;
import org.jpmml.model.InvalidElementException;
import org.jpmml.model.UnsupportedElementException;

Expand Down Expand Up @@ -97,14 +96,20 @@ public void translateExpression(TranslationContext context){
switch(inputDataType){
case BOOLEAN:
{
if(defaultValue != null){
throw new InvalidAttributeException(mapValues, PMMLAttributes.MAPVALUES_DEFAULTVALUE, defaultValue);
}
Object trueValue = mapping.getOrDefault(Boolean.TRUE, defaultValue);
Object falseValue = mapping.getOrDefault(Boolean.FALSE, defaultValue);

if(Objects.equals(trueValue, Boolean.TRUE) && Objects.equals(falseValue, Boolean.FALSE)){
context._return(fieldValueRef.asBoolean());
} else

Object trueValue = mapping.get(Boolean.TRUE);
Object falseValue = mapping.get(Boolean.FALSE);
if(Objects.equals(trueValue, Boolean.FALSE) && Objects.equals(falseValue, Boolean.TRUE)){
context._return((fieldValueRef.asBoolean()).not());
} else

context._return(JOp.cond(fieldValueRef.asJavaValue(), PMMLObjectUtil.createExpression(trueValue, context), PMMLObjectUtil.createExpression(falseValue, context)));
{
context._return(JOp.cond(fieldValueRef.asBoolean(), PMMLObjectUtil.createExpression(trueValue, context), PMMLObjectUtil.createExpression(falseValue, context)));
}
}
break;
default:
Expand Down

0 comments on commit 523b772

Please sign in to comment.