Exemplo n.º 1
0
        /// <summary>
        /// Converts a Path into its Algebra Form
        /// </summary>
        /// <param name="context">Path Transformation Context</param>
        /// <returns></returns>
        public override ISparqlAlgebra ToAlgebra(PathTransformContext context)
        {
            if (this._n > 0)
            {
                // Generate a Triple Pattern for each step in the cardinality
                for (int i = 0; i < this._n; i++)
                {
                    context.Object = context.GetNextTemporaryVariable();

                    if (i < this._n - 1 || !context.Top)
                    {
                        context.AddTriplePattern(context.GetTriplePattern(context.Subject, this._path, context.Object));
                        context.Subject = context.Object;
                    }
                    else
                    {
                        context.ResetObject();
                        context.AddTriplePattern(context.GetTriplePattern(context.Subject, this._path, context.Object));
                    }
                }

                return(context.ToAlgebra());
            }
            else
            {
                return(new ZeroLengthPath(context.Subject, context.Object, this._path));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Converts a Path into its Algebra Form.
        /// </summary>
        /// <param name="context">Path Transformation Context.</param>
        /// <returns></returns>
        public override ISparqlAlgebra ToAlgebra(PathTransformContext context)
        {
            bool top = context.Top;

            // The Object becomes a temporary variable then we transform the LHS of the path
            context.Object = context.GetNextTemporaryVariable();
            context.Top    = false;
            context.AddTriplePattern(context.GetTriplePattern(context.Subject, _lhs, context.Object));

            // The Subject is then the Object that results from the LHS transform since the
            // Transform may adjust the Object
            context.Subject = context.Object;

            // We then reset the Object to be the target Object so that if the RHS is the last part
            // of the Path then it will complete the path transformation
            // If it isn't the last part of the path it will be set to a new temporary variable
            context.Top = top;
            if (context.Top)
            {
                context.ResetObject();
            }
            else
            {
                context.Object = context.GetNextTemporaryVariable();
            }
            context.Top = top;
            context.AddTriplePattern(context.GetTriplePattern(context.Subject, _rhs, context.Object));

            return(context.ToAlgebra());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Converts a Path into its Algebra Form
        /// </summary>
        /// <param name="context">Path Transformation Context</param>
        /// <returns></returns>
        public override ISparqlAlgebra ToAlgebra(PathTransformContext context)
        {
            PatternItem tempVar = context.GetNextTemporaryVariable();

            context.AddTriplePattern(new PropertyPathPattern(context.Subject, new FixedCardinality(this._path, this._n), tempVar));
            context.AddTriplePattern(new PropertyPathPattern(tempVar, new ZeroOrMore(this._path), context.Object));
            return(context.ToAlgebra());
        }
Exemplo n.º 4
0
        /// <summary>
        /// Converts a Path into its Algebra Form
        /// </summary>
        /// <param name="context">Path Transformation Context</param>
        /// <returns></returns>
        public override ISparqlAlgebra ToAlgebra(PathTransformContext context)
        {
            ISparqlAlgebra complex = null;
            int            i       = this._n;

            while (i <= this._m)
            {
                PathTransformContext tempContext = new PathTransformContext(context);
                tempContext.AddTriplePattern(new PropertyPathPattern(context.Subject, new FixedCardinality(this._path, i), context.Object));
                if (complex == null)
                {
                    complex = tempContext.ToAlgebra();
                }
                else
                {
                    complex = new Union(complex, tempContext.ToAlgebra());
                }
                i++;
            }
            return(complex);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Converts a Path into its Algebra Form.
        /// </summary>
        /// <param name="context">Path Transformation Context.</param>
        /// <returns></returns>
        public override ISparqlAlgebra ToAlgebra(PathTransformContext context)
        {
            // Swap the Subject and Object over
            PatternItem tempObj  = context.Object;
            PatternItem tempSubj = context.Subject;
            PatternItem tempEnd  = context.End;

            context.Object  = tempSubj;
            context.Subject = tempObj;
            context.End     = tempSubj;

            // Then transform the path
            context.AddTriplePattern(context.GetTriplePattern(context.Subject, _path, context.Object));

            // Then swap the Subject and Object back
            context.Subject = tempSubj;
            context.Object  = tempObj;
            context.End     = tempEnd;

            return(context.ToAlgebra());
        }
Exemplo n.º 6
0
 /// <summary>
 /// Converts a Path into its Algebra Form.
 /// </summary>
 /// <param name="context">Path Transformation Context.</param>
 /// <returns></returns>
 public ISparqlAlgebra ToAlgebra(PathTransformContext context)
 {
     if (_properties.Count > 0 && _inverseProperties.Count == 0)
     {
         return(new NegatedPropertySet(context.Subject, context.Object, _properties));
     }
     else if (_properties.Count == 0 && _inverseProperties.Count > 0)
     {
         return(new NegatedPropertySet(context.Object, context.Subject, _inverseProperties, true));
     }
     else
     {
         PathTransformContext lhsContext = new PathTransformContext(context);
         PathTransformContext rhsContext = new PathTransformContext(context);
         lhsContext.AddTriplePattern(new PropertyPathPattern(lhsContext.Subject, new NegatedSet(_properties, Enumerable.Empty <Property>()), lhsContext.Object));
         rhsContext.AddTriplePattern(new PropertyPathPattern(rhsContext.Subject, new NegatedSet(Enumerable.Empty <Property>(), _inverseProperties), rhsContext.Object));
         ISparqlAlgebra lhs = lhsContext.ToAlgebra();
         ISparqlAlgebra rhs = rhsContext.ToAlgebra();
         return(new Union(lhs, rhs));
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// Converts a Path into its Algebra Form.
 /// </summary>
 /// <param name="context">Path Transformation Context.</param>
 /// <returns></returns>
 public ISparqlAlgebra ToAlgebra(PathTransformContext context)
 {
     context.AddTriplePattern(context.GetTriplePattern(context.Subject, this, context.Object));
     return(context.ToAlgebra());
 }
Exemplo n.º 8
0
 /// <summary>
 /// Converts a Path into its Algebra Form
 /// </summary>
 /// <param name="context">Path Transformation Context</param>
 /// <returns></returns>
 public override ISparqlAlgebra ToAlgebra(PathTransformContext context)
 {
     ISparqlAlgebra complex = null;
     int i = this._n;
     while (i <= this._m)
     {
         PathTransformContext tempContext = new PathTransformContext(context);
         tempContext.AddTriplePattern(new PropertyPathPattern(context.Subject, new FixedCardinality(this._path, i), context.Object));
         if (complex == null)
         {
             complex = tempContext.ToAlgebra();
         }
         else
         {
             complex = new Union(complex, tempContext.ToAlgebra());
         }
         i++;
     }
     return complex;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Converts a Path into its Algebra Form
 /// </summary>
 /// <param name="context">Path Transformation Context</param>
 /// <returns></returns>
 public override ISparqlAlgebra ToAlgebra(PathTransformContext context)
 {
     context.AddTriplePattern(new PropertyPathPattern(context.Subject, new NToM(this._path, 0, this._n), context.Object));
     return context.ToAlgebra();
 }
Exemplo n.º 10
0
 /// <summary>
 /// Converts a Path into its Algebra Form
 /// </summary>
 /// <param name="context">Path Transformation Context</param>
 /// <returns></returns>
 public override ISparqlAlgebra ToAlgebra(PathTransformContext context)
 {
     PatternItem tempVar = context.GetNextTemporaryVariable();
     context.AddTriplePattern(new PropertyPathPattern(context.Subject, new FixedCardinality(this._path, this._n), tempVar));
     context.AddTriplePattern(new PropertyPathPattern(tempVar, new ZeroOrMore(this._path), context.Object));
     return context.ToAlgebra();
 }
Exemplo n.º 11
0
        /// <summary>
        /// Converts a Path into its Algebra Form
        /// </summary>
        /// <param name="context">Path Transformation Context</param>
        /// <returns></returns>
        public override ISparqlAlgebra ToAlgebra(PathTransformContext context)
        {
            if (this._n > 0)
            {
                //Generate a Triple Pattern for each step in the cardinality
                for (int i = 0; i < this._n; i++)
                {
                    context.Object = context.GetNextTemporaryVariable();

                    if (i < this._n - 1 || !context.Top)
                    {
                        context.AddTriplePattern(context.GetTriplePattern(context.Subject, this._path, context.Object));
                        context.Subject = context.Object;
                    }
                    else
                    {
                        context.ResetObject();
                        context.AddTriplePattern(context.GetTriplePattern(context.Subject, this._path, context.Object));
                    }
                }

                return context.ToAlgebra();
            }
            else
            {
                return new ZeroLengthPath(context.Subject, context.Object, this._path);
            }
        }
Exemplo n.º 12
0
 /// <summary>
 /// Converts a Path into its Algebra Form
 /// </summary>
 /// <param name="context">Path Transformation Context</param>
 /// <returns></returns>
 public override ISparqlAlgebra ToAlgebra(PathTransformContext context)
 {
     context.AddTriplePattern(new PropertyPathPattern(context.Subject, new NToM(this._path, 0, this._n), context.Object));
     return(context.ToAlgebra());
 }
Exemplo n.º 13
0
 /// <summary>
 /// Converts a Path into its Algebra Form
 /// </summary>
 /// <param name="context">Path Transformation Context</param>
 /// <returns></returns>
 public ISparqlAlgebra ToAlgebra(PathTransformContext context)
 {
     if (this._properties.Count > 0 && this._inverseProperties.Count == 0)
     {
         return new NegatedPropertySet(context.Subject, context.Object, this._properties);
     }
     else if (this._properties.Count == 0 && this._inverseProperties.Count > 0)
     {
         return new NegatedPropertySet(context.Object, context.Subject, this._inverseProperties, true);
     }
     else
     {
         PathTransformContext lhsContext = new PathTransformContext(context);
         PathTransformContext rhsContext = new PathTransformContext(context);
         lhsContext.AddTriplePattern(new PropertyPathPattern(lhsContext.Subject, new NegatedSet(this._properties, Enumerable.Empty<Property>()), lhsContext.Object));
         rhsContext.AddTriplePattern(new PropertyPathPattern(rhsContext.Subject, new NegatedSet(Enumerable.Empty<Property>(), this._inverseProperties), rhsContext.Object));
         ISparqlAlgebra lhs = lhsContext.ToAlgebra();
         ISparqlAlgebra rhs = rhsContext.ToAlgebra();
         return new Union(lhs, rhs);
     }
 }
Exemplo n.º 14
0
        /// <summary>
        /// Converts a Path into its Algebra Form
        /// </summary>
        /// <param name="context">Path Transformation Context</param>
        /// <returns></returns>
        public override ISparqlAlgebra ToAlgebra(PathTransformContext context)
        {
            //Swap the Subject and Object over
            PatternItem tempObj = context.Object;
            PatternItem tempSubj = context.Subject;
            PatternItem tempEnd = context.End;
            context.Object = tempSubj;
            context.Subject = tempObj;
            context.End = tempSubj;

            //Then transform the path
            context.AddTriplePattern(context.GetTriplePattern(context.Subject, this._path, context.Object));

            //Then swap the Subject and Object back
            context.Subject = tempSubj;
            context.Object = tempObj;
            context.End = tempEnd;

            return context.ToAlgebra();
        }
Exemplo n.º 15
0
        /// <summary>
        /// Converts a Path into its Algebra Form
        /// </summary>
        /// <param name="context">Path Transformation Context</param>
        /// <returns></returns>
        public override ISparqlAlgebra ToAlgebra(PathTransformContext context)
        {
            bool top = context.Top;

            //The Object becomes a temporary variable then we transform the LHS of the path
            context.Object = context.GetNextTemporaryVariable();
            context.Top = false;
            context.AddTriplePattern(context.GetTriplePattern(context.Subject, this._lhs, context.Object));

            //The Subject is then the Object that results from the LHS transform since the
            //Transform may adjust the Object
            context.Subject = context.Object;

            //We then reset the Object to be the target Object so that if the RHS is the last part
            //of the Path then it will complete the path transformation
            //If it isn't the last part of the path it will be set to a new temporary variable
            context.Top = top;
            if (context.Top)
            {
                context.ResetObject();
            }
            else
            {
                context.Object = context.GetNextTemporaryVariable();
            }
            context.Top = top;
            context.AddTriplePattern(context.GetTriplePattern(context.Subject, this._rhs, context.Object));

            return context.ToAlgebra();
        }
Exemplo n.º 16
0
 /// <summary>
 /// Converts a Path into its Algebra Form
 /// </summary>
 /// <param name="context">Path Transformation Context</param>
 /// <returns></returns>
 public ISparqlAlgebra ToAlgebra(PathTransformContext context)
 {
     context.AddTriplePattern(context.GetTriplePattern(context.Subject, this, context.Object));
     return context.ToAlgebra();
 }