Esempio n. 1
0
def evaluate_Predicate(context, query):
    # We evaluate the left-hand side
    left_value = context.evaluate(query.left)
    # Then we go through the list of items in the resulting left-hand
    # collection. For each item, we evaluate the predicate with the specified
    # item as the context item. If the result of evaluating the predicate is
    # a true collection (a collection with at least one true value), then we
    # include the item in the list of values to return. 
    return [v for v in left_value if is_true_collection(context.new_with_item(v).evaluate(query.right))]
Esempio n. 2
0
def flwor_FlworWhere(context, query, var_stream):
    # This one's even easier. We get the expression to evaluat to check
    # whether or not we want to allow each varset through
    expr = query.expr
    # Then we iterate over the varsets
    for varset in var_stream:
        # For each one, we evaluate the expression to see if we should let
        # this varset on to further processing stages
        expr_value = context.new_with_vars(varset).evaluate(expr)
        # Then we check to see if the result was a true value
        if is_true_collection(expr_value):
            # It was, so we yield this varset.
            yield varset
Esempio n. 3
0
def evaluate_Satisfies(context, query):
    name = query.name
    expr_value = context.evaluate(query.expr)
    some = query.type == "some"
    for item in expr_value:
        result = context.new_with_var(name, [item]).evaluate(query.condition)
        truth = is_true_collection(result)
        if some: # Checking for at least one to be true
            if truth:
                return [Boolean(True)]
        else: # Checking for all to be true, so if one's false, we just quit
            if not truth:
                return [Boolean(False)]
    if some: # Checking for some, but none of them were true
        return [Boolean(False)]
    else: # Checking for all, and none of them were false so we return true
        return [Boolean(True)]
Esempio n. 4
0
def evaluate_IfThenElse(context, query):
    condition_value = context.evaluate(query.condition)
    if is_true_collection(condition_value):
        return context.evaluate(query.true)
    else:
        return context.evaluate(query.false)
Esempio n. 5
0
def evaluate_Or(context, query):
    left_value = context.evaluate(query.left)
    if not is_true_collection(left_value):
        return [Boolean(is_true_collection(context.evaluate(query.right)))]
    else:
        return [Boolean(True)]