/// <summary> /// Left Joins the Multiset to another Multiset /// </summary> /// <param name="other">Other Multiset</param> /// <param name="expr">Expression which the Join is predicated on</param> /// <returns>The other Multiset</returns> public override BaseMultiset LeftJoin(BaseMultiset other, ISparqlExpression expr) { //If Other is Null/Empty then the Join still results in Identity if (other is NullMultiset) return this; if (other.IsEmpty) return this; return other; }
/// <summary> /// Creates a new 2D Cartesian Function /// </summary> /// <param name="x1">Expression for X Coordinate of 1st point</param> /// <param name="y1">Expression for Y Coordinate of 1st point</param> /// <param name="x2">Expression for X Coordinate of 2nd point</param> /// <param name="y2">Expression for Y Coordinate of 2nd point</param> public CartesianFunction(ISparqlExpression x1, ISparqlExpression y1, ISparqlExpression x2, ISparqlExpression y2) { this._x1 = x1; this._y1 = y1; this._x2 = x2; this._y2 = y2; }
/// <summary> /// Create a transform that replaces one variable with another /// </summary> /// <param name="findVar">Find Variable</param> /// <param name="replaceVar">Replace Variable</param> public VariableSubstitutionTransformer(String findVar, String replaceVar) { this._findVar = findVar; this._replaceItem = new VariablePattern("?" + replaceVar); this._replaceExpr = new VariableTerm(replaceVar); this._replaceToken = new VariableToken("?" + replaceVar, 0, 0, 0); this._canReplaceObjects = false; }
/// <summary> /// Creates a new XPath Binary String function /// </summary> /// <param name="stringExpr">Expression</param> /// <param name="argExpr">Argument</param> /// <param name="allowNullArgument">Whether the argument may be null</param> /// <param name="argumentTypeValidator">Type validator for the argument</param> public BaseBinaryStringFunction(ISparqlExpression stringExpr, ISparqlExpression argExpr, bool allowNullArgument, Func<Uri, bool> argumentTypeValidator) { this._expr = stringExpr; this._arg = argExpr; this._allowNullArgument = allowNullArgument; if (this._arg == null && !this._allowNullArgument) throw new RdfParseException("Cannot create a XPath String Function which takes a String and a single argument since the expression for the argument is null"); this._argumentTypeValidator = argumentTypeValidator; }
/// <summary> /// Creates a new 3D Cartesian Function /// </summary> /// <param name="x1">Expression for X Coordinate of 1st point</param> /// <param name="y1">Expression for Y Coordinate of 1st point</param> /// <param name="z1">Expression for Z Coordiante of 1st point</param> /// <param name="x2">Expression for X Coordinate of 2nd point</param> /// <param name="y2">Expression for Y Coordinate of 2nd point</param> /// <param name="z2">Expression for Z Coordinate of 2nd point</param> public LeviathanCartesianFunction(ISparqlExpression x1, ISparqlExpression y1, ISparqlExpression z1, ISparqlExpression x2, ISparqlExpression y2, ISparqlExpression z2) { this._x1 = x1; this._y1 = y1; this._z1 = z1; this._x2 = x2; this._y2 = y2; this._z2 = z2; this._3d = true; }
/// <summary> /// Transforms an expression into a form where primary expressions may be substituted /// </summary> /// <param name="expr">Expression</param> /// <returns></returns> public ISparqlExpression Transform(ISparqlExpression expr) { if (expr.Type == SparqlExpressionType.Primary) { return this.SubstitutePrimaryExpression(expr); } else { return expr.Transform(this); } }
/// <summary> /// Creates a new Extend operator /// </summary> /// <param name="pattern">Pattern</param> /// <param name="expr">Expression</param> /// <param name="var">Variable to bind to</param> public Extend(ISparqlAlgebra pattern, ISparqlExpression expr, String var) { this._inner = pattern; this._expr = expr; this._var = var; if (this._inner.Variables.Contains(this._var)) { throw new RdfQueryException("Cannot create an Extend() operator which extends the results of the inner algebra with a variable that is already used in the inner algebra"); } }
public bool TryCreateExpression(Uri u, List<ISparqlExpression> args, Dictionary<string, ISparqlExpression> scalarArguments, out ISparqlExpression expr) { //TODO: Add support for FullTextMatchFunction and FullTextSearchFunction //switch (u.ToString()) //{ //} expr = null; return false; }
/// <summary> /// Creates a new MAX Aggregate /// </summary> /// <param name="distinct">Distinct Modifier</param> /// <param name="expr">Expression</param> public MaxAggregate(ISparqlExpression distinct, ISparqlExpression expr) : base(expr) { if (distinct is DistinctModifier) { this._distinct = true; } else { throw new RdfQueryException("The first argument to the MaxAggregate constructor must be of type DistinctModifierExpression"); } }
/// <summary> /// Creates a new SPARQL Replace function /// </summary> /// <param name="text">Text Expression</param> /// <param name="find">Search Expression</param> /// <param name="replace">Replace Expression</param> /// <param name="options">Options Expression</param> public ReplaceFunction(ISparqlExpression text, ISparqlExpression find, ISparqlExpression replace, ISparqlExpression options) { this._textExpr = text; //Get the Pattern if (find is ConstantTerm) { //If the Pattern is a Node Expression Term then it is a fixed Pattern IValuedNode n = find.Evaluate(null, 0); if (n.NodeType == NodeType.Literal) { //Try to parse as a Regular Expression try { string p = n.AsString(); Regex temp = new Regex(p); //It's a Valid Pattern this._fixedPattern = true; this._find = p; } catch { //No catch actions } } } this._findExpr = find; //Get the Replace if (replace is ConstantTerm) { //If the Replace is a Node Expresison Term then it is a fixed Pattern IValuedNode n = replace.Evaluate(null, 0); if (n.NodeType == NodeType.Literal) { this._replace = n.AsString(); this._fixedReplace = true; } } this._replaceExpr = replace; //Get the Options if (options != null) { if (options is ConstantTerm) { this.ConfigureOptions(options.Evaluate(null, 0), false); } this._optionExpr = options; } }
/// <summary> /// Creates a new Leviathan Tangent Function /// </summary> /// <param name="expr">Expression</param> /// <param name="inverse">Whether this should be the inverse function</param> public TangentFunction(ISparqlExpression expr, bool inverse) : base(expr) { this._inverse = inverse; if (this._inverse) { this._func = Math.Atan; } else { this._func = Math.Tan; } }
/// <summary> /// Creates a new Leviathan Cotangent Function /// </summary> /// <param name="expr">Expression</param> /// <param name="inverse">Whether this should be the inverse function</param> public CotangentFunction(ISparqlExpression expr, bool inverse) : base(expr) { this._inverse = inverse; if (this._inverse) { this._func = _arccotangent; } else { this._func = _cotangent; } }
/// <summary> /// Creates a new Leviathan Secant Function /// </summary> /// <param name="expr">Expression</param> /// <param name="inverse">Whether this should be the inverse function</param> public SecantFunction(ISparqlExpression expr, bool inverse) : base(expr) { this._inverse = inverse; if (this._inverse) { this._func = _arcsecant; } else { this._func = _secant; } }
/// <summary> /// Creates a new Leviathan Sine Function /// </summary> /// <param name="expr">Expression</param> /// <param name="inverse">Whether this should be the inverse function</param> public SineFunction(ISparqlExpression expr, bool inverse) : base(expr) { this._inverse = inverse; if (this._inverse) { this._func = Math.Asin; } else { this._func = Math.Sin; } }
public bool TryCreateExpression(Uri u, List<ISparqlExpression> args, Dictionary<string, ISparqlExpression> scalarArguments, out ISparqlExpression expr) { // If any scalar arguments are present, it can't be a BrightstarDB function if (scalarArguments.Count > 0) { expr = null; return false; } var func = u.ToString(); if (func.StartsWith(BrightstarFunctionsNamespace)) { func = func.Substring(BrightstarFunctionsNamespace.Length); ISparqlExpression brightstarFunc = null; switch (func) { case BitAnd: if (args.Count == 2) { brightstarFunc = new BitAndFunc(args[0], args[1]); } else { throw new RdfParseException("Incorrect number of arguments for the BrightstarDB bit_and() function."); } break; case BitOr: if (args.Count == 2) { brightstarFunc = new BitOrFunc(args[0], args[1]); } else { throw new RdfParseException("Incorrect number of arguments for the BrightstarDB bit_and() function."); } break; } if (brightstarFunc != null) { expr = brightstarFunc; return true; } } expr = null; return false; }
/// <summary> /// Creates a new Regex() function expression /// </summary> /// <param name="text">Text to apply the Regular Expression to</param> /// <param name="pattern">Regular Expression Pattern</param> /// <param name="options">Regular Expression Options</param> public RegexFunction(ISparqlExpression text, ISparqlExpression pattern, ISparqlExpression options) { this._textExpr = text; this._patternExpr = pattern; //Get the Pattern if (pattern is ConstantTerm) { //If the Pattern is a Node Expression Term then it is a fixed Pattern INode n = pattern.Evaluate(null, 0); if (n.NodeType == NodeType.Literal) { //Try to parse as a Regular Expression try { string p = ((ILiteralNode)n).Value; Regex temp = new Regex(p); //It's a Valid Pattern this._fixedPattern = true; //this._useInStr = p.ToCharArray().All(c => Char.IsLetterOrDigit(c) || Char.IsWhiteSpace(c)); this._pattern = p; } catch { //No catch actions } } } //Get the Options if (options != null) { this._optionExpr = options; if (options is ConstantTerm) { this.ConfigureOptions(options.Evaluate(null, 0), false); this._fixedOptions = true; if (this._fixedPattern) this._regex = new Regex(this._pattern, this._options); } } else { if (this._fixedPattern) this._regex = new Regex(this._pattern); } }
/// <summary> /// Creates a new ARQ String Join function /// </summary> /// <param name="sepExpr">Separator Expression</param> /// <param name="expressions">Expressions to concatentate</param> public StringJoinFunction(ISparqlExpression sepExpr, IEnumerable<ISparqlExpression> expressions) { if (sepExpr is ConstantTerm) { IValuedNode temp = sepExpr.Evaluate(null, 0); if (temp.NodeType == NodeType.Literal) { this._separator = temp.AsString(); this._fixedSeparator = true; } else { this._sep = sepExpr; } } else { this._sep = sepExpr; } this._exprs.AddRange(expressions); }
/// <summary> /// Creates a new Lang() function expression /// </summary> /// <param name="expr">Expression to apply the function to</param> public LangFunction(ISparqlExpression expr) : base(expr) { }
/// <summary> /// Creates a new XPath Substring After function /// </summary> /// <param name="stringExpr">Expression</param> /// <param name="findExpr">Search Expression</param> public SubstringAfterFunction(ISparqlExpression stringExpr, ISparqlExpression findExpr) : base(stringExpr, findExpr, false, XPathFunctionFactory.AcceptStringArguments) { }
/// <summary> /// Creates a new XPath Normalize Unicode function /// </summary> /// <param name="stringExpr">Expression</param> /// <param name="normalizationFormExpr">Normalization Form</param> public NormalizeUnicodeFunction(ISparqlExpression stringExpr, ISparqlExpression normalizationFormExpr) : base(stringExpr, normalizationFormExpr, true, XPathFunctionFactory.AcceptStringArguments) { }
/// <summary> /// Creates a new Equality Expression /// </summary> /// <param name="leftExpr">Left Hand Expression</param> /// <param name="rightExpr">Right Hand Expression</param> public EqualsExpression(ISparqlExpression leftExpr, ISparqlExpression rightExpr) : base(leftExpr, rightExpr) { }
/// <summary> /// Creates a new MEDIAN Aggregate. /// </summary> /// <param name="expr">Expression.</param> public MedianAggregate(ISparqlExpression expr) : this(expr, false) { }
/// <summary> /// Wraps the <paramref name="expression"/> as an RDF term expression /// </summary> public RdfTermExpression(ISparqlExpression expression) : base(expression) { }
/// <summary> /// Creates a new All Aggregate /// </summary> /// <param name="expr">Expression</param> public AllAggregate(ISparqlExpression expr) : this(expr, false) { }
/// <summary> /// Creates a new SPARQL CEIL() Function. /// </summary> /// <param name="expr">Argument Expression.</param> public CeilFunction(ISparqlExpression expr) : base(expr) { }
/// <summary> /// Creates a new XPath Lower Case function /// </summary> /// <param name="stringExpr">Expression</param> public LowerCaseFunction(ISparqlExpression stringExpr) : base(stringExpr) { }
/// <summary> /// Creates a new SPARQL HOURS() Function. /// </summary> /// <param name="expr">Argument Expression.</param> public HoursFunction(ISparqlExpression expr) : base(expr) { }
/// <summary> /// Creates a new Str() function expression. /// </summary> /// <param name="expr">Expression to apply the function to.</param> public StrFunction(ISparqlExpression expr) : base(expr) { }
/// <summary> /// Creates a new Leviathan Random Function /// </summary> /// <param name="min">Minumum</param> /// <param name="max">Maximum</param> public RandomFunction(ISparqlExpression min, ISparqlExpression max) : base(min, max) { _args = 2; }
/// <summary> /// Creates a new Leviathan Random Function /// </summary> /// <param name="max">Maximum</param> public RandomFunction(ISparqlExpression max) : base(new ConstantTerm(new DoubleNode(null, 0)), max) { _args = 1; }
/// <summary> /// Tries to create an XPath Function expression if the function Uri correseponds to a supported XPath Function /// </summary> /// <param name="u">Function Uri</param> /// <param name="args">Function Arguments</param> /// <param name="scalarArgs">Scalar Arguments</param> /// <param name="expr">Generated Expression</param> /// <returns>Whether an expression was successfully generated</returns> public bool TryCreateExpression(Uri u, List<ISparqlExpression> args, Dictionary<String,ISparqlExpression> scalarArgs, out ISparqlExpression expr) { //If any Scalar Arguments are present then can't possibly be an XPath Function if (scalarArgs.Count > 0) { expr = null; return false; } String func = u.ToString(); if (func.StartsWith(XPathFunctionFactory.XPathFunctionsNamespace)) { func = func.Substring(XPathFunctionFactory.XPathFunctionsNamespace.Length); ISparqlExpression xpathFunc = null; switch (func) { case XPathFunctionFactory.Absolute: if (args.Count == 1) { xpathFunc = new XPathAbsoluteFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath abs() function"); } break; case XPathFunctionFactory.AdjustDateTimeToTimezone: throw new NotSupportedException("XPath adjust-dateTime-to-timezone() function is not supported"); case XPathFunctionFactory.Boolean: if (args.Count == 1) { xpathFunc = new XPathBooleanFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath boolean() function"); } throw new NotSupportedException("XPath boolean() function is not supported"); case XPathFunctionFactory.Ceiling: if (args.Count == 1) { xpathFunc = new XPathCeilingFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath ceiling() function"); } break; case XPathFunctionFactory.Compare: if (args.Count == 2) { xpathFunc = new XPathCompareFunction(args.First(), args.Last()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath compare() function"); } break; case XPathFunctionFactory.Concat: if (args.Count == 2) { xpathFunc = new XPathConcatFunction(args.First(), args.Last()); } else if (args.Count > 2) { xpathFunc = new XPathConcatFunction(args); } else { throw new RdfParseException("Incorrect number of arguments for the XPath concat() function"); } break; case XPathFunctionFactory.Contains: if (args.Count == 2) { xpathFunc = new XPathContainsFunction(args.First(), args.Last()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath contains() function"); } break; case XPathFunctionFactory.DayFromDateTime: if (args.Count == 1) { xpathFunc = new XPathDayFromDateTimeFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath day-from-dateTime() function"); } break; case XPathFunctionFactory.EncodeForURI: if (args.Count == 1) { xpathFunc = new XPathEncodeForUriFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath encode-for-uri() function"); } break; case XPathFunctionFactory.EndsWith: if (args.Count == 2) { xpathFunc = new XPathEndsWithFunction(args.First(), args.Last()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath ends-with() function"); } break; #if !NO_WEB case XPathFunctionFactory.EscapeHtmlURI: if (args.Count == 1) { xpathFunc = new XPathEscapeHtmlUriFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath escape-html-uri() function"); } break; #endif case XPathFunctionFactory.False: if (args.Count == 0) { xpathFunc = new BooleanExpressionTerm(false); } else { throw new RdfParseException("Incorrect number of arguments for the XPath false() function"); } break; case XPathFunctionFactory.Floor: if (args.Count == 1) { xpathFunc = new XPathFloorFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath floor() function"); } break; case XPathFunctionFactory.HoursFromDateTime: if (args.Count == 1) { xpathFunc = new XPathHoursFromDateTimeFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath hours-from-dateTime() function"); } break; case XPathFunctionFactory.LowerCase: if (args.Count == 1) { xpathFunc = new XPathLowerCaseFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath lower-case() function"); } break; case XPathFunctionFactory.Matches: if (args.Count == 2) { xpathFunc = new RegexFunction(args.First(), args.Last()); } else if (args.Count == 3) { xpathFunc = new RegexFunction(args.First(), args[1], args.Last()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath matches() function"); } break; case XPathFunctionFactory.MinutesFromDateTime: if (args.Count == 1) { xpathFunc = new XPathMinutesFromDateTimeFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath minutes-from-dateTime() function"); } break; case XPathFunctionFactory.MonthFromDateTime: if (args.Count == 1) { xpathFunc = new XPathMonthFromDateTimeFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath month-from-dateTime() function"); } break; case XPathFunctionFactory.NormalizeSpace: if (args.Count == 1) { xpathFunc = new XPathNormalizeSpaceFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath normalize-space() function"); } break; #if !NO_NORM case XPathFunctionFactory.NormalizeUnicode: if (args.Count == 1) { xpathFunc = new XPathNormalizeUnicodeFunction(args.First()); } else if (args.Count == 2) { xpathFunc = new XPathNormalizeUnicodeFunction(args.First(), args.Last()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath normalize-space() function"); } break; #endif case XPathFunctionFactory.Not: if (args.Count == 1) { xpathFunc = new NegationExpression(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath not() function"); } break; case XPathFunctionFactory.Replace: if (args.Count == 3) { xpathFunc = new XPathReplaceFunction(args.First(), args[1], args.Last()); } else if (args.Count == 4) { xpathFunc = new XPathReplaceFunction(args.First(), args[1], args[2], args.Last()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath replace() function"); } break; case XPathFunctionFactory.Round: if (args.Count == 1) { xpathFunc = new XPathRoundFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath round() function"); } break; #if !SILVERLIGHT case XPathFunctionFactory.RoundHalfToEven: if (args.Count == 1) { xpathFunc = new XPathRoundHalfToEvenFunction(args.First()); } else if (args.Count == 2) { xpathFunc = new XPathRoundHalfToEvenFunction(args.First(), args.Last()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath round-half-to-even() function"); } break; #endif case XPathFunctionFactory.SecondsFromDateTime: if (args.Count == 1) { xpathFunc = new XPathSecondsFromDateTimeFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath seconds-from-dateTime() function"); } break; case XPathFunctionFactory.StartsWith: if (args.Count == 2) { xpathFunc = new XPathStartsWithFunction(args.First(), args.Last()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath starts-with() function"); } break; case XPathFunctionFactory.StringJoin: if (args.Count == 1) { xpathFunc = new NonNumericAggregateExpressionTerm(new XPathStringJoinFunction(args.First())); } else if (args.Count == 2) { xpathFunc = new NonNumericAggregateExpressionTerm(new XPathStringJoinFunction(args.First(), args.Last())); } else { throw new RdfParseException("Incorrect number of arguments for the XPath string-join() function"); } break; case XPathFunctionFactory.StringLength: if (args.Count == 1) { xpathFunc = new XPathStringLengthFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath string-length() function"); } break; case XPathFunctionFactory.Substring: if (args.Count == 2) { xpathFunc = new XPathSubstringFunction(args.First(), args.Last()); } else if (args.Count == 3) { xpathFunc = new XPathSubstringFunction(args.First(), args[1], args.Last()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath substring() function"); } break; case XPathFunctionFactory.SubstringAfter: if (args.Count == 2) { xpathFunc = new XPathSubstringAfterFunction(args.First(), args.Last()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath substring-after() function"); } break; case XPathFunctionFactory.SubstringBefore: if (args.Count == 2) { xpathFunc = new XPathSubstringBeforeFunction(args.First(), args.Last()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath substring-before() function"); } break; case XPathFunctionFactory.TimezoneFromDateTime: if (args.Count == 1) { xpathFunc = new XPathTimezoneFromDateTimeFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath timezone-from-dateTime() function"); } break; case XPathFunctionFactory.Translate: throw new NotSupportedException("XPath translate() function is not supported"); case XPathFunctionFactory.True: if (args.Count == 0) { xpathFunc = new BooleanExpressionTerm(true); } else { throw new RdfParseException("Incorrect number of arguments for the XPath true() function"); } break; case XPathFunctionFactory.UpperCase: if (args.Count == 1) { xpathFunc = new XPathUpperCaseFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath upper-case() function"); } break; case XPathFunctionFactory.YearFromDateTime: if (args.Count == 1) { xpathFunc = new XPathYearFromDateTimeFunction(args.First()); } else { throw new RdfParseException("Incorrect number of arguments for the XPath year-from-dateTime() function"); } break; } if (xpathFunc != null) { expr = xpathFunc; return true; } } expr = null; return false; }
private void EvalLeftJoin(ISet x, BaseMultiset other, List <String> joinVars, List <MultiDictionary <INode, List <int> > > values, List <List <int> > nulls, BaseMultiset joinedSet, SparqlEvaluationContext subcontext, ISparqlExpression expr) { IEnumerable <int> possMatches = null; int i = 0; foreach (String var in joinVars) { INode value = x[var]; if (value != null) { if (values[i].ContainsKey(value)) { possMatches = (possMatches == null ? values[i][value].Concat(nulls[i]) : possMatches.Intersect(values[i][value].Concat(nulls[i]))); } else { possMatches = Enumerable.Empty <int>(); break; } } else { //Don't forget that a null will be potentially compatible with everything possMatches = (possMatches == null ? this.SetIDs : possMatches.Intersect(this.SetIDs)); } i++; } //If no possible matches just copy LHS across if (possMatches == null) { joinedSet.Add(x.Copy()); return; } //Now do the actual joins for the current set bool standalone = false; bool matched = false; foreach (int poss in possMatches) { if (other[poss].IsCompatibleWith(x, joinVars)) { ISet z = x.Join(other[poss]); joinedSet.Add(z); try { if (!expr.Evaluate(subcontext, z.ID).AsSafeBoolean()) { joinedSet.Remove(z.ID); } else { matched = true; } } catch { joinedSet.Remove(z.ID); standalone = true; } } } if (standalone || !matched) { joinedSet.Add(x.Copy()); } }
/// <summary> /// Creates a new SPARQL ROUND() Function /// </summary> /// <param name="expr">Argument Expression</param> public RoundFunction(ISparqlExpression expr) : base(expr) { }
/// <summary> /// Creates a new MEDIAN Aggregate. /// </summary> /// <param name="expr">Expression.</param> /// <param name="distinct">Whether a DISTINCT modifer applies.</param> public MedianAggregate(ISparqlExpression expr, bool distinct) : base(expr, distinct) { }
/// <summary> /// Creates a new Leviathan Cotangent Function /// </summary> /// <param name="expr">Expression</param> public CotangentFunction(ISparqlExpression expr) : base(expr, _cotangent) { }
/// <summary> /// Does a Left Join of this Multiset to another Multiset where the Join is predicated on the given Expression /// </summary> /// <param name="other">Other Multiset</param> /// <param name="expr">Expression</param> /// <returns></returns> public virtual BaseMultiset LeftJoin(BaseMultiset other, ISparqlExpression expr) { //If the Other is the Identity/Null Multiset the result is this Multiset if (other is IdentityMultiset) { return(this); } if (other is NullMultiset) { return(this); } if (other.IsEmpty) { return(this); } Multiset joinedSet = new Multiset(); LeviathanLeftJoinBinder binder = new LeviathanLeftJoinBinder(joinedSet); SparqlEvaluationContext subcontext = new SparqlEvaluationContext(binder); //Find the First Variable from this Multiset which is in both Multisets //If there is no Variable from this Multiset in the other Multiset then this //should be a Join operation instead of a LeftJoin List <String> joinVars = this.Variables.Where(v => other.Variables.Contains(v)).ToList(); if (joinVars.Count == 0) { #if NET40 && !SILVERLIGHT if (Options.UsePLinqEvaluation && expr.CanParallelise) { PartitionedMultiset partitionedSet = new PartitionedMultiset(this.Count, other.Count + 1); this.Sets.AsParallel().ForAll(x => EvalLeftJoinProduct(x, other, partitionedSet, expr)); return(partitionedSet); } #endif //Do a serial Left Join Product //Calculate a Product filtering as we go foreach (ISet x in this.Sets) { bool standalone = false; bool matched = false; foreach (ISet y in other.Sets) { ISet z = x.Join(y); try { joinedSet.Add(z); if (!expr.Evaluate(subcontext, z.ID).AsSafeBoolean()) { joinedSet.Remove(z.ID); standalone = true; } else { matched = true; } } catch { joinedSet.Remove(z.ID); standalone = true; } } if (standalone && !matched) { joinedSet.Add(x.Copy()); } } #if NET40 && !SILVERLIGHT #endif } else { //This is the new Join algorithm which is also correct but is O(2n) so much faster and scalable //Downside is that it does require more memory than the old algorithm List <MultiDictionary <INode, List <int> > > values = new List <MultiDictionary <INode, List <int> > >(); List <List <int> > nulls = new List <List <int> >(); foreach (String var in joinVars) { joinedSet.AddVariable(var); values.Add(new MultiDictionary <INode, List <int> >(new FastVirtualNodeComparer())); nulls.Add(new List <int>()); } //First do a pass over the RHS Result to find all possible values for joined variables foreach (ISet y in other.Sets) { int i = 0; foreach (String var in joinVars) { INode value = y[var]; if (value != null) { List <int> ids; if (values[i].TryGetValue(value, out ids)) { ids.Add(y.ID); } else { values[i].Add(value, new List <int> { y.ID }); } } else { nulls[i].Add(y.ID); } i++; } } //Then do a pass over the LHS and work out the intersections #if NET40 && !SILVERLIGHT if (Options.UsePLinqEvaluation && expr.CanParallelise) { this.Sets.AsParallel().ForAll(x => EvalLeftJoin(x, other, joinVars, values, nulls, joinedSet, subcontext, expr)); } else { #endif //Use a Serial Left Join foreach (ISet x in this.Sets) { this.EvalLeftJoin(x, other, joinVars, values, nulls, joinedSet, subcontext, expr); } #if NET40 && !SILVERLIGHT } #endif } return(joinedSet); }
/// <summary> /// Creates a new Leviathan Pythagorean Distance Function. /// </summary> /// <param name="arg1">First Argument.</param> /// <param name="arg2">Second Argument.</param> public PythagoreanDistanceFunction(ISparqlExpression arg1, ISparqlExpression arg2) : base(arg1, arg2) { }
/// <summary> /// Does a Left Join of this Multiset to another Multiset where the Join is predicated on the given Expression /// </summary> /// <param name="other">Other Multiset</param> /// <param name="expr">Expression</param> /// <returns></returns> public override BaseMultiset LeftJoin(BaseMultiset other, ISparqlExpression expr) { //If the Other is the Identity/Null Multiset the result is this Multiset if (other is IdentityMultiset) { return(this); } if (other is NullMultiset) { return(this); } if (other.IsEmpty) { return(this); } Multiset joinedSet = new Multiset(); LeviathanLeftJoinBinder binder = new LeviathanLeftJoinBinder(joinedSet); SparqlEvaluationContext subcontext = new SparqlEvaluationContext(binder); //Find the First Variable from this Multiset which is in both Multisets //If there is no Variable from this Multiset in the other Multiset then this //should be a Join operation instead of a LeftJoin List <String> joinVars = this._variables.Where(v => other.Variables.Contains(v)).ToList(); if (joinVars.Count == 0) { //Calculate a Product filtering as we go foreach (ISet x in this.Sets) { bool standalone = false; foreach (ISet y in other.Sets) { ISet z = x.Join(y); try { joinedSet.Add(z); if (!expr.EffectiveBooleanValue(subcontext, z.ID)) { joinedSet.Remove(z.ID); standalone = true; } } catch { joinedSet.Remove(z.ID); standalone = true; } } if (standalone) { joinedSet.Add(x); } } } else { foreach (ISet x in this.Sets) { IEnumerable <ISet> ys = other.Sets.Where(s => joinVars.All(v => x[v] == null || s[v] == null || x[v].Equals(s[v]))); //IEnumerable<ISet> ys = other.Sets.Where(s => s.IsCompatibleWith(x, joinVars)); bool standalone = false; int i = 0; foreach (ISet y in ys) { i++; ISet z = x.Join(y); try { joinedSet.Add(z); if (!expr.EffectiveBooleanValue(subcontext, z.ID)) { joinedSet.Remove(z.ID); standalone = true; } } catch { joinedSet.Remove(z.ID); standalone = true; } } if (standalone || i == 0) { joinedSet.Add(x); } } } return(joinedSet); }
internal IfElsePart(ISparqlExpression ifExpression, ISparqlExpression thenExpression) { _ifExpression = ifExpression; _thenExpression = thenExpression; }
/// <summary> /// Creates a new AVG Aggregate /// </summary> /// <param name="expr">Expression</param> /// <param name="distinct">Whether a DISTINCT modifier applies</param> public AverageAggregate(ISparqlExpression expr, bool distinct) : base(expr, distinct) { }
internal IfThenPart(ISparqlExpression ifExpression) { _ifExpression = ifExpression; }
/// <summary> /// Creates a new AVG Aggregate /// </summary> /// <param name="expr">Expression</param> public AverageAggregate(ISparqlExpression expr) : this(expr, false) { }
/// <summary> /// Creates a new SPARQL SECONDS() Function. /// </summary> /// <param name="expr">Argument Expression.</param> public SecondsFunction(ISparqlExpression expr) : base(expr) { }
/// <summary> /// Creates a new STRENDS() function /// </summary> /// <param name="stringExpr">String Expression</param> /// <param name="endsExpr">Argument Expression</param> public StrEndsFunction(ISparqlExpression stringExpr, ISparqlExpression endsExpr) : base(stringExpr, endsExpr) { }
/// <summary> /// Creates a new XPath Starts With function /// </summary> /// <param name="stringExpr">Expression</param> /// <param name="prefixExpr">Prefix Expression</param> public StartsWithFunction(ISparqlExpression stringExpr, ISparqlExpression prefixExpr) : base(stringExpr, prefixExpr, false, XPathFunctionFactory.AcceptStringArguments) { }
/// <summary> /// Creates a new ARQ Namespace function /// </summary> /// <param name="expr">Expression</param> public NamespaceFunction(ISparqlExpression expr) : base(expr) { }
/// <summary> /// Left Join combines two multisets where the join is predicated on an arbitrary expression /// </summary> /// <param name="other">Multiset to join with</param> /// <param name="expr">Expression on which the Join is predicated</param> /// <returns></returns> /// <remarks> /// Used for doing OPTIONALs /// </remarks> public abstract BaseMultiset LeftJoin(BaseMultiset other, ISparqlExpression expr);
/// <summary> /// Creates a new SHA256() Function. /// </summary> /// <param name="expr">Argument Expression.</param> public Sha256HashFunction(ISparqlExpression expr) : base(expr) { }
/// <summary> /// Creates a new SPARQL IN function /// </summary> /// <param name="expr">Expression</param> /// <param name="set">Set</param> public InFunction(ISparqlExpression expr, IEnumerable<ISparqlExpression> set) : base(expr, set) { }
/// <summary> /// Creates a new Leviathan Log Function /// </summary> /// <param name="arg">Expression</param> public LogFunction(ISparqlExpression arg) : base(arg, new ConstantTerm(new DoubleNode(null, 10))) { _log10 = true; }
/// <summary> /// Creates a new Order By using the given Expression /// </summary> /// <param name="expr">Expression to order by</param> public OrderByExpression(ISparqlExpression expr) { this._expr = expr; }
/// <summary> /// Creates a new Leviathan Log Function /// </summary> /// <param name="arg">Expression</param> /// <param name="logBase">Log Base Expression</param> public LogFunction(ISparqlExpression arg, ISparqlExpression logBase) : base(arg, logBase) { }
/// <summary> /// Creates a new Regex() function expression /// </summary> /// <param name="text">Text to apply the Regular Expression to</param> /// <param name="pattern">Regular Expression Pattern</param> public RegexFunction(ISparqlExpression text, ISparqlExpression pattern) : this(text, pattern, null) { }
/// <summary> /// Creates a new Lang() function expression. /// </summary> /// <param name="expr">Expression to apply the function to.</param> public LangFunction(ISparqlExpression expr) : base(expr) { }
/// <summary> /// Creates a new Multiplication Expression /// </summary> /// <param name="leftExpr">Left Hand Expression</param> /// <param name="rightExpr">Right Hand Expression</param> public MultiplicationExpression(ISparqlExpression leftExpr, ISparqlExpression rightExpr) : base(leftExpr, rightExpr) { }
/// <summary> /// Creates a new STRAFTER Function. /// </summary> /// <param name="stringExpr">String Expression.</param> /// <param name="startsExpr">Starts Expression.</param> public StrAfterFunction(ISparqlExpression stringExpr, ISparqlExpression startsExpr) { _stringExpr = stringExpr; _startsExpr = startsExpr; }
/// <summary> /// Creates a new All Aggregate /// </summary> /// <param name="expr">Expression</param> /// <param name="distinct">Whether a DISTINCT modifier applies</param> public AllAggregate(ISparqlExpression expr, bool distinct) : base(expr, distinct) { }
private ILiteralNode CheckArgument(ISparqlExpression expr, SparqlEvaluationContext context, int bindingID) { return(CheckArgument(expr, context, bindingID, XPathFunctionFactory.AcceptStringArguments)); }
/// <summary> /// Creates a new XPath Substring After function. /// </summary> /// <param name="stringExpr">Expression.</param> /// <param name="findExpr">Search Expression.</param> public SubstringAfterFunction(ISparqlExpression stringExpr, ISparqlExpression findExpr) : base(stringExpr, findExpr, false, XPathFunctionFactory.AcceptStringArguments) { }
private void EvalLeftJoinProduct(ISet x, BaseMultiset other, PartitionedMultiset partitionedSet, ISparqlExpression expr) { LeviathanLeftJoinBinder binder = new LeviathanLeftJoinBinder(partitionedSet); SparqlEvaluationContext subcontext = new SparqlEvaluationContext(binder); bool standalone = false, matched = false; int id = partitionedSet.GetNextBaseID(); foreach (ISet y in other.Sets) { id++; ISet z = x.Join(y); z.ID = id; try { partitionedSet.Add(z); if (!expr.Evaluate(subcontext, z.ID).AsSafeBoolean()) { partitionedSet.Remove(z.ID); standalone = true; } else { matched = true; } } catch { partitionedSet.Remove(z.ID); standalone = true; } } if (standalone && !matched) { id++; ISet z = x.Copy(); z.ID = id; partitionedSet.Add(z); } }