public void Remove(string text, int cursor, int removeAt, int removeLength, string expectedText, int expectedCursor) { var merged = new Reduced(new TextOf(text, cursor), removeAt, removeLength); Assert.Equal(expectedText, merged.Text); Assert.Equal(expectedCursor, merged.Cursor); }
/// <summary> /// Processes a Reduced modifier /// </summary> /// <param name="reduced">Reduced modifier</param> /// <param name="context">SPARQL Evaluation Context</param> public virtual BaseMultiset ProcessReduced(Reduced reduced, SparqlEvaluationContext context) { if (context == null) { context = this.GetContext(); } return(reduced.Evaluate(context)); }
public void Dispose() { reductionWorker.RunWorkerCompleted -= reductionWorkerOnCompleted; if (reductionWorker.WorkerSupportsCancellation && reductionWorker.IsBusy) { reductionWorker.CancelAsync(); } Reduced.Clear(); Reduced = null; }
public override string ToString() { return(String.Join(Environment.NewLine, new string[] { "step: " + Step, (Killed?"<KIA>":"") + Stack, Input, NodeId + (isForked()?" %FORK":"") + Shifted + Reduced.Join("") + (Recovered ? " recovering" : "") }.Where(it => it != null))); }
private void reductionWorkerDoWork(object sender, DoWorkEventArgs args) { var worker = sender as BackgroundWorker; var lineSimplify = new DouglasPeuckerLineSimplifier(CoordinateConvertor.LocationCollectionToCoordinates(Original)); for (int i = 21; i > 0; i--) { if (worker != null && worker.CancellationPending) { args.Cancel = true; break; } var simplificationDistance = (1 / (Math.Pow(2, i - 1))); lineSimplify.DistanceTolerance = simplificationDistance; Reduced.Add(i, CoordinateConvertor.CoordinatesToLocationCollection(lineSimplify.Simplify())); } Initalized = true; }
/// <summary> /// Processes a Reduced modifier. /// </summary> /// <param name="reduced">Reduced modifier.</param> /// <param name="context">SPARQL Evaluation Context.</param> public override BaseMultiset ProcessReduced(Reduced reduced, SparqlEvaluationContext context) { return(ExplainAndEvaluate <Reduced>(reduced, context, base.ProcessReduced)); }
/// <summary> /// Optimizes the given algebra. /// </summary> /// <param name="algebra">Algebra.</param> /// <returns>Optimized algebra.</returns> public ISparqlAlgebra Optimise(ISparqlAlgebra algebra) { if (algebra is Distinct) { Distinct distinct = (Distinct)algebra; if (distinct.InnerAlgebra is Select) { Select select = (Select)distinct.InnerAlgebra; if (!select.IsSelectAll) { if (select.InnerAlgebra is OrderBy) { bool ok = true; OrderBy orderBy = (OrderBy)select.InnerAlgebra; List <String> projectVars = select.SparqlVariables.Select(v => v.Name).ToList(); foreach (String var in orderBy.Ordering.Variables) { if (!projectVars.Contains(var)) { ok = false; break; } } if (ok) { // Safe to apply the optimization Select newSelect = new Select(orderBy.InnerAlgebra, false, select.SparqlVariables); Distinct newDistinct = new Distinct(newSelect); return(new OrderBy(newDistinct, orderBy.Ordering)); } } } } // If we reach here than optimization is not applicable return(((Distinct)algebra).Transform(this)); } else if (algebra is Reduced) { Reduced reduced = (Reduced)algebra; if (reduced.InnerAlgebra is Select) { Select select = (Select)reduced.InnerAlgebra; if (!select.IsSelectAll) { if (select.InnerAlgebra is OrderBy) { bool ok = true; OrderBy orderBy = (OrderBy)select.InnerAlgebra; List <String> projectVars = select.SparqlVariables.Select(v => v.Name).ToList(); foreach (String var in orderBy.Ordering.Variables) { if (!projectVars.Contains(var)) { ok = false; break; } } if (ok) { // Safe to apply the optimization Select newSelect = new Select(orderBy.InnerAlgebra, false, select.SparqlVariables); Reduced newReduced = new Reduced(newSelect); return(new OrderBy(newReduced, orderBy.Ordering)); } } } } // If we reach here than optimization is not applicable return(((Reduced)algebra).Transform(this)); } else if (algebra is ITerminalOperator) { return(algebra); } else if (algebra is IUnaryOperator) { return(((IUnaryOperator)algebra).Transform(this)); } else if (algebra is IAbstractJoin) { return(((IAbstractJoin)algebra).Transform(this)); } else { return(algebra); } }
/// <summary> /// Converts the Query into it's SPARQL Algebra representation (as represented in the Leviathan API) /// </summary> /// <returns></returns> public ISparqlAlgebra ToAlgebra() { //Firstly Transform the Root Graph Pattern to SPARQL Algebra ISparqlAlgebra pattern; if (this._rootGraphPattern != null) { if (Options.AlgebraOptimisation) { //If using Algebra Optimisation may use a special algebra in some cases switch (this.SpecialType) { case SparqlSpecialQueryType.DistinctGraphs: pattern = new SelectDistinctGraphs(this.Variables.First(v => v.IsResultVariable).Name); break; case SparqlSpecialQueryType.AskAnyTriples: pattern = new AskAnyTriples(); break; case SparqlSpecialQueryType.NotApplicable: default: //If not just use the standard transform pattern = this._rootGraphPattern.ToAlgebra(); break; } } else { //If not using Algebra Optimisation just use the standard transform pattern = this._rootGraphPattern.ToAlgebra(); } } else { pattern = new Bgp(); } //If we have a BINDINGS clause then we'll add it into the algebra here if (this._bindings != null) { pattern = new Bindings(this._bindings, pattern); } //Then we apply any optimisers followed by relevant solution modifiers switch (this._type) { case SparqlQueryType.Ask: //Apply Algebra Optimisation is enabled if (Options.AlgebraOptimisation) { pattern = this.ApplyAlgebraOptimisations(pattern); } return(new Ask(pattern)); case SparqlQueryType.Construct: case SparqlQueryType.Describe: case SparqlQueryType.DescribeAll: case SparqlQueryType.Select: case SparqlQueryType.SelectAll: case SparqlQueryType.SelectAllDistinct: case SparqlQueryType.SelectAllReduced: case SparqlQueryType.SelectDistinct: case SparqlQueryType.SelectReduced: //Apply Algebra Optimisation if enabled if (Options.AlgebraOptimisation) { pattern = this.ApplyAlgebraOptimisations(pattern); } //GROUP BY is the first thing applied if (this._groupBy != null) { pattern = new GroupBy(pattern, this._groupBy); } //After grouping we do projection //This will generate the values for any Project Expressions and Aggregates pattern = new Project(pattern, this.Variables); //Add HAVING clause after the projection if (this._having != null) { pattern = new Having(pattern, this._having); } //We can then Order our results //We do ordering before we do Select but after Project so we can order by any of //the project expressions/aggregates and any variable in the results even if //it won't be output as a result variable if (this._orderBy != null) { pattern = new OrderBy(pattern, this._orderBy); } //After Ordering we apply Select //Select effectively trims the results so only result variables are left //This doesn't apply to CONSTRUCT since any variable may be used in the Construct Template //so we don't want to eliminate anything if (this._type != SparqlQueryType.Construct) { pattern = new Select(pattern, this.Variables); } //If we have a Distinct/Reduced then we'll apply those after Selection if (this._type == SparqlQueryType.SelectAllDistinct || this._type == SparqlQueryType.SelectDistinct) { pattern = new Distinct(pattern); } else if (this._type == SparqlQueryType.SelectAllReduced || this._type == SparqlQueryType.SelectReduced) { pattern = new Reduced(pattern); } //Finally we can apply any limit and/or offset if (this._limit >= 0 || this._offset > 0) { pattern = new Slice(pattern, this._limit, this._offset); } return(pattern); default: throw new RdfQueryException("Unable to convert unknown Query Types to SPARQL Algebra"); } }
/// <summary> /// Converts the Query into it's SPARQL Algebra representation (as represented in the Leviathan API) /// </summary> /// <returns></returns> public ISparqlAlgebra ToAlgebra() { //Depending on how the query gets built we may not have had graph pattern optimization applied //which we should do here if query optimization is enabled if (!this.IsOptimised && Options.QueryOptimisation) { this.Optimise(); } //Firstly Transform the Root Graph Pattern to SPARQL Algebra ISparqlAlgebra algebra; if (this._rootGraphPattern != null) { if (Options.AlgebraOptimisation) { //If using Algebra Optimisation may use a special algebra in some cases switch (this.SpecialType) { case SparqlSpecialQueryType.DistinctGraphs: algebra = new SelectDistinctGraphs(this.Variables.First(v => v.IsResultVariable).Name); break; case SparqlSpecialQueryType.AskAnyTriples: algebra = new AskAnyTriples(); break; case SparqlSpecialQueryType.NotApplicable: default: //If not just use the standard transform algebra = this._rootGraphPattern.ToAlgebra(); break; } } else { //If not using Algebra Optimisation just use the standard transform algebra = this._rootGraphPattern.ToAlgebra(); } } else { //No root graph pattern means empty BGP algebra = new Bgp(); } //If we have a top level VALUES clause then we'll add it into the algebra here if (this._bindings != null) { algebra = Join.CreateJoin(algebra, new Bindings(this._bindings)); } //Then we apply any optimisers followed by relevant solution modifiers switch (this._type) { case SparqlQueryType.Ask: //Apply Algebra Optimisation is enabled if (Options.AlgebraOptimisation) { algebra = this.ApplyAlgebraOptimisations(algebra); } return(new Ask(algebra)); case SparqlQueryType.Construct: case SparqlQueryType.Describe: case SparqlQueryType.DescribeAll: case SparqlQueryType.Select: case SparqlQueryType.SelectAll: case SparqlQueryType.SelectAllDistinct: case SparqlQueryType.SelectAllReduced: case SparqlQueryType.SelectDistinct: case SparqlQueryType.SelectReduced: //Apply Algebra Optimisation if enabled if (Options.AlgebraOptimisation) { algebra = this.ApplyAlgebraOptimisations(algebra); } //GROUP BY is the first thing applied //This applies if there is a GROUP BY or if there are aggregates //With no GROUP BY it produces a single group of all results if (this._groupBy != null || this._vars.Any(v => v.IsAggregate)) { algebra = new GroupBy(algebra, this._groupBy, this._vars.Where(v => v.IsAggregate)); } //After grouping we do projection //We introduce an Extend for each Project Expression foreach (SparqlVariable var in this._vars) { if (var.IsProjection) { algebra = new Extend(algebra, var.Projection, var.Name); } } //Add HAVING clause after the projection if (this._having != null) { algebra = new Having(algebra, this._having); } //We can then Order our results //We do ordering before we do Select but after Project so we can order by any of //the project expressions/aggregates and any variable in the results even if //it won't be output as a result variable if (this._orderBy != null) { algebra = new OrderBy(algebra, this._orderBy); } //After Ordering we apply Select //Select effectively trims the results so only result variables are left //This doesn't apply to CONSTRUCT since any variable may be used in the Construct Template //so we don't want to eliminate anything if (this._type != SparqlQueryType.Construct) { algebra = new Select(algebra, this.Variables); } //If we have a Distinct/Reduced then we'll apply those after Selection if (this._type == SparqlQueryType.SelectAllDistinct || this._type == SparqlQueryType.SelectDistinct) { algebra = new Distinct(algebra); } else if (this._type == SparqlQueryType.SelectAllReduced || this._type == SparqlQueryType.SelectReduced) { algebra = new Reduced(algebra); } //Finally we can apply any limit and/or offset if (this._limit >= 0 || this._offset > 0) { algebra = new Slice(algebra, this._limit, this._offset); } return(algebra); default: throw new RdfQueryException("Unable to convert unknown Query Types to SPARQL Algebra"); } }
/// <summary> /// Reduce la duración del timer /// </summary> /// <param name="secondsToReduce"></param> public void ReduceDuration(float secondsToReduce) { durationInSeconds -= secondsToReduce; Update(); Reduced?.Invoke(); }
internal void OnReduced(ParsingContext context, Production reducedProduction, ParseTreeNode resultNode) { Reduced?.Invoke(this, new ReducedEventArgs(context, reducedProduction, resultNode)); }