Search in sources :

Example 1 with FunctionType

use of org.geotoolkit.ogc.xml.v200.FunctionType in project geotoolkit by Geomatys.

the class FilterToOGC200Converter method convert.

private FunctionType convert(final Expression source) {
    List<Expression> parameters = source.getParameters();
    final FunctionType function = ogc_factory.createFunctionType();
    function.getExpression().add(extract(parameters.get(0)));
    function.getExpression().add(extract(parameters.get(1)));
    return function;
}
Also used : Expression(org.opengis.filter.Expression) FunctionType(org.geotoolkit.ogc.xml.v200.FunctionType)

Example 2 with FunctionType

use of org.geotoolkit.ogc.xml.v200.FunctionType in project geo-platform by geosdi.

the class BaseBinaryStrategy method createBinaryComparisonTypeForDate.

/**
 * @param queryRestrictionDTO
 * @return {@link BinaryComparisonOpType}
 */
protected BinaryComparisonOpType createBinaryComparisonTypeForDate(QueryRestrictionDTO queryRestrictionDTO) {
    return new BinaryComparisonOpType() {

        {
            PropertyNameType propertyNameType = new PropertyNameType();
            propertyNameType.setContent(asList(queryRestrictionDTO.getAttribute().getName()));
            FunctionType functionType = new FunctionType();
            functionType.setName("dateParse");
            LiteralType literalType = new LiteralType();
            literalType.setContent(asList(queryRestrictionDTO.getRestriction()));
            LiteralType literalTypeFormat = new LiteralType();
            literalTypeFormat.setContent(dateFormatStrategyFinder.findDateFormat(queryRestrictionDTO.getAttribute()));
            List<JAXBElement<?>> functionElements = new ArrayList<>(2);
            functionElements.add(filterFactory.createLiteral(literalTypeFormat));
            functionElements.add(filterFactory.createLiteral(literalType));
            functionType.setExpression(functionElements);
            List<JAXBElement<?>> elements = new ArrayList<>(2);
            elements.add(filterFactory.createPropertyName(propertyNameType));
            elements.add(filterFactory.createFunction(functionType));
            super.setExpression(elements);
        }
    };
}
Also used : FunctionType(org.geosdi.geoplatform.xml.filter.v110.FunctionType) ArrayList(java.util.ArrayList) LiteralType(org.geosdi.geoplatform.xml.filter.v110.LiteralType) JAXBElement(javax.xml.bind.JAXBElement) BinaryComparisonOpType(org.geosdi.geoplatform.xml.filter.v110.BinaryComparisonOpType) PropertyNameType(org.geosdi.geoplatform.xml.filter.v110.PropertyNameType)

Example 3 with FunctionType

use of org.geotoolkit.ogc.xml.v200.FunctionType in project ddf by codice.

the class CswFilterFactory method createPropertyIsEqualTo.

public FilterType createPropertyIsEqualTo(String functionName, List<? extends JAXBElement<?>> expressions, Object literal) {
    FunctionType function = new FunctionType();
    function.setName(functionName);
    function.getExpression().addAll(expressions);
    FilterType filter = new FilterType();
    BinaryComparisonOpType propertyIsEqualTo = new BinaryComparisonOpType();
    propertyIsEqualTo.getExpression().add(filterObjectFactory.createFunction(function));
    propertyIsEqualTo.getExpression().add(createLiteralType(literal));
    filter.setComparisonOps(filterObjectFactory.createPropertyIsEqualTo(propertyIsEqualTo));
    return filter;
}
Also used : FilterType(net.opengis.filter.v_1_1_0.FilterType) FunctionType(net.opengis.filter.v_1_1_0.FunctionType) BinaryComparisonOpType(net.opengis.filter.v_1_1_0.BinaryComparisonOpType)

Example 4 with FunctionType

use of org.geotoolkit.ogc.xml.v200.FunctionType in project java-smt by sosy-lab.

the class CVC4FormulaCreator method visit.

@Override
public <R> R visit(FormulaVisitor<R> visitor, Formula formula, final Expr f) {
    checkState(!f.isNull());
    Type type = f.getType();
    if (f.isConst()) {
        if (type.isBoolean()) {
            return visitor.visitConstant(formula, f.getConstBoolean());
        } else if (type.isInteger() || type.isReal()) {
            return visitor.visitConstant(formula, f.getConstRational());
        } else if (type.isBitVector()) {
            // TODO is this correct?
            return visitor.visitConstant(formula, f.getConstBitVector().getValue());
        } else if (type.isFloatingPoint()) {
            // TODO is this correct?
            return visitor.visitConstant(formula, f.getConstFloatingPoint());
        } else if (type.isRoundingMode()) {
            // TODO is this correct?
            return visitor.visitConstant(formula, f.getConstRoundingMode());
        } else if (type.isString()) {
            return visitor.visitConstant(formula, f.getConstString());
        } else {
            throw new UnsupportedOperationException("Unhandled constant " + f + " with type " + type);
        }
    } else if (f.getKind() == Kind.BOUND_VARIABLE) {
        // BOUND vars are used for all vars that are bound to a quantifier in CVC4.
        // We resubstitute them back to the original free.
        // CVC4 doesn't give you the de-brujin index
        Expr originalVar = variablesCache.get(formula.toString());
        return visitor.visitBoundVariable(encapsulate(originalVar), 0);
    } else if (f.getKind() == Kind.FORALL || f.getKind() == Kind.EXISTS) {
        // QUANTIFIER: replace bound variable with free variable for visitation
        assert f.getNumChildren() == 2;
        Expr body = f.getChildren().get(1);
        List<Formula> freeVars = new ArrayList<>();
        for (Expr boundVar : f.getChild(0)) {
            // unpack grand-children of f.
            String name = getName(boundVar);
            Expr freeVar = Preconditions.checkNotNull(variablesCache.get(name));
            body = body.substitute(boundVar, freeVar);
            freeVars.add(encapsulate(freeVar));
        }
        BooleanFormula fBody = encapsulateBoolean(body);
        Quantifier quant = f.getKind() == Kind.EXISTS ? Quantifier.EXISTS : Quantifier.FORALL;
        return visitor.visitQuantifier((BooleanFormula) formula, quant, freeVars, fBody);
    } else if (f.isVariable()) {
        assert f.getKind() != Kind.BOUND_VARIABLE;
        return visitor.visitFreeVariable(formula, getName(f));
    } else {
        // Expressions like uninterpreted function calls (Kind.APPLY_UF) or operators (e.g. Kind.AND).
        // These are all treated like operators, so we can get the declaration by f.getOperator()!
        List<Formula> args = ImmutableList.copyOf(Iterables.transform(f, this::encapsulate));
        List<FormulaType<?>> argsTypes = new ArrayList<>();
        Expr operator = normalize(f.getOperator());
        if (operator.getType().isFunction()) {
            vectorType argTypes = new FunctionType(operator.getType()).getArgTypes();
            for (int i = 0; i < argTypes.size(); i++) {
                argsTypes.add(getFormulaTypeFromTermType(argTypes.get(i)));
            }
        } else {
            for (Expr arg : f) {
                argsTypes.add(getFormulaType(arg));
            }
        }
        checkState(args.size() == argsTypes.size());
        // additional parameters? We do so for some methods of Princess.
        return visitor.visitFunction(formula, args, FunctionDeclarationImpl.of(getName(f), getDeclarationKind(f), argsTypes, getFormulaType(f), operator));
    }
}
Also used : CVC4.vectorType(edu.stanford.CVC4.vectorType) FunctionType(edu.stanford.CVC4.FunctionType) ArrayList(java.util.ArrayList) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) RegexFormula(org.sosy_lab.java_smt.api.RegexFormula) StringFormula(org.sosy_lab.java_smt.api.StringFormula) FloatingPointFormula(org.sosy_lab.java_smt.api.FloatingPointFormula) BitvectorFormula(org.sosy_lab.java_smt.api.BitvectorFormula) CVC4BooleanFormula(org.sosy_lab.java_smt.solvers.cvc4.CVC4Formula.CVC4BooleanFormula) CVC4StringFormula(org.sosy_lab.java_smt.solvers.cvc4.CVC4Formula.CVC4StringFormula) CVC4FloatingPointFormula(org.sosy_lab.java_smt.solvers.cvc4.CVC4Formula.CVC4FloatingPointFormula) ArrayFormula(org.sosy_lab.java_smt.api.ArrayFormula) CVC4IntegerFormula(org.sosy_lab.java_smt.solvers.cvc4.CVC4Formula.CVC4IntegerFormula) CVC4FloatingPointRoundingModeFormula(org.sosy_lab.java_smt.solvers.cvc4.CVC4Formula.CVC4FloatingPointRoundingModeFormula) CVC4RationalFormula(org.sosy_lab.java_smt.solvers.cvc4.CVC4Formula.CVC4RationalFormula) CVC4RegexFormula(org.sosy_lab.java_smt.solvers.cvc4.CVC4Formula.CVC4RegexFormula) CVC4BitvectorFormula(org.sosy_lab.java_smt.solvers.cvc4.CVC4Formula.CVC4BitvectorFormula) Formula(org.sosy_lab.java_smt.api.Formula) CVC4ArrayFormula(org.sosy_lab.java_smt.solvers.cvc4.CVC4Formula.CVC4ArrayFormula) FloatingPointType(org.sosy_lab.java_smt.api.FormulaType.FloatingPointType) CVC4.vectorType(edu.stanford.CVC4.vectorType) Type(edu.stanford.CVC4.Type) BitVectorType(edu.stanford.CVC4.BitVectorType) FormulaType(org.sosy_lab.java_smt.api.FormulaType) ArrayFormulaType(org.sosy_lab.java_smt.api.FormulaType.ArrayFormulaType) ArrayType(edu.stanford.CVC4.ArrayType) FunctionType(edu.stanford.CVC4.FunctionType) CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) Expr(edu.stanford.CVC4.Expr) Quantifier(org.sosy_lab.java_smt.api.QuantifiedFormulaManager.Quantifier) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) CVC4BooleanFormula(org.sosy_lab.java_smt.solvers.cvc4.CVC4Formula.CVC4BooleanFormula)

Aggregations

ArrayList (java.util.ArrayList)2 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayType (edu.stanford.CVC4.ArrayType)1 BitVectorType (edu.stanford.CVC4.BitVectorType)1 Expr (edu.stanford.CVC4.Expr)1 FunctionType (edu.stanford.CVC4.FunctionType)1 Type (edu.stanford.CVC4.Type)1 CVC4.vectorExpr (edu.stanford.CVC4.vectorExpr)1 CVC4.vectorType (edu.stanford.CVC4.vectorType)1 List (java.util.List)1 JAXBElement (javax.xml.bind.JAXBElement)1 BinaryComparisonOpType (net.opengis.filter.v_1_1_0.BinaryComparisonOpType)1 FilterType (net.opengis.filter.v_1_1_0.FilterType)1 FunctionType (net.opengis.filter.v_1_1_0.FunctionType)1 BinaryComparisonOpType (org.geosdi.geoplatform.xml.filter.v110.BinaryComparisonOpType)1 FunctionType (org.geosdi.geoplatform.xml.filter.v110.FunctionType)1 LiteralType (org.geosdi.geoplatform.xml.filter.v110.LiteralType)1 PropertyNameType (org.geosdi.geoplatform.xml.filter.v110.PropertyNameType)1 FunctionType (org.geotoolkit.ogc.xml.v200.FunctionType)1 Expression (org.opengis.filter.Expression)1