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()); } }
public void WhereNotEqual(SparqlVariable v, ConstantExpression c) { if (c.Value == null) { PatternBuilder.Filter(e => e.Bound(v.Name)); } else if (c.Type.IsValueType || c.Type == typeof(string)) { PatternBuilder.Filter(e => e.Variable(v.Name) != c.AsLiteralExpression()); } else { PatternBuilder.Filter(e => e.Variable(v.Name) != c.AsIriExpression()); } }
public void WhereResourceNotOfType(SparqlVariable s, Type type) { RdfClassAttribute t = type.TryGetCustomAttribute <RdfClassAttribute>(); if (t != null) { Uri a = new Uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); SparqlVariable o = VariableGenerator.CreateObjectVariable(); ConstantExpression c = Expression.Constant(t.MappedUri); PatternBuilder.Where(e => e.Subject(s).PredicateUri(a).Object(o)); PatternBuilder.Filter(e => e.Variable(o.Name) != c.AsIriExpression() || !e.Bound(o.Name)); } }