Example #1
0
        public void WhereLessThanOrEqual(MemberExpression expression, ConstantExpression c)
        {
            SparqlVariable o = BuildMemberAccess(expression);

            if (expression.Member.IsBuiltInCall())
            {
                BuildBuiltInCall(expression, e => e <= c.AsNumericExpression());
            }
            else
            {
                PatternBuilder.Filter(e => e.Variable(o.Name) <= c.AsNumericExpression());
            }
        }
Example #2
0
        public void WhereEqual(MemberExpression expression, ConstantExpression c)
        {
            if (c.Value == null)
            {
                // If we want to filter for non-bound values we need to mark the properties as optional.
                SparqlVariable so = BuildMemberAccessOptional(expression);

                // TODO: If we filter a resource, make sure it has been described with variables in the local scope.

                // Comparing with null means the variable is not bound.
                PatternBuilder.Filter(e => !e.Bound(so.Name));
            }
            else if (c.Type.IsValueType || c.Type == typeof(string))
            {
                if (expression.Member.DeclaringType == typeof(string))
                {
                    BuildMemberAccess(expression);

                    // If we are comparing a property of string we need to implement SPARQL built-in call on the variable such as STRLEN..
                    BuildBuiltInCall(expression, e => e == c.AsNumericExpression());
                }
                else
                {
                    // TODO: The default value for a property may be overridden with the DefaultValue attribute.
                    object defaultValue = TypeHelper.GetDefaultValue(c.Type);

                    // If the value IS the default value, WhereEquals includes the default value and therefore includes non-bound values..
                    if (c.Value.Equals(defaultValue))
                    {
                        // If we want to filter for non-bound values we need to mark the properties as optional.
                        SparqlVariable o = BuildMemberAccessOptional(expression);

                        // Mark the variable to be coalesced with the default value when selected.
                        CoalescedVariables[o] = Expression.Constant(defaultValue).AsLiteralExpression();

                        // Comparing with null means the variable is not bound.
                        PatternBuilder.Filter(e => e.Variable(o.Name) == c.AsLiteralExpression() || !e.Bound(o.Name));
                    }
                    else
                    {
                        // If we want to filter bound literal values, we still write them into a variable so they can be selected.
                        SparqlVariable o = BuildMemberAccess(expression);

                        PatternBuilder.Filter(e => e.Variable(o.Name) == c.AsLiteralExpression());
                    }
                }
            }
            else
            {
                // We are comparing reference types / resources against a bound value here.
                SparqlVariable so = BuildMemberAccess(expression);

                // TODO: If we filter a resource, make sure it has been described with variables in the local scope.

                PatternBuilder.Filter(e => e.Variable(so.Name) == c.AsIriExpression());
            }
        }
Example #3
0
 public void WhereGreaterThan(SparqlVariable v, ConstantExpression c)
 {
     PatternBuilder.Filter(e => e.Variable(v.Name) > c.AsNumericExpression());
 }