当前位置: 首页>>代码示例>>Java>>正文


Java Expression类代码示例

本文整理汇总了Java中org.dmg.pmml.Expression的典型用法代码示例。如果您正苦于以下问题:Java Expression类的具体用法?Java Expression怎么用?Java Expression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Expression类属于org.dmg.pmml包,在下文中一共展示了Expression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleExpression

import org.dmg.pmml.Expression; //导入依赖的package包/类
private void handleExpression(int preProcessingStepIndex, DerivedField derivedField) {
    if (derivedField.getExpression() instanceof Apply) {
        for (Expression expression : ((Apply) derivedField.getExpression()).getExpressions()) {
            if (expression instanceof Apply) {
                if (((Apply) expression).getFunction().equals("isMissing")) {
                    // now find the value that is supposed to replace the missing value

                    for (Expression expression2 : ((Apply) derivedField.getExpression()).getExpressions()) {
                        if (expression2 instanceof Constant) {
                            String missingValue = ((Constant) expression2).getValue();
                            preProcessingSteps[preProcessingStepIndex] = new MissingValuePreProcess(derivedField, missingValue);
                            break;
                        }
                    }
                } else {
                    throw new UnsupportedOperationException("So far only if isMissing implemented.");
                }
            }
        }
    } else if (derivedField.getExpression() instanceof NormContinuous) {
        preProcessingSteps[preProcessingStepIndex] = new NormContinousPreProcess((NormContinuous) derivedField
                .getExpression(), derivedField.getName().getValue());
    } else {
        throw new UnsupportedOperationException("So far only Apply expression implemented.");
    }
}
 
开发者ID:brwe,项目名称:es-token-plugin,代码行数:27,代码来源:PMMLVectorRange.java

示例2: createExpression

import org.dmg.pmml.Expression; //导入依赖的package包/类
static
public Expression createExpression(Number multiplier, FieldRef fieldRef){
	Number one;

	if(multiplier instanceof Float){
		one = 1f;
	} else

	if(multiplier instanceof Double){
		one = 1d;
	} else

	{
		throw new IllegalArgumentException();
	}

	return PMMLUtil.createApply("/", PMMLUtil.createConstant(one), PMMLUtil.createApply("+", PMMLUtil.createConstant(one), PMMLUtil.createApply("exp", PMMLUtil.createApply("*", PMMLUtil.createConstant(multiplier), fieldRef))));
}
 
开发者ID:jpmml,项目名称:jpmml-converter,代码行数:19,代码来源:SigmoidTransformation.java

示例3: encodeDefineFunction

import org.dmg.pmml.Expression; //导入依赖的package包/类
@Override
public DefineFunction encodeDefineFunction(){
	TfidfTransformer transformer = getTransformer();

	DefineFunction defineFunction = super.encodeDefineFunction();

	Expression expression = defineFunction.getExpression();

	Boolean sublinearTf = transformer.getSublinearTf();
	if(sublinearTf){
		expression = PMMLUtil.createApply("+", PMMLUtil.createApply("log", expression), PMMLUtil.createConstant(1d));
	} // End if

	Boolean useIdf = transformer.getUseIdf();
	if(useIdf){
		ParameterField weight = new ParameterField(FieldName.create("weight"));

		defineFunction.addParameterFields(weight);

		expression = PMMLUtil.createApply("*", expression, new FieldRef(weight.getName()));
	}

	defineFunction.setExpression(expression);

	return defineFunction;
}
 
开发者ID:jpmml,项目名称:jpmml-sklearn,代码行数:27,代码来源:TfidfVectorizer.java

示例4: inlineLogicalExpressions

import org.dmg.pmml.Expression; //导入依赖的package包/类
static
private void inlineLogicalExpressions(Apply apply){
	String function = apply.getFunction();

	List<Expression> expressions = apply.getExpressions();
	for(ListIterator<Expression> expressionIt = expressions.listIterator(); expressionIt.hasNext(); ){
		Expression expression = expressionIt.next();

		if(expression instanceof Apply){
			Apply nestedApply = (Apply)expression;

			if((function).equals(nestedApply.getFunction())){
				expressionIt.remove();

				// Deep inline
				inlineLogicalExpressions(nestedApply);

				List<Expression> nestedExpressions = nestedApply.getExpressions();
				for(Expression nestedExpression : nestedExpressions){
					expressionIt.add(nestedExpression);
				}
			}
		}
	}
}
 
开发者ID:jpmml,项目名称:jpmml-r,代码行数:26,代码来源:ExpressionCompactor.java

示例5: filter

import org.dmg.pmml.Expression; //导入依赖的package包/类
private Schema filter(Schema schema){
	Function<Feature, Feature> function = new Function<Feature, Feature>(){

		@Override
		public Feature apply(Feature feature){
			Expression expression = encodeExpression(feature);

			if(expression == null){
				return feature;
			}

			DerivedField derivedField = createDerivedField(FeatureUtil.createName("preProcess", feature), OpType.CONTINUOUS, DataType.DOUBLE, expression);

			return new ContinuousFeature(PreProcessEncoder.this, derivedField);
		}
	};

	return schema.toTransformedSchema(function);
}
 
开发者ID:jpmml,项目名称:jpmml-r,代码行数:20,代码来源:PreProcessEncoder.java

示例6: checkApply

import org.dmg.pmml.Expression; //导入依赖的package包/类
static
private boolean checkApply(Apply apply, String function, Class<? extends Expression>... expressionClazzes){

	if((function).equals(apply.getFunction())){
		List<Expression> expressions = apply.getExpressions();

		if(expressionClazzes.length == expressions.size()){

			for(int i = 0; i < expressionClazzes.length; i++){
				Class<? extends Expression> expressionClazz = expressionClazzes[i];
				Expression expression = expressions.get(i);

				if(!(expressionClazz).isInstance(expression)){
					return false;
				}
			}

			return true;
		}
	}

	return false;
}
 
开发者ID:jpmml,项目名称:jpmml-r,代码行数:24,代码来源:Formula.java

示例7: encodeIfElseExpression

import org.dmg.pmml.Expression; //导入依赖的package包/类
static
private Expression encodeIfElseExpression(FunctionExpression functionExpression, VariableMap expressionFields, RExpEncoder encoder){
	FunctionExpression.Argument testArgument = functionExpression.getArgument("test", 0);

	expressionFields.putAll(testArgument);

	FunctionExpression.Argument yesArgument = functionExpression.getArgument("yes", 1);
	FunctionExpression.Argument noArgument = functionExpression.getArgument("no", 2);

	expressionFields.putAll(yesArgument);
	expressionFields.putAll(noArgument);

	// XXX: "Missing values in test give missing values in the result"
	Apply apply = PMMLUtil.createApply("if")
		.addExpressions(prepareExpression(testArgument, expressionFields, encoder))
		.addExpressions(prepareExpression(yesArgument, expressionFields, encoder), prepareExpression(noArgument, expressionFields, encoder));

	return apply;
}
 
开发者ID:jpmml,项目名称:jpmml-r,代码行数:20,代码来源:FormulaUtil.java

示例8: prepareInputField

import org.dmg.pmml.Expression; //导入依赖的package包/类
static
private FieldName prepareInputField(FunctionExpression.Argument argument, OpType opType, DataType dataType, RExpEncoder encoder){
	Expression expression = argument.getExpression();

	if(expression instanceof FieldRef){
		FieldRef fieldRef = (FieldRef)expression;

		return fieldRef.getField();
	} else

	if(expression instanceof Apply){
		Apply apply = (Apply)expression;

		DerivedField derivedField = encoder.createDerivedField(FieldName.create((argument.formatExpression()).trim()), opType, dataType, apply);

		return derivedField.getName();
	} else

	{
		throw new IllegalArgumentException();
	}
}
 
开发者ID:jpmml,项目名称:jpmml-r,代码行数:23,代码来源:FormulaUtil.java

示例9: prepareExpression

import org.dmg.pmml.Expression; //导入依赖的package包/类
static
private Expression prepareExpression(FunctionExpression.Argument argument, VariableMap expressionFields, RExpEncoder encoder){
	Expression expression = argument.getExpression();

	if(expression instanceof FunctionExpression){
		FunctionExpression functionExpression = (FunctionExpression)expression;

		if(functionExpression.hasId("base", "ifelse")){
			return encodeIfElseExpression(functionExpression, expressionFields, encoder);
		}

		throw new IllegalArgumentException();
	}

	return expression;
}
 
开发者ID:jpmml,项目名称:jpmml-r,代码行数:17,代码来源:FormulaUtil.java

示例10: createHingeFunction

import org.dmg.pmml.Expression; //导入依赖的package包/类
static
private Apply createHingeFunction(int dir, Feature feature, double cut){
	Expression expression;

	switch(dir){
		case -1:
			expression = PMMLUtil.createApply("-", PMMLUtil.createConstant(cut), feature.ref());
			break;
		case 1:
			expression = PMMLUtil.createApply("-", feature.ref(), PMMLUtil.createConstant(cut));
			break;
		default:
			throw new IllegalArgumentException();
	}

	return PMMLUtil.createApply("max", expression, PMMLUtil.createConstant(0d));
}
 
开发者ID:jpmml,项目名称:jpmml-r,代码行数:18,代码来源:EarthConverter.java

示例11: translateLogicalExpression

import org.dmg.pmml.Expression; //导入依赖的package包/类
@Test
public void translateLogicalExpression(){
	Apply apply = (Apply)ExpressionTranslator.translateExpression("a >= 0.0 & b >= 0.0 | c <= 0.0");

	List<Expression> expressions = checkApply(apply, "or", Apply.class, Apply.class);

	Expression left = expressions.get(0);
	Expression right = expressions.get(1);

	expressions = checkApply((Apply)left, "and", Apply.class, Apply.class);
	checkApply((Apply)right, "lessOrEqual", FieldRef.class, Constant.class);

	left = expressions.get(0);
	right = expressions.get(1);

	checkApply((Apply)left, "greaterOrEqual", FieldRef.class, Constant.class);
	checkApply((Apply)right, "greaterOrEqual", FieldRef.class, Constant.class);
}
 
开发者ID:jpmml,项目名称:jpmml-r,代码行数:19,代码来源:ExpressionTranslatorTest.java

示例12: translateArithmeticExpressionChain

import org.dmg.pmml.Expression; //导入依赖的package包/类
@Test
public void translateArithmeticExpressionChain(){
	Apply apply = (Apply)ExpressionTranslator.translateExpression("A + B - X + C");

	List<Expression> expressions = checkApply(apply, "+", Apply.class, FieldRef.class);

	Expression left = expressions.get(0);
	Expression right = expressions.get(1);

	expressions = checkApply((Apply)left, "-", Apply.class, FieldRef.class);
	checkFieldRef((FieldRef)right, FieldName.create("C"));

	left = expressions.get(0);
	right = expressions.get(1);

	expressions = checkApply((Apply)left, "+", FieldRef.class, FieldRef.class);
	checkFieldRef((FieldRef)right, FieldName.create("X"));

	left = expressions.get(0);
	right = expressions.get(1);

	checkFieldRef((FieldRef)left, FieldName.create("A"));
	checkFieldRef((FieldRef)right, FieldName.create("B"));
}
 
开发者ID:jpmml,项目名称:jpmml-r,代码行数:25,代码来源:ExpressionTranslatorTest.java

示例13: checkApply

import org.dmg.pmml.Expression; //导入依赖的package包/类
static
private List<Expression> checkApply(Apply apply, String function, Class<? extends Expression>... expressionClazzes){
	assertEquals(function, apply.getFunction());

	List<Expression> expressions = apply.getExpressions();
	assertEquals(expressionClazzes.length, expressions.size());

	for(int i = 0; i < expressionClazzes.length; i++){
		Class<? extends Expression> expressionClazz = expressionClazzes[i];
		Expression expression = expressions.get(i);

		assertEquals(expressionClazz, expression.getClass());
	}

	return expressions;
}
 
开发者ID:jpmml,项目名称:jpmml-r,代码行数:17,代码来源:ExpressionTranslatorTest.java

示例14: correct

import org.dmg.pmml.Expression; //导入依赖的package包/类
@Test
public void correct(){
	Apply apply = new Apply("substring")
		.addExpressions(new FieldRef(FieldName.create("AnyCInput")), new Constant("1"), new Constant("FMTWIDTH"));

	ExpressionCorrector expressionCorrector = new ExpressionCorrector();
	expressionCorrector.applyTo(apply);

	List<Expression> expressions = apply.getExpressions();

	Expression string = expressions.get(0);
	Expression position = expressions.get(1);
	Expression length = expressions.get(2);

	assertTrue(string instanceof FieldRef);
	assertEquals(FieldName.create("AnyCInput"), ((FieldRef)string).getField());

	assertTrue(position instanceof Constant);
	assertEquals("1", ((Constant)position).getValue());

	assertTrue(length instanceof FieldRef);
	assertEquals(FieldName.create("FMTWIDTH"), ((FieldRef)length).getField());
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:24,代码来源:ExpressionCorrectorTest.java

示例15: encodeFeatures

import org.dmg.pmml.Expression; //导入依赖的package包/类
@Override
public List<Feature> encodeFeatures(SparkMLEncoder encoder){
	PCAModel transformer = getTransformer();

	List<Feature> features = encoder.getFeatures(transformer.getInputCol());

	DenseMatrix pc = transformer.pc();
	if(pc.numRows() != features.size()){
		throw new IllegalArgumentException();
	}

	List<Feature> result = new ArrayList<>();

	for(int i = 0; i < transformer.getK(); i++){
		Apply apply = new Apply("sum");

		for(int j = 0; j < features.size(); j++){
			Feature feature = features.get(j);

			ContinuousFeature continuousFeature = feature.toContinuousFeature();

			Expression expression = continuousFeature.ref();

			Double coefficient = pc.apply(j, i);
			if(!ValueUtil.isOne(coefficient)){
				expression = PMMLUtil.createApply("*", expression, PMMLUtil.createConstant(coefficient));
			}

			apply.addExpressions(expression);
		}

		DerivedField derivedField = encoder.createDerivedField(formatName(transformer, i), OpType.CONTINUOUS, DataType.DOUBLE, apply);

		result.add(new ContinuousFeature(encoder, derivedField));
	}

	return result;
}
 
开发者ID:jpmml,项目名称:jpmml-sparkml,代码行数:39,代码来源:PCAModelConverter.java


注:本文中的org.dmg.pmml.Expression类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。