Search in sources :

Example 1 with AFloat

use of org.apache.asterix.om.base.AFloat in project asterixdb by apache.

the class FuzzyUtils method getSimThreshold.

public static IAObject getSimThreshold(MetadataProvider metadata, String simFuncName) {
    String simThresholValue = metadata.getPropertyValue(SIM_THRESHOLD_PROP_NAME);
    IAObject ret = null;
    if (simFuncName.equals(JACCARD_FUNCTION_NAME)) {
        if (simThresholValue != null) {
            float jaccThresh = Float.parseFloat(simThresholValue);
            ret = new AFloat(jaccThresh);
        } else {
            ret = new AFloat(JACCARD_DEFAULT_SIM_THRESHOLD);
        }
    } else if (simFuncName.equals(EDIT_DISTANCE_FUNCTION_NAME)) {
        if (simThresholValue != null) {
            int edThresh = Integer.parseInt(simThresholValue);
            ret = new AInt32(edThresh);
        } else {
            ret = new AFloat(EDIT_DISTANCE_DEFAULT_SIM_THRESHOLD);
        }
    }
    return ret;
}
Also used : AFloat(org.apache.asterix.om.base.AFloat) IAObject(org.apache.asterix.om.base.IAObject) AInt32(org.apache.asterix.om.base.AInt32)

Example 2 with AFloat

use of org.apache.asterix.om.base.AFloat in project asterixdb by apache.

the class SimilarityCheckRule method getSimilarityCheckExpr.

private ScalarFunctionCallExpression getSimilarityCheckExpr(FunctionIdentifier normFuncIdent, AsterixConstantValue constVal, AbstractFunctionCallExpression funcExpr) throws AlgebricksException {
    // Remember args from original similarity function to add them to the similarity-check function later.
    ArrayList<Mutable<ILogicalExpression>> similarityArgs = null;
    ScalarFunctionCallExpression simCheckFuncExpr = null;
    // Look for jaccard function call, and GE or GT.
    if (funcExpr.getFunctionIdentifier() == BuiltinFunctions.SIMILARITY_JACCARD) {
        IAObject jaccThresh;
        if (normFuncIdent == AlgebricksBuiltinFunctions.GE) {
            if (constVal.getObject() instanceof AFloat) {
                jaccThresh = constVal.getObject();
            } else {
                jaccThresh = new AFloat((float) ((ADouble) constVal.getObject()).getDoubleValue());
            }
        } else if (normFuncIdent == AlgebricksBuiltinFunctions.GT) {
            float threshVal = 0.0f;
            if (constVal.getObject() instanceof AFloat) {
                threshVal = ((AFloat) constVal.getObject()).getFloatValue();
            } else {
                threshVal = (float) ((ADouble) constVal.getObject()).getDoubleValue();
            }
            float f = threshVal + Float.MIN_VALUE;
            if (f > 1.0f)
                f = 1.0f;
            jaccThresh = new AFloat(f);
        } else {
            return null;
        }
        similarityArgs = new ArrayList<Mutable<ILogicalExpression>>();
        similarityArgs.addAll(funcExpr.getArguments());
        similarityArgs.add(new MutableObject<ILogicalExpression>(new ConstantExpression(new AsterixConstantValue(jaccThresh))));
        simCheckFuncExpr = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.SIMILARITY_JACCARD_CHECK), similarityArgs);
    }
    // Look for edit-distance function call, and LE or LT.
    if (funcExpr.getFunctionIdentifier() == BuiltinFunctions.EDIT_DISTANCE) {
        AInt32 aInt = new AInt32(0);
        try {
            aInt = (AInt32) ATypeHierarchy.convertNumericTypeObject(constVal.getObject(), ATypeTag.INTEGER);
        } catch (HyracksDataException e) {
            throw new AlgebricksException(e);
        }
        AInt32 edThresh;
        if (normFuncIdent == AlgebricksBuiltinFunctions.LE) {
            edThresh = aInt;
        } else if (normFuncIdent == AlgebricksBuiltinFunctions.LT) {
            int ed = aInt.getIntegerValue() - 1;
            if (ed < 0)
                ed = 0;
            edThresh = new AInt32(ed);
        } else {
            return null;
        }
        similarityArgs = new ArrayList<Mutable<ILogicalExpression>>();
        similarityArgs.addAll(funcExpr.getArguments());
        similarityArgs.add(new MutableObject<ILogicalExpression>(new ConstantExpression(new AsterixConstantValue(edThresh))));
        simCheckFuncExpr = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.EDIT_DISTANCE_CHECK), similarityArgs);
    }
    // Preserve all annotations.
    if (simCheckFuncExpr != null) {
        simCheckFuncExpr.getAnnotations().putAll(funcExpr.getAnnotations());
    }
    return simCheckFuncExpr;
}
Also used : Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) AFloat(org.apache.asterix.om.base.AFloat) AsterixConstantValue(org.apache.asterix.om.constants.AsterixConstantValue) IAObject(org.apache.asterix.om.base.IAObject) ConstantExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) AInt32(org.apache.asterix.om.base.AInt32) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)

Aggregations

AFloat (org.apache.asterix.om.base.AFloat)2 AInt32 (org.apache.asterix.om.base.AInt32)2 IAObject (org.apache.asterix.om.base.IAObject)2 AsterixConstantValue (org.apache.asterix.om.constants.AsterixConstantValue)1 Mutable (org.apache.commons.lang3.mutable.Mutable)1 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)1 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)1 ConstantExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression)1 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)1 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)1