Пример #1
0
        /// <summary>
        /// Converts the Algebra back to a SPARQL Query
        /// </summary>
        /// <returns></returns>
        public GraphPattern ToGraphPattern()
        {
            GraphPattern p = _lhs.ToGraphPattern();

            p.AddGraphPattern(_rhs.ToGraphPattern());
            return(p);
        }
 /// <summary>
 /// Tries to substitute variables within primary expressions
 /// </summary>
 /// <param name="expr">Expression</param>
 /// <returns></returns>
 protected override ISparqlExpression SubstitutePrimaryExpression(ISparqlExpression expr)
 {
     if (expr is VariableTerm)
     {
         if (expr.Variables.First().Equals(this._findVar))
         {
             return(this._replaceExpr);
         }
         else
         {
             return(expr);
         }
     }
     else if (expr is GraphPatternTerm)
     {
         GraphPatternTerm gp  = (GraphPatternTerm)expr;
         ISparqlAlgebra   alg = gp.Pattern.ToAlgebra();
         alg = this.Optimise(alg);
         return(new GraphPatternTerm(alg.ToGraphPattern()));
     }
     else
     {
         return(expr);
     }
 }
Пример #3
0
        /// <summary>
        /// Converts the Algebra back to a SPARQL Query
        /// </summary>
        /// <returns></returns>
        public GraphPattern ToGraphPattern()
        {
            GraphPattern p   = _lhs.ToGraphPattern();
            GraphPattern opt = _rhs.ToGraphPattern();

            opt.IsOptional = true;
            if (_filter.Expression is ConstantTerm)
            {
                try
                {
                    if (!_filter.Expression.Evaluate(null, 0).AsSafeBoolean())
                    {
                        opt.Filter = _filter;
                    }
                }
                catch
                {
                    opt.Filter = _filter;
                }
            }
            else
            {
                opt.Filter = _filter;
            }
            p.AddGraphPattern(opt);
            return(p);
        }
Пример #4
0
        private void RunTest(ISparqlPath path, IEnumerable <String> expectedOperators)
        {
            VariablePattern      x       = new VariablePattern("?x");
            VariablePattern      y       = new VariablePattern("?y");
            PathTransformContext context = new PathTransformContext(x, y);

            Console.WriteLine("Path: " + path.ToString());

            ISparqlAlgebra algebra = path.ToAlgebra(context);
            String         result  = algebra.ToString();

            Console.WriteLine("Algebra: " + result);

            try
            {
                GraphPattern gp = algebra.ToGraphPattern();
                Console.WriteLine("GraphPattern:");
                Console.WriteLine(this._formatter.Format(gp));
                Console.WriteLine();
            }
            catch
            {
                Console.WriteLine("Algebra not translatable to a GraphPattern");
            }

            foreach (String op in expectedOperators)
            {
                if (result.Contains(op))
                {
                    continue;
                }
                Console.WriteLine("Expected Operator '" + op + "' missing");
                Assert.True(false, "Expected Operator '" + op + "' missing");
            }
        }
Пример #5
0
        /// <summary>
        /// Converts the Algebra back to a Graph Pattern.
        /// </summary>
        /// <returns></returns>
        public GraphPattern ToGraphPattern()
        {
            GraphPattern p = _pattern.ToGraphPattern();
            GraphPattern f = new GraphPattern();

            f.AddFilter(_filter);
            p.AddGraphPattern(f);
            return(p);
        }
Пример #6
0
        /// <summary>
        /// Converts the Union back to Graph Patterns.
        /// </summary>
        /// <returns></returns>
        public GraphPattern ToGraphPattern()
        {
            GraphPattern p = new GraphPattern();

            p.IsUnion = true;
            p.AddGraphPattern(_lhs.ToGraphPattern());
            p.AddGraphPattern(_rhs.ToGraphPattern());
            return(p);
        }
Пример #7
0
        /// <summary>
        /// Converts the Algebra back to a Graph Pattern
        /// </summary>
        /// <returns></returns>
        public GraphPattern ToGraphPattern()
        {
            GraphPattern p = _pattern.ToGraphPattern();

            if (!p.IsGraph)
            {
                p.IsGraph        = true;
                p.GraphSpecifier = _graphSpecifier;
            }
            return(p);
        }
Пример #8
0
        /// <summary>
        /// Converts the Algebra back to a Graph Pattern
        /// </summary>
        /// <returns></returns>
        public GraphPattern ToGraphPattern()
        {
            GraphPattern p   = _lhs.ToGraphPattern();
            GraphPattern opt = _rhs.ToGraphPattern();

            if (_mustExist)
            {
                opt.IsExists = true;
            }
            else
            {
                opt.IsNotExists = true;
            }
            p.AddGraphPattern(opt);
            return(p);
        }
Пример #9
0
        /// <summary>
        /// Converts the Algebra to a Graph Pattern.
        /// </summary>
        /// <returns></returns>
        public GraphPattern ToGraphPattern()
        {
            GraphPattern gp = _inner.ToGraphPattern();

            if (gp.HasModifier)
            {
                GraphPattern p = new GraphPattern();
                p.AddGraphPattern(gp);
                p.AddAssignment(new BindPattern(_var, _expr));
                return(p);
            }
            else
            {
                gp.AddAssignment(new BindPattern(_var, _expr));
                return(gp);
            }
        }
Пример #10
0
        /// <summary>
        /// Converts the Minus() back to a MINUS Graph Pattern.
        /// </summary>
        /// <returns></returns>
        public GraphPattern ToGraphPattern()
        {
            GraphPattern p   = _lhs.ToGraphPattern();
            GraphPattern opt = _rhs.ToGraphPattern();

            if (!opt.HasModifier)
            {
                opt.IsMinus = true;
                p.AddGraphPattern(opt);
            }
            else
            {
                GraphPattern parent = new GraphPattern();
                parent.AddGraphPattern(opt);
                parent.IsMinus = true;
                p.AddGraphPattern(parent);
            }
            return(p);
        }