
org.jpmml.evaluator.FieldUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pmml-evaluator Show documentation
Show all versions of pmml-evaluator Show documentation
JPMML class model evaluator
/*
* Copyright (c) 2018 Villu Ruusmann
*
* This file is part of JPMML-Evaluator
*
* JPMML-Evaluator 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-Evaluator 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-Evaluator. If not, see .
*/
package org.jpmml.evaluator;
import java.util.ArrayList;
import java.util.List;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableRangeSet;
import com.google.common.collect.Range;
import com.google.common.collect.RangeSet;
import com.google.common.collect.TreeRangeSet;
import org.dmg.pmml.DataField;
import org.dmg.pmml.DataType;
import org.dmg.pmml.Field;
import org.dmg.pmml.HasContinuousDomain;
import org.dmg.pmml.HasDiscreteDomain;
import org.dmg.pmml.Interval;
import org.dmg.pmml.Value;
public class FieldUtil {
private FieldUtil(){
}
static
public List getCategories(DataField dataField){
return CacheUtil.getValue(dataField, FieldUtil.categoryCache);
}
static
public & HasDiscreteDomain> List> getValidValues(F field){
return CacheUtil.getValue(field, FieldUtil.validValueCache);
}
static
public & HasContinuousDomain> RangeSet getValidRanges(F field){
return CacheUtil.getValue(field, FieldUtil.validRangeCache);
}
static
private List parseCategories(DataField dataField){
List result = new ArrayList<>();
if(dataField.hasValues()){
List pmmlValues = dataField.getValues();
for(Value pmmlValue : pmmlValues){
String stringValue = pmmlValue.getValue();
if(stringValue == null){
throw new MissingAttributeException(pmmlValue, PMMLAttributes.VALUE_VALUE);
}
Value.Property property = pmmlValue.getProperty();
switch(property){
case VALID:
result.add(stringValue);
break;
default:
break;
}
}
}
return result;
}
static
private & HasDiscreteDomain> List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy