/// <summary>
 /// Optimises the Commands in the Command Set.
 /// </summary>
 /// <param name="optimiser">Optimiser to use.</param>
 public void Optimise(IQueryOptimiser optimiser)
 {
     foreach (SparqlUpdateCommand c in _commands)
     {
         c.Optimise(optimiser);
     }
 }
 /// <summary>
 /// Optimises the Graph Pattern using the given optimiser and with the given variables
 /// </summary>
 /// <param name="optimiser">Query Optimiser</param>
 /// <param name="vars">Variables</param>
 /// <remarks>
 /// <para>
 /// <strong>Important:</strong> If a Pattern has already been optimized then calling this again is a no-op.
 /// </para>
 /// <para>
 /// For finer grained control of what gets optimized you can use <see cref="Options.QueryOptimisation"/> to disable automatic optimisation and then manually call this method as necessary
 /// </para>
 /// <para>
 /// The <paramref name="vars">vars</paramref> parameter contains Variables mentioned in the parent Graph Pattern (if any) that can be used to guide optimisation of child graph patterns
 /// </para>
 /// </remarks>
 public void Optimise(IQueryOptimiser optimiser, IEnumerable <String> vars)
 {
     if (_isOptimised)
     {
         return;
     }
     optimiser.Optimise(this, vars);
 }
 /// <summary>
 /// Optimises the Graph Pattern using the given optimiser
 /// </summary>
 /// <param name="optimiser">Query Optimiser</param>
 /// <remarks>
 /// <para>
 /// <strong>Important:</strong> If a Pattern has already been optimized then calling this again is a no-op.
 /// </para>
 /// <para>
 /// For finer grained control of what gets optimized you can use <see cref="Options.QueryOptimisation"/> to disable automatic optimisation and then manually call this method as necessary
 /// </para>
 /// </remarks>
 public void Optimise(IQueryOptimiser optimiser)
 {
     if (_isOptimised)
     {
         return;
     }
     optimiser.Optimise(this, Enumerable.Empty <String>());
 }
 /// <summary>
 /// Resets Optimisers to default settings.
 /// </summary>
 public static void ResetOptimisers()
 {
     if (!_queryOpt.GetType().Equals(typeof(DefaultOptimiser)))
     {
         _queryOpt = new DefaultOptimiser();
     }
     _algebraOpt = new List <IAlgebraOptimiser>()
     {
         new AskBgpOptimiser(),
         new LazyBgpOptimiser(),
     };
 }
Exemple #5
0
        /// <summary>
        /// Applies optimisation to a Query using the specific optimiser
        /// </summary>
        /// <param name="optimiser">Query Optimiser</param>
        public void Optimise(IQueryOptimiser optimiser)
        {
            if (optimiser == null)
            {
                throw new ArgumentNullException("Cannot optimise a Query using a null optimiser");
            }
            if (this._rootGraphPattern != null)
            {
                optimiser.Optimise(this._rootGraphPattern, Enumerable.Empty <String>());
            }

            this._optimised = true;
        }
Exemple #6
0
 /// <summary>
 /// Optimises the Graph Pattern using the given optimiser
 /// </summary>
 /// <param name="optimiser">Query Optimiser</param>
 public void Optimise(IQueryOptimiser optimiser)
 {
     optimiser.Optimise(this, Enumerable.Empty <String>());
 }
 /// <summary>
 /// Optimises the Commands WHERE pattern
 /// </summary>
 public override void Optimise(IQueryOptimiser optimiser)
 {
     this._wherePattern.Optimise(optimiser);
 }
Exemple #8
0
        /// <summary>
        /// Creates a new Base SPARQL Server Configuration based on information from a Configuration Graph
        /// </summary>
        /// <param name="context">HTTP Context</param>
        /// <param name="g">Configuration Graph</param>
        /// <param name="objNode">Object Node</param>
        public BaseSparqlServerConfiguration(HttpContext context, IGraph g, INode objNode)
            : base(context, g, objNode)
        {
            //Get the Query Processor to be used
            INode procNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyQueryProcessor));

            if (procNode != null)
            {
                Object temp = ConfigurationLoader.LoadObject(g, procNode);
                if (temp is ISparqlQueryProcessor)
                {
                    this._queryProcessor = (ISparqlQueryProcessor)temp;
                }
                else
                {
                    throw new DotNetRdfConfigurationException("Unable to load SPARQL Server Configuration as the RDF configuration file specifies a value for the Handlers dnr:queryProcessor property which cannot be loaded as an object which implements the ISparqlQueryProcessor interface");
                }
            }

            //SPARQL Query Default Config
            this._defaultGraph          = ConfigurationLoader.GetConfigurationValue(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDefaultGraphUri)).ToSafeString();
            this._defaultTimeout        = ConfigurationLoader.GetConfigurationInt64(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyTimeout), this._defaultTimeout);
            this._defaultPartialResults = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyPartialResults), this._defaultPartialResults);

            //Handler Configuration
            this._showQueryForm = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyShowQueryForm), this._showQueryForm);
            String defQueryFile = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDefaultQueryFile));

            if (defQueryFile != null)
            {
                defQueryFile = ConfigurationLoader.ResolvePath(defQueryFile);
                if (File.Exists(defQueryFile))
                {
                    using (StreamReader reader = new StreamReader(defQueryFile))
                    {
                        this._defaultQuery = reader.ReadToEnd();
                        reader.Close();
                    }
                }
            }

            //Get Query Syntax to use
            try
            {
                String syntaxSetting = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertySyntax));
                if (syntaxSetting != null)
                {
                    this._syntax = (SparqlQuerySyntax)Enum.Parse(typeof(SparqlQuerySyntax), syntaxSetting);
                }
            }
            catch (Exception ex)
            {
                throw new DotNetRdfConfigurationException("Unable to set the Syntax for the HTTP Handler identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:syntax property was not a valid value from the enum VDS.RDF.Parsing.SparqlQuerySyntax", ex);
            }

            //Get the SPARQL Describe Algorithm
            INode describeNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDescribeAlgorithm));

            if (describeNode != null)
            {
                if (describeNode.NodeType == NodeType.Literal)
                {
                    String algoClass = ((ILiteralNode)describeNode).Value;
                    try
                    {
                        Object desc = Activator.CreateInstance(Type.GetType(algoClass));
                        if (desc is ISparqlDescribe)
                        {
                            this._describer = (ISparqlDescribe)desc;
                        }
                        else
                        {
                            throw new DotNetRdfConfigurationException("Unable to set the Describe Algorithm for the HTTP Handler identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:describeAlgorithm property was not a type name of a type that implements the ISparqlDescribe interface");
                        }
                    }
                    catch (DotNetRdfConfigurationException)
                    {
                        throw;
                    }
                    catch (Exception ex)
                    {
                        throw new DotNetRdfConfigurationException("Unable to set the Describe Algorithm for the HTTP Handler identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:describeAlgorithm property was not a type name for a type that can be instantiated", ex);
                    }
                }
            }

            //Get the Query Optimiser
            INode queryOptNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyQueryOptimiser));

            if (queryOptNode != null)
            {
                Object queryOpt = ConfigurationLoader.LoadObject(g, queryOptNode);
                if (queryOpt is IQueryOptimiser)
                {
                    this._queryOptimiser = (IQueryOptimiser)queryOpt;
                }
                else
                {
                    throw new DotNetRdfConfigurationException("Unable to set the Query Optimiser for the HTTP Handler identified by the Node '" + queryOptNode.ToString() + "' as the value given for the dnr:queryOptimiser property points to an Object which could not be loaded as an object which implements the required IQueryOptimiser interface");
                }
            }

            //Get the Algebra Optimisers
            foreach (INode algOptNode in ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyAlgebraOptimiser)))
            {
                Object algOpt = ConfigurationLoader.LoadObject(g, algOptNode);
                if (algOpt is IAlgebraOptimiser)
                {
                    this._algebraOptimisers.Add((IAlgebraOptimiser)algOpt);
                }
                else
                {
                    throw new DotNetRdfConfigurationException("Unable to set the Algebra Optimiser for the HTTP Handler identified by the Node '" + algOptNode.ToString() + "' as the value given for the dnr:algebraOptimiser property points to an Object which could not be loaded as an object which implements the required IAlgebraOptimiser interface");
                }
            }

            //Then get the Update Processor to be used
            procNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUpdateProcessor));
            if (procNode != null)
            {
                Object temp = ConfigurationLoader.LoadObject(g, procNode);
                if (temp is ISparqlUpdateProcessor)
                {
                    this._updateProcessor = (ISparqlUpdateProcessor)temp;
                }
                else
                {
                    throw new DotNetRdfConfigurationException("Unable to load SPARQL Server Configuration as the RDF configuration file specifies a value for the Handlers dnr:updateProcessor property which cannot be loaded as an object which implements the ISparqlUpdateProcessor interface");
                }
            }

            //Handler Settings
            this._showUpdateForm = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyShowUpdateForm), this._showUpdateForm);
            String defUpdateFile = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDefaultUpdateFile));

            if (defUpdateFile != null)
            {
                defUpdateFile = ConfigurationLoader.ResolvePath(defUpdateFile);
                if (File.Exists(defUpdateFile))
                {
                    using (StreamReader reader = new StreamReader(defUpdateFile))
                    {
                        this._defaultUpdate = reader.ReadToEnd();
                        reader.Close();
                    }
                }
            }

            //Then get the Protocol Processor to be used
            procNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyProtocolProcessor));
            if (procNode != null)
            {
                Object temp = ConfigurationLoader.LoadObject(g, procNode);
                if (temp is ISparqlHttpProtocolProcessor)
                {
                    this._protocolProcessor = (ISparqlHttpProtocolProcessor)temp;
                }
                else
                {
                    throw new DotNetRdfConfigurationException("Unable to load SPARQL Server Configuration as the RDF configuration file specifies a value for the Handlers dnr:protocolProcessor property which cannot be loaded as an object which implements the ISparqlHttpProtocolProcessor interface");
                }
            }

            if (this._queryProcessor == null && this._updateProcessor == null && this._protocolProcessor == null)
            {
                throw new DotNetRdfConfigurationException("Unable to load SPARQL Server Configuration as the RDF configuration file does not specify at least one of a Query/Update/Protocol processor for the server using the dnr:queryProcessor/dnr:updateProcessor/dnr:protocolProcessor properties");
            }

            //Get the Service Description Graph
            INode descripNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyServiceDescription));

            if (descripNode != null)
            {
                Object descrip = ConfigurationLoader.LoadObject(g, descripNode);
                if (descrip is IGraph)
                {
                    this._serviceDescription = (IGraph)descrip;
                }
                else
                {
                    throw new DotNetRdfConfigurationException("Unable to set the Service Description Graph for the HTTP Handler identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:serviceDescription property points to an Object which could not be loaded as an object which implements the required IGraph interface");
                }
            }
        }
Exemple #9
0
 /// <summary>
 /// Optimises the Command
 /// </summary>
 public virtual void Optimise(IQueryOptimiser optimiser)
 {
     // Does Nothing by Default
 }
Exemple #10
0
 /// <summary>
 /// Optimises the Command
 /// </summary>
 public virtual void Optimise(IQueryOptimiser optimiser)
 {
     //Does Nothing by Default
 }
        /// <summary>
        /// Creates a new Query Handler Configuration
        /// </summary>
        /// <param name="context">HTTP Context</param>
        /// <param name="g">Configuration Graph</param>
        /// <param name="objNode">Object Node</param>
        public BaseQueryHandlerConfiguration(HttpContext context, IGraph g, INode objNode)
            : base(context, g, objNode)
        {
            //Get the Query Processor to be used
            ISparqlQueryProcessor processor;
            INode procNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyQueryProcessor));
            if (procNode == null) throw new DotNetRdfConfigurationException("Unable to load Query Handler Configuration as the RDF configuration file does not specify a dnr:queryProcessor property for the Handler");
            Object temp = ConfigurationLoader.LoadObject(g, procNode);
            if (temp is ISparqlQueryProcessor)
            {
                processor = (ISparqlQueryProcessor)temp;
            }
            else
            {
                throw new DotNetRdfConfigurationException("Unable to load Query Handler Configuration as the RDF configuration file specifies a value for the Handlers dnr:updateProcessor property which cannot be loaded as an object which implements the ISparqlQueryProcessor interface");
            }
            this._processor = processor;

            //SPARQL Query Default Config
            this._defaultGraph = ConfigurationLoader.GetConfigurationValue(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDefaultGraphUri)).ToSafeString();
            this._defaultTimeout = ConfigurationLoader.GetConfigurationInt64(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyTimeout), this._defaultTimeout);
            this._defaultPartialResults = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyPartialResults), this._defaultPartialResults);

            //Handler Configuration
            this._showQueryForm = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyShowQueryForm), this._showQueryForm);
            String defQueryFile = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDefaultQueryFile));
            if (defQueryFile != null)
            {
                defQueryFile = ConfigurationLoader.ResolvePath(defQueryFile);
                if (File.Exists(defQueryFile))
                {
                    using (StreamReader reader = new StreamReader(defQueryFile))
                    {
                        this._defaultQuery = reader.ReadToEnd();
                        reader.Close();
                    }
                }
            }

            //Get Query Syntax to use
            try
            {
                String syntaxSetting = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertySyntax));
                if (syntaxSetting != null)
                {
                    this._syntax = (SparqlQuerySyntax)Enum.Parse(typeof(SparqlQuerySyntax), syntaxSetting);
                }
            }
            catch (Exception ex)
            {
                throw new DotNetRdfConfigurationException("Unable to set the Syntax for the HTTP Handler identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:syntax property was not a valid value from the enum VDS.RDF.Parsing.SparqlQuerySyntax", ex);
            }

            //Get the SPARQL Describe Algorithm
            INode describeNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDescribeAlgorithm));
            if (describeNode != null)
            {
                if (describeNode.NodeType == NodeType.Literal)
                {
                    String algoClass = ((ILiteralNode)describeNode).Value;
                    try
                    {
                        Object desc = Activator.CreateInstance(Type.GetType(algoClass));
                        if (desc is ISparqlDescribe)
                        {
                            this._describer = (ISparqlDescribe)desc;
                        }
                        else
                        {
                            throw new DotNetRdfConfigurationException("Unable to set the Describe Algorithm for the HTTP Handler identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:describeAlgorithm property was not a type name of a type that implements the ISparqlDescribe interface");
                        }
                    }
                    catch (DotNetRdfConfigurationException)
                    {
                            throw;
                    }
                    catch (Exception ex)
                    {
                        throw new DotNetRdfConfigurationException("Unable to set the Describe Algorithm for the HTTP Handler identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:describeAlgorithm property was not a type name for a type that can be instantiated", ex);
                    }
                }
            }

            //Get the Service Description Graph
            INode descripNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyServiceDescription));
            if (descripNode != null)
            {
                Object descrip = ConfigurationLoader.LoadObject(g, descripNode);
                if (descrip is IGraph)
                {
                    this._serviceDescription = (IGraph)descrip;
                }
                else
                {
                    throw new DotNetRdfConfigurationException("Unable to set the Service Description Graph for the HTTP Handler identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:serviceDescription property points to an Object which could not be loaded as an object which implements the required IGraph interface");
                }
            }

            //Get the Query Optimiser
            INode queryOptNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyQueryOptimiser));
            if (queryOptNode != null)
            {
                Object queryOpt = ConfigurationLoader.LoadObject(g, queryOptNode);
                if (queryOpt is IQueryOptimiser)
                {
                    this._queryOptimiser = (IQueryOptimiser)queryOpt;
                }
                else
                {
                    throw new DotNetRdfConfigurationException("Unable to set the Query Optimiser for the HTTP Handler identified by the Node '" + queryOptNode.ToString() + "' as the value given for the dnr:queryOptimiser property points to an Object which could not be loaded as an object which implements the required IQueryOptimiser interface");
                }
            }

            //Get the Algebra Optimisers
            foreach (INode algOptNode in ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyAlgebraOptimiser)))
            {
                Object algOpt = ConfigurationLoader.LoadObject(g, algOptNode);
                if (algOpt is IAlgebraOptimiser)
                {
                    this._algebraOptimisers.Add((IAlgebraOptimiser)algOpt);
                }
                else
                {
                    throw new DotNetRdfConfigurationException("Unable to set the Algebra Optimiser for the HTTP Handler identified by the Node '" + algOptNode.ToString() + "' as the value given for the dnr:algebraOptimiser property points to an Object which could not be loaded as an object which implements the required IAlgebraOptimiser interface");
                }
            }
        }
Exemple #12
0
 /// <summary>
 /// Resets Optimisers to default settings
 /// </summary>
 public static void ResetOptimisers()
 {
     if (!_queryOpt.GetType().Equals(typeof(DefaultOptimiser)))
     {
         _queryOpt = new DefaultOptimiser();
     }
     _algebraOpt = new List<IAlgebraOptimiser>()
     {
         new AskBgpOptimiser(),
         new LazyBgpOptimiser()
     };
 }
Exemple #13
0
        /// <summary>
        /// Applies optimisation to a Query using the specific optimiser
        /// </summary>
        /// <param name="optimiser">Query Optimiser</param>
        public void Optimise(IQueryOptimiser optimiser)
        {
            if (optimiser == null) throw new ArgumentNullException("Cannot optimise a Query using a null optimiser");
            if (this._rootGraphPattern != null)
            {
                optimiser.Optimise(this._rootGraphPattern, Enumerable.Empty<String>());
            }

            this._optimised = true;
        }
Exemple #14
0
 /// <summary>
 /// Optimises the Graph Pattern using the given optimiser and with the given variables
 /// </summary>
 /// <param name="optimiser">Query Optimiser</param>
 /// <param name="vars">Variables</param>
 /// <remarks>
 /// The <paramref name="vars">vars</paramref> parameter contains Variables mentioned in the parent Graph Pattern (if any) that can be used to guide optimisation of child graph patterns
 /// </remarks>
 public void Optimise(IQueryOptimiser optimiser, IEnumerable <String> vars)
 {
     optimiser.Optimise(this, vars);
 }
 /// <summary>
 /// Optimises the Commands in the Command Set
 /// </summary>
 /// <param name="optimiser">Optimiser to use</param>
 public void Optimise(IQueryOptimiser optimiser)
 {
     foreach (SparqlUpdateCommand c in this._commands)
     {
         c.Optimise(optimiser);
     }
 }
Exemple #16
0
 /// <summary>
 /// Optimises the Commands WHERE pattern
 /// </summary>
 public override void Optimise(IQueryOptimiser optimiser)
 {
     this._wherePattern.Optimise(optimiser);
 }
Exemple #17
0
 /// <summary>
 /// Optimises the Graph Pattern using the given optimiser and with the given variables
 /// </summary>
 /// <param name="optimiser">Query Optimiser</param>
 /// <param name="vars">Variables</param>
 /// <remarks>
 /// The <paramref name="vars">vars</paramref> parameter contains Variables mentioned in the parent Graph Pattern (if any) that can be used to guide optimisation of child graph patterns
 /// </remarks>
 public void Optimise(IQueryOptimiser optimiser, IEnumerable<String> vars)
 {
     optimiser.Optimise(this, vars);
 }
Exemple #18
0
 /// <summary>
 /// Optimises the Graph Pattern using the given optimiser
 /// </summary>
 /// <param name="optimiser">Query Optimiser</param>
 public void Optimise(IQueryOptimiser optimiser)
 {
     optimiser.Optimise(this, Enumerable.Empty<String>());
 }