Java Code Examples for org.dmg.pmml.DataType#INTEGER

The following examples show how to use org.dmg.pmml.DataType#INTEGER . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeUtil.java    From jpmml-tensorflow with GNU Affero General Public License v3.0 6 votes vote down vote up
static
public DataType getDataType(Output output){
	org.tensorflow.DataType dataType = output.dataType();

	switch(dataType){
		case FLOAT:
			return DataType.FLOAT;
		case DOUBLE:
			return DataType.DOUBLE;
		case INT32:
		case INT64:
			return DataType.INTEGER;
		case STRING:
			return DataType.STRING;
		case BOOL:
			return DataType.BOOLEAN;
		default:
			throw new IllegalArgumentException();
	}
}
 
Example 2
Source File: DatasetUtil.java    From jpmml-sparkml with GNU Affero General Public License v3.0 6 votes vote down vote up
static
public DataType translateDataType(org.apache.spark.sql.types.DataType sparkDataType){

	if(sparkDataType instanceof StringType){
		return DataType.STRING;
	} else

	if(sparkDataType instanceof IntegralType){
		return DataType.INTEGER;
	} else

	if(sparkDataType instanceof DoubleType){
		return DataType.DOUBLE;
	} else

	if(sparkDataType instanceof BooleanType){
		return DataType.BOOLEAN;
	} else

	{
		throw new IllegalArgumentException("Expected string, integral, double or boolean data type, got " + sparkDataType.typeName() + " data type");
	}
}
 
Example 3
Source File: FunctionTransformerTest.java    From jpmml-sklearn with GNU Affero General Public License v3.0 5 votes vote down vote up
static
private Object evaluate(String function, Object value){
	UFunc ufunc = new UFunc("numpy.core", "_ufunc_reconstruct");
	ufunc.__init__(new String[]{"numpy", function});

	FieldName name = FieldName.create("x");

	DataType dataType;

	if(value instanceof Integer){
		dataType = DataType.INTEGER;
	} else

	if(value instanceof Float){
		dataType = DataType.FLOAT;
	} else

	{
		dataType = DataType.DOUBLE;
	}

	EvaluationContext context = new VirtualEvaluationContext();
	context.declare(name, FieldValueUtil.create(dataType, OpType.CONTINUOUS, value));

	Expression expression = UFuncUtil.encodeUFunc(ufunc, Collections.singletonList(new FieldRef(name)));

	FieldValue result = ExpressionUtil.evaluate(expression, context);

	return FieldValueUtil.getValue(result);
}
 
Example 4
Source File: RIntegerVector.java    From jpmml-r with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public DataType getDataType(){

	if(isFactor()){
		return DataType.STRING;
	}

	return DataType.INTEGER;
}
 
Example 5
Source File: TypeUtil.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
static
public DataType getConstantDataType(String value){

	if(("").equals(value)){
		return DataType.STRING;
	} else

	if(("NaN").equalsIgnoreCase(value) || ("INF").equalsIgnoreCase(value) || ("-INF").equalsIgnoreCase(value)){
		return DataType.DOUBLE;
	}

	try {
		if(value.indexOf('.') > -1){
			Double.parseDouble(value);

			return DataType.DOUBLE;
		} else

		{
			Long.parseLong(value);

			return DataType.INTEGER;
		}
	} catch(NumberFormatException nfe){
		return DataType.STRING;
	}
}
 
Example 6
Source File: FieldValueTest.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void ordinalInteger(){
	OrdinalValue zero = (OrdinalValue)FieldValueUtil.create(DataType.INTEGER, OpType.ORDINAL, 0);
	OrdinalValue one = (OrdinalValue)FieldValueUtil.create(DataType.INTEGER, OpType.ORDINAL, 1);

	assertTrue(zero.equalsValue("0"));
	assertTrue(zero.equalsValue("0.0"));

	assertTrue(zero.compareToValue("-1") > 0);
	assertTrue(zero.compareToValue("0") == 0);
	assertTrue(zero.compareToValue("1") < 0);

	assertTrue(zero.compareTo(zero) == 0);
	assertTrue(zero.compareTo(one) < 0);

	assertTrue(one.compareTo(zero) > 0);
	assertTrue(one.compareTo(one) == 0);

	TypeInfo typeInfo = new SimpleTypeInfo(DataType.INTEGER, OpType.ORDINAL, Arrays.asList(1, 0));

	zero = (OrdinalValue)FieldValueUtil.create(typeInfo, zero.getValue());

	assertTrue(zero.compareTo(zero) == 0);
	assertTrue(zero.compareTo(one) > 0);

	one = (OrdinalValue)FieldValueUtil.create(typeInfo, one.getValue());

	assertTrue(one.compareTo(zero) < 0);
	assertTrue(one.compareTo(one) == 0);
}
 
Example 7
Source File: DurationTransformer.java    From jpmml-sklearn with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public DataType getDataType(){
	return DataType.INTEGER;
}
 
Example 8
Source File: SecondsSinceMidnightTransformer.java    From jpmml-sklearn with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public DataType getDataType(){
	return DataType.INTEGER;
}
 
Example 9
Source File: ContinuousValue.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
ContinuousInteger(Object value){
	super(DataType.INTEGER, value);
}