當前位置: 首頁>>代碼示例>>Java>>正文


Java Expressions.apply方法代碼示例

本文整理匯總了Java中com.sri.ai.expresso.helper.Expressions.apply方法的典型用法代碼示例。如果您正苦於以下問題:Java Expressions.apply方法的具體用法?Java Expressions.apply怎麽用?Java Expressions.apply使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.sri.ai.expresso.helper.Expressions的用法示例。


在下文中一共展示了Expressions.apply方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: visitFunctionType

import com.sri.ai.expresso.helper.Expressions; //導入方法依賴的package包/類
@Override 
public Expression visitFunctionType(AntlrGrinderParser.FunctionTypeContext ctx) { 
    Object[] arguments  = new Object[2];
    if (ctx.domaintypes.size() == 1) {
        Expression domain = visit(ctx.domaintypes.get(0));					
        arguments[0] = domain;
    }
    else {
        Object[] domainArgs = new Object[ctx.domaintypes.size()];
        for (int i = 0; i < ctx.domaintypes.size(); i++) {
            domainArgs[i] = visit(ctx.domaintypes.get(i));
        }
        Expression tupleType = Expressions.apply(FunctorConstants.TUPLE_TYPE, domainArgs);
        arguments[0] = tupleType;
    }
    arguments[1] = visit(ctx.rangetype);
    Expression result = Expressions.apply(FunctorConstants.FUNCTION_TYPE, arguments);
    return result;
}
 
開發者ID:aic-sri-international,項目名稱:aic-expresso,代碼行數:20,代碼來源:ExpressionVisitor.java

示例2: simplify

import com.sri.ai.expresso.helper.Expressions; //導入方法依賴的package包/類
static public Expression simplify(Expression expression) {
    Expression result = expression;
    
    Expression first = expression.get(0);
    Expression second = expression.get(1);

    if (Expressions.isNumber(first)) {
        Rational firstValue = first.rationalValue();
        if (Expressions.isNumber(second)) {
            Rational secondValue = second.rationalValue();
            result = Expressions.makeSymbol(firstValue.subtract(secondValue));
        } 
        else if (firstValue.isZero()) {
            result = Expressions.apply("-", second);
        }
    } 
    else if (Expressions.isNumber(second) && second.rationalValue().isZero()) {
        result = first;
    }
        
    return result;
}
 
開發者ID:aic-sri-international,項目名稱:aic-expresso,代碼行數:23,代碼來源:BinaryMinus.java

示例3: applySimplifier

import com.sri.ai.expresso.helper.Expressions; //導入方法依賴的package包/類
@Override
public Expression applySimplifier(Expression expression, Context context) {
    // We need to override this method because INFINITY and MINUS_INFINITY
    // are not Java constants.
    Expression result;
    if ( ! isExtensional(expression)) {
        result = expression;
    }
    else {
        // takes care of infinity arguments before deferring to super method
        if (expression.getArguments().contains(INFINITY)) {
            result = INFINITY;
        }
        else {
            // remove MINUS_INFINITY if any and defer to super method
            List<Expression> argumentsWithoutMinusInfinity =
                    Util.removeNonDestructively(expression.getArguments(), MINUS_INFINITY);
            Expression expressionWithoutMinusInfinity =
                    expression.getArguments() == argumentsWithoutMinusInfinity?
                            expression : Expressions.apply(expression.getFunctor(), argumentsWithoutMinusInfinity);
            result = super.apply(expressionWithoutMinusInfinity, context);
        }
    }
    return result;
}
 
開發者ID:aic-sri-international,項目名稱:aic-expresso,代碼行數:26,代碼來源:Max.java

示例4: simplify

import com.sri.ai.expresso.helper.Expressions; //導入方法依賴的package包/類
public static Expression simplify(Expression conjunction) {
    Expression result = conjunction;
    if (conjunction.getArguments().contains(Expressions.FALSE)) {
        result = Expressions.FALSE;
    }
    else {
        LinkedHashSet<Expression> distinctArgumentsNotEqualToTrue = new LinkedHashSet<Expression>();
        Util.collect(conjunction.getArguments(), distinctArgumentsNotEqualToTrue, e -> ! e.equals(Expressions.TRUE));
        if (distinctArgumentsNotEqualToTrue.size() != conjunction.getArguments().size()) {
            if (distinctArgumentsNotEqualToTrue.size() == 0) {
                result = Expressions.TRUE;
            }
            else if (distinctArgumentsNotEqualToTrue.size() == 1) {
                result = Util.getFirst(distinctArgumentsNotEqualToTrue);
            }
            else if (distinctArgumentsNotEqualToTrue.size() != conjunction.numberOfArguments()) {
                result = Expressions.apply(FunctorConstants.AND, distinctArgumentsNotEqualToTrue);
            }
        }
    }
    return result;
}
 
開發者ID:aic-sri-international,項目名稱:aic-expresso,代碼行數:23,代碼來源:And.java

示例5: copyIndexExpressionWithNewIndex

import com.sri.ai.expresso.helper.Expressions; //導入方法依賴的package包/類
public static Expression copyIndexExpressionWithNewIndex(Expression indexExpression, Expression newIndex) {
    if (newIndex != IndexExpressions.getIndex(indexExpression)) {
        Expression result;
        if (indexExpression.hasFunctor("in")) {
            result = Expressions.apply("in", newIndex, indexExpression.get(1));
        }
        else {
            result = newIndex;
        }
        return result;
    }
    return indexExpression;
}
 
開發者ID:aic-sri-international,項目名稱:aic-expresso,代碼行數:14,代碼來源:IndexExpressions.java

示例6: getTypeCardinality

import com.sri.ai.expresso.helper.Expressions; //導入方法依賴的package包/類
/**
 * Returns the cardinality of the type of a given variable in the given registry,
 * looking for <code>| Type |</code>, for <code>Type</code> the type of the variable,
 * in the registry global objects.
 * If the size cannot be determined, returns -1.
 * If the size is infinite, returns -2.
 * @param symbol a variable
 * @param registry the registry
 * @return the cardinality of the type of the variable according to the registry or -1 if it cannot be determined.
 */
public static long getTypeCardinality(Expression symbol, Registry registry) {
    long result = -1;

    Expression variableType = registry.getTypeExpressionOfRegisteredSymbol(symbol);
    if (variableType != null) {
        Expression typeCardinality = Expressions.apply(FunctorConstants.CARDINALITY, variableType);
        Expression typeCardinalityValue = (Expression) registry.getGlobalObject(typeCardinality);
        if (typeCardinalityValue != null) {
            result = typeCardinalityValue.intValueExact();
        }
    }
    
    // If that didn't work, we try find the Type object:
    if (result == -1) {
        variableType = registry.getTypeExpressionOfRegisteredSymbol(symbol);
        if (variableType != null) {
            Type type = registry.getTypeFromTypeExpression(variableType);
            if (type != null) {
                Expression sizeExpression = type.cardinality();
                if (sizeExpression.equals(apply(CARDINALITY, type.getName()))) {
                    result = -1;
                }
                else if (sizeExpression.equals(Expressions.INFINITY)) {
                    result = -2;
                }
                else {
                    result = sizeExpression.intValue();
                }
            }
        }
    }
    
    return result;
}
 
開發者ID:aic-sri-international,項目名稱:aic-expresso,代碼行數:45,代碼來源:GrinderUtil.java

示例7: add

import com.sri.ai.expresso.helper.Expressions; //導入方法依賴的package包/類
@Override
public Expression add(Expression value1, Expression value2, Context context) {
    Expression result;
    if (value1.getValue() instanceof Number && value2.getValue() instanceof Number) {
        Rational rationalValue1 = value1.rationalValue();
        Rational rationalValue2 = value2.rationalValue();
        if (rationalValue1.compareTo(rationalValue2) > 0) {
            result = value1;
        }
        else {
            result = value2;
        }
    }
    else if (value1.equals(INFINITY) || value2.equals(INFINITY)) {
        result = INFINITY;
    }
    else if (isMinusInfinity(value1)) {
        result = value2;
    }
    else if (isMinusInfinity(value2)) {
        result = value1;
    }
    else {
        result = Expressions.apply(MAX, value1, value2);
    }
    return result;
}
 
開發者ID:aic-sri-international,項目名稱:aic-expresso,代碼行數:28,代碼來源:Max.java

示例8: makeIntersection

import com.sri.ai.expresso.helper.Expressions; //導入方法依賴的package包/類
public static Expression makeIntersection(Expression... sets) {
    if (sets.length == 0) {
        throw new IllegalArgumentException("No set arguments passed to construct intersection with.");
    }
    
    Expression result;
    if (sets.length == 1) {
        result = sets[0];			
    }
    else {
        result = Expressions.apply(FunctorConstants.INTERSECTION, (Object []) sets);
    }
    return result;
}
 
開發者ID:aic-sri-international,項目名稱:aic-expresso,代碼行數:15,代碼來源:Sets.java

示例9: make

import com.sri.ai.expresso.helper.Expressions; //導入方法依賴的package包/類
/**
 * Makes a disequality of two expressions, returning Expressions.FALSE if
 * the expressions are identical.
 */
public static Expression make(Object expression1Object,
        Object expression2Object) {
    Expression expression1 = Expressions.wrap(expression1Object);
    Expression expression2 = Expressions.wrap(expression2Object);
    if (expression1.equals(expression2)) {
        return Expressions.FALSE;
    }
    return Expressions.apply(DISEQUALITY, expression1, expression2);
}
 
開發者ID:aic-sri-international,項目名稱:aic-expresso,代碼行數:14,代碼來源:Disequality.java

示例10: getAtomNegation

import com.sri.ai.expresso.helper.Expressions; //導入方法依賴的package包/類
/**
 * Inverts <code>=</code> to <code>!=</code> and vice-versa,
 * and adds <code>not</code> to other atoms.
 */
@Override
public Expression getAtomNegation(Expression atom, Context context) {
    Expression result;
    if (atom.hasFunctor(EQUALITY)) {
        result = Expressions.apply(DISEQUALITY, atom.get(0), atom.get(1));
    }
    else if (atom.hasFunctor(DISEQUALITY)) {
        result = Expressions.apply(EQUALITY, atom.get(0), atom.get(1));
    }
    else {
        result = not(atom);
    }
    return result;
}
 
開發者ID:aic-sri-international,項目名稱:aic-expresso,代碼行數:19,代碼來源:AbstractTheoryWithBinaryAtomsIncludingEquality.java

示例11: simplify

import com.sri.ai.expresso.helper.Expressions; //導入方法依賴的package包/類
public static Expression simplify(Expression expression, Context context) {
    Expression result = expression;
    
    if (Expressions.hasFunctor(expression, FunctorConstants.IN) && expression.numberOfArguments() == 2) {
        Expression t   = expression.get(0);
        Expression set = expression.get(1);
        if (Sets.isExtensionalSet(set)) {
            // if empty set
            if (set.numberOfArguments() == 0) {
                result = Expressions.FALSE;
            }
            else if (set.numberOfArguments() == 1) {
                // (t = t<sub>1</sub>)
                result = Equality.make(t, set.get(0));
            }
            else { // > 1 element to test
                // (t = t<sub>1</sub>)
                Expression tEqualsT1         = Equality.make(t, set.get(0));
                // {t<sub>2</sub>,&hellip;,t<sub>n</sub>}
                Expression tailSet           = ExtensionalSets.makeOfSameTypeAs(set, set.getArguments().subList(1, set.numberOfArguments()));
                // t &isin; {t<sub>2</sub>,&hellip;,t<sub>n</sub>}
                Expression tElementOfTailSet = Expressions.apply(FunctorConstants.IN, t, tailSet);
                // (t = t<sub>1</sub>) &or; t &isin; {t<sub>2</sub>,&hellip;,t<sub>n</sub>}
                result = Or.make(tEqualsT1, tElementOfTailSet);
            }
        }
    }
    
    return result;
}
 
開發者ID:aic-sri-international,項目名稱:aic-expresso,代碼行數:31,代碼來源:ElementOfExtensionalSetSimplifier.java

示例12: make

import com.sri.ai.expresso.helper.Expressions; //導入方法依賴的package包/類
/** Make a "not" application on given expression. */
public static Expression make(Expression expression) {
    if (expression.equals(Expressions.TRUE)) {
        return Expressions.FALSE;
    }
    if (expression.equals(Expressions.FALSE)) {
        return Expressions.TRUE;
    }
    return Expressions.apply("not", expression);
}
 
開發者ID:aic-sri-international,項目名稱:aic-expresso,代碼行數:11,代碼來源:Not.java

示例13: makeFunctionApplication

import com.sri.ai.expresso.helper.Expressions; //導入方法依賴的package包/類
protected Expression makeFunctionApplication(String functorName, FunctionType functionType) {
    // Generate arguments for the application
    List<Expression> args = new ArrayList<>();
    for (Type argType : functionType.getArgumentTypes()) {
        // If constants supported, use at random
        if (argType.isSampleUniquelyNamedConstantSupported() && getRandom().nextBoolean()) {
            args.add(argType.sampleUniquelyNamedConstant(getRandom()));
        }
        else {
            // Otherwise retrieve a term variable matching that type and use it
            String termVariable = pickTestingVariableAtRandom(getTermVariableNamesAndTypesForTesting(), argType, variableName -> true);
            Type   termType     = getTermVariableNamesAndTypesForTesting().get(termVariable);
            if (termType instanceof FunctionType) {
                // Allow for nested function applications
                args.add(makeFunctionApplication(termVariable, (FunctionType) termType));
            }
            else {
                // Otherwise just assign the variable for the term.
                args.add(parse(termVariable));
            }
        }
    }
            
    Expression result = Expressions.apply(functorName, args.toArray(new Object[args.size()]));
            
    return result;
}
 
開發者ID:aic-sri-international,項目名稱:aic-expresso,代碼行數:28,代碼來源:BruteForceFunctionTheoryTestingSupport.java

示例14: make

import com.sri.ai.expresso.helper.Expressions; //導入方法依賴的package包/類
public static Expression make(Expression argument) {
    if (argument.getValue() instanceof Number) {
        return Expressions.makeSymbol(argument.rationalValue().negate());
    }
    return Expressions.apply(FunctorConstants.MINUS, argument);
}
 
開發者ID:aic-sri-international,項目名稱:aic-expresso,代碼行數:7,代碼來源:UnaryMinus.java

示例15: reassembleComparisonWithIsolatedNegativeVariable

import com.sri.ai.expresso.helper.Expressions; //導入方法依賴的package包/類
private static Expression reassembleComparisonWithIsolatedNegativeVariable(Expression variable, Expression numericalComparison, ArrayList<Expression> side) {
    Expression sideSummation = Plus.make(side);
    Expression result = Expressions.apply(numericalComparison.getFunctor(), sideSummation, variable);
    return result;
}
 
開發者ID:aic-sri-international,項目名稱:aic-expresso,代碼行數:6,代碼來源:DifferenceArithmeticUtil.java


注:本文中的com.sri.ai.expresso.helper.Expressions.apply方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。