/// <summary>
 /// Creates a new <see cref="IDataObjectContext"/> instance that uses SPARQL query and update
 /// to access RDF data.
 /// </summary>
 /// <param name="queryProcessor">The SPARQL query processor to use for read/query </param>
 /// <param name="updateProcessor">The SPARQL update processor to use for update</param>
 /// <param name="optimisticLocking">Boolean flag indicating if optimistic locking should be enabled by default for the stores
 /// accessed via this context.</param>
 /// <param name="storeName">Overrides the default store name of 'sparql' for the store managed by this context</param>
 public SparqlDataObjectContext(ISparqlQueryProcessor queryProcessor, ISparqlUpdateProcessor updateProcessor, bool optimisticLocking, string storeName = DefaultStoreName)
 {
     QueryProcessor = queryProcessor;
     UpdateProcessor = updateProcessor;
     OptimisticLockingEnabled = optimisticLocking;
     _storeName = storeName;
 }
예제 #2
0
 public MetadataSource(Options opts)
 {
     if (!String.IsNullOrEmpty(opts.EndpointUri))
     {
         if (String.IsNullOrEmpty(opts.DefaultGraphUri))
         {
             this._processor = new RemoteQueryProcessor(new SparqlRemoteEndpoint(new Uri(opts.EndpointUri)));
         }
         else
         {
             this._processor = new RemoteQueryProcessor(new SparqlRemoteEndpoint(new Uri(opts.EndpointUri), opts.DefaultGraphUri));
         }
     }
     else if (!String.IsNullOrEmpty(opts.SourceFile))
     {
         TripleStore store = new TripleStore();
         Graph g = new Graph();
         FileLoader.Load(g, opts.SourceFile);
         store.Add(g);
         this._processor = new LeviathanQueryProcessor(store);
     }
     else
     {
         throw new Exception("Must specify an endpoint or a file to query");
     }
 }
예제 #3
0
        public void Setup()
        {
            TripleStore store = new TripleStore();

            store.LoadFromString(data);
            this._dataset   = new InMemoryQuadDataset(store, false);
            this._processor = new LeviathanQueryProcessor(this._dataset);
        }
 public RdfDataBuilder(ISparqlDataset dataset, INamespaceMapper namespaceMapper, TimelineTable timelineTable)
 {
     this.dataset         = dataset ?? throw new ArgumentNullException(nameof(dataset));
     this.namespaceMapper = namespaceMapper ?? throw new ArgumentNullException(nameof(namespaceMapper));
     this.timelineTable   = timelineTable ?? throw new ArgumentNullException(nameof(timelineTable));
     sparqlProcessor      = new LeviathanQueryProcessor(dataset);
     sparqlQueryParser    = new SparqlQueryParser();
 }
 public SparqlDataObjectStore(
     ISparqlQueryProcessor queryProcessor, ISparqlUpdateProcessor updateProcessor,
     Dictionary <string, string> namespaceMappings, bool optimisticLockingEnabled,
     string updateGraphUri = null, IEnumerable <string> datasetGraphUris = null, string versionGraphUri = null)
     : base(updateProcessor == null, namespaceMappings, optimisticLockingEnabled, updateGraphUri, datasetGraphUris, versionGraphUri)
 {
     _client = new SparqlUpdatableStore(queryProcessor, updateProcessor);
 }
 public SparqlDataObjectStore(
     ISparqlQueryProcessor queryProcessor, ISparqlUpdateProcessor updateProcessor,
     Dictionary<string, string> namespaceMappings, bool optimisticLockingEnabled, 
     string updateGraphUri = null, IEnumerable<string> datasetGraphUris = null, string versionGraphUri = null) 
     : base(namespaceMappings, optimisticLockingEnabled, updateGraphUri, datasetGraphUris, versionGraphUri)
 {
     _client = new SparqlUpdatableStore(queryProcessor, updateProcessor);
 }
 private void EnsureGenericReady()
 {
     this.EnsureLeviathanReady();
     if (this._generic == null)
     {
         this._generic = new GenericQueryProcessor(new InMemoryManager(this._dataset));
     }
 }
 private void EnsureRemoteReady()
 {
     if (this._remote == null)
     {
         Skip.IfNot(TestConfigManager.GetSettingAsBoolean(TestConfigManager.UseIIS), "Test Config marks IIS as unavailable, cannot run test");
         this._remote = new RemoteQueryProcessor(new SparqlRemoteEndpoint(new Uri(TestConfigManager.GetSetting(TestConfigManager.LocalQueryUri))));
     }
 }
 /// <summary>
 /// Create a new instance of <see cref="DotNetRdfDataObjectContext"/>
 /// with a specific ISparqlQueryProcessor and ISparqlUpdateProcessor instance
 /// that serves up a single named store.
 /// </summary>
 /// <param name="storeName">The name of the store that will be provided by this context</param>
 /// <param name="queryProcessor">The ISparqlQueryProcessor instance that provides SPARQL query functionality for the store.</param>
 /// <param name="updateProcessor">The ISparqlUpdateProcessor instance that provides SPARQL update functionality for the store.</param>
 /// <exception cref="ArgumentException">Raised if <paramref name="storeName"/> is NULL or an empty string</exception>
 /// <exception cref="ArgumentNullException">Raised if <paramref name="queryProcessor"/> or <paramref name="updateProcessor"/> is NULL</exception>
 public DotNetRdfDataObjectContext(string storeName, ISparqlQueryProcessor queryProcessor, ISparqlUpdateProcessor updateProcessor)
 {
     if (String.IsNullOrEmpty(storeName)) throw new ArgumentException(Strings.StringParameterMustBeNonEmpty, "storeName");
     if (queryProcessor == null) throw new ArgumentNullException("queryProcessor");
     if (updateProcessor == null) throw new ArgumentNullException("updateProcessor");
     _configuredStoreName = storeName;
     _queryProcessor = queryProcessor;
     _updateProcessor = updateProcessor;
 }
 /// <summary>
 /// Executes a SPARQL Query on the Graph.
 /// </summary>
 /// <param name="query">SPARQL Query.</param>
 /// <returns></returns>
 public Object ExecuteQuery(SparqlQuery query)
 {
     if (_processor == null)
     {
         InMemoryDataset ds = new InMemoryDataset(this);
         _processor = new LeviathanQueryProcessor(ds);
     }
     return(_processor.ProcessQuery(query));
 }
 /// <summary>
 /// Executes a SPARQL Query on the Graph handling the results with the given handlers.
 /// </summary>
 /// <param name="rdfHandler">RDF Handler.</param>
 /// <param name="resultsHandler">SPARQL Results Handler.</param>
 /// <param name="query">SPARQL Query.</param>
 public void ExecuteQuery(IRdfHandler rdfHandler, ISparqlResultsHandler resultsHandler, SparqlQuery query)
 {
     if (_processor == null)
     {
         InMemoryDataset ds = new InMemoryDataset(this);
         _processor = new LeviathanQueryProcessor(ds);
     }
     _processor.ProcessQuery(rdfHandler, resultsHandler, query);
 }
예제 #12
0
        /// <summary>
        /// Loads data from ontology file and initialize some intances for querying
        /// </summary>
        public static void Start()
        {
            store = new TripleStore();
            store.LoadFromFile("PhoneOntology.owl");

            InMemoryDataset ds = new InMemoryDataset(store);

            processor    = new LeviathanQueryProcessor(ds);
            sparqlparser = new SparqlQueryParser();
        }
 private void EnsureRemoteReady()
 {
     if (this._remote == null)
     {
         if (!TestConfigManager.GetSettingAsBoolean(TestConfigManager.UseIIS))
         {
             Assert.Inconclusive("Test Config marks IIS as unavailabe, cannot run test");
         }
         this._remote = new RemoteQueryProcessor(new SparqlRemoteEndpoint(new Uri(TestConfigManager.GetSetting(TestConfigManager.LocalQueryUri))));
     }
 }
        private IGraph QueryWithGraph(SparqlQuery q, ISparqlQueryProcessor processor)
        {
            var results = processor.ProcessQuery(q);

            if (results is IGraph)
            {
                return((IGraph)results);
            }
            else
            {
                Assert.True(false, "Query did not produce a Graph as expected");
            }
            return(null);
        }
        private SparqlResultSet QueryWithResults(SparqlQuery q, ISparqlQueryProcessor processor)
        {
            var results = processor.ProcessQuery(q);

            if (results is SparqlResultSet)
            {
                return((SparqlResultSet)results);
            }
            else
            {
                Assert.True(false, "Query did not produce a Result Set as expected");
            }
            return(null);
        }
        private void TestResultCountHandler(ISparqlQueryProcessor processor, String query)
        {
            SparqlQuery q = this._parser.ParseFromString(query);

            SparqlResultSet expected = processor.ProcessQuery(q) as SparqlResultSet;

            Assert.NotNull(expected);

            ResultCountHandler handler = new ResultCountHandler();

            processor.ProcessQuery(null, handler, q);

            Assert.Equal(expected.Count, handler.Count);
        }
        private void TestCountHandler(ISparqlQueryProcessor processor, String query)
        {
            SparqlQuery q = this._parser.ParseFromString(query);

            Graph expected = processor.ProcessQuery(q) as Graph;

            Assert.NotNull(expected);

            CountHandler handler = new CountHandler();

            processor.ProcessQuery(handler, null, q);

            Assert.Equal(expected.Triples.Count, handler.Count);
        }
        private void TestGraphHandler(ISparqlQueryProcessor processor, String query)
        {
            SparqlQuery q = this._parser.ParseFromString(query);

            Graph expected = processor.ProcessQuery(q) as Graph;

            Assert.NotNull(expected);

            Graph        actual  = new Graph();
            GraphHandler handler = new GraphHandler(actual);

            processor.ProcessQuery(handler, null, q);

            Assert.Equal(expected, actual);
        }
        private void TestCountHandler(ISparqlQueryProcessor processor, String query)
        {
            SparqlQuery q = this._parser.ParseFromString(query);

            Graph expected = processor.ProcessQuery(q) as Graph;

            if (expected == null)
            {
                Assert.Fail("Query failed to return a Graph as expected");
            }

            CountHandler handler = new CountHandler();

            processor.ProcessQuery(handler, null, q);

            Assert.AreEqual(expected.Triples.Count, handler.Count, "Counts should have been equal");
        }
        private void TestResultCountHandler(ISparqlQueryProcessor processor, String query)
        {
            SparqlQuery q = this._parser.ParseFromString(query);

            SparqlResultSet expected = processor.ProcessQuery(q) as SparqlResultSet;

            if (expected == null)
            {
                Assert.Fail("Query failed to return a Result Set as expected");
            }

            ResultCountHandler handler = new ResultCountHandler();

            processor.ProcessQuery(null, handler, q);

            Assert.AreEqual(expected.Count, handler.Count, "Counts should have been equal");
        }
        private void TestResultSetHandler(ISparqlQueryProcessor processor, String query)
        {
            SparqlQuery q = this._parser.ParseFromString(query);

            SparqlResultSet expected = processor.ProcessQuery(q) as SparqlResultSet;

            if (expected == null)
            {
                Assert.Fail("Query failed to return a Result Set as expected");
            }

            SparqlResultSet  actual  = new SparqlResultSet();
            ResultSetHandler handler = new ResultSetHandler(actual);

            processor.ProcessQuery(null, handler, q);

            Assert.AreEqual(expected, actual, "Result Sets should be equal");
        }
 /// <summary>
 /// Create a new instance of <see cref="DotNetRdfDataObjectContext"/>
 /// with a specific ISparqlQueryProcessor and ISparqlUpdateProcessor instance
 /// that serves up a single named store.
 /// </summary>
 /// <param name="storeName">The name of the store that will be provided by this context</param>
 /// <param name="queryProcessor">The ISparqlQueryProcessor instance that provides SPARQL query functionality for the store.</param>
 /// <param name="updateProcessor">The ISparqlUpdateProcessor instance that provides SPARQL update functionality for the store.</param>
 /// <exception cref="ArgumentException">Raised if <paramref name="storeName"/> is NULL or an empty string</exception>
 /// <exception cref="ArgumentNullException">Raised if <paramref name="queryProcessor"/> or <paramref name="updateProcessor"/> is NULL</exception>
 public DotNetRdfDataObjectContext(string storeName, ISparqlQueryProcessor queryProcessor, ISparqlUpdateProcessor updateProcessor)
 {
     if (String.IsNullOrEmpty(storeName))
     {
         throw new ArgumentException(Strings.StringParameterMustBeNonEmpty, "storeName");
     }
     if (queryProcessor == null)
     {
         throw new ArgumentNullException("queryProcessor");
     }
     if (updateProcessor == null)
     {
         throw new ArgumentNullException("updateProcessor");
     }
     _configuredStoreName = storeName;
     _queryProcessor      = queryProcessor;
     _updateProcessor     = updateProcessor;
 }
        private void TestGraphHandler(ISparqlQueryProcessor processor, String query)
        {
            SparqlQuery q = this._parser.ParseFromString(query);

            Graph expected = processor.ProcessQuery(q) as Graph;

            if (expected == null)
            {
                Assert.Fail("Query failed to return a Grah as expected");
            }

            Graph        actual  = new Graph();
            GraphHandler handler = new GraphHandler(actual);

            processor.ProcessQuery(handler, null, q);

            Assert.AreEqual(expected, actual, "Graphs should be equal");
        }
        private void EnsureLeviathanReady()
        {
            if (this._dataset == null)
            {
                TripleStore store = new TripleStore();
                Graph       g     = new Graph();
                g.LoadFromFile("resources\\InferenceTest.ttl");
                store.Add(g);

                this._dataset = new InMemoryDataset(store);
            }
            if (this._leviathan == null)
            {
                this._leviathan = new LeviathanQueryProcessor(this._dataset);
            }
            if (this._explainer == null)
            {
                this._explainer = new ExplainQueryProcessor(this._dataset, ExplanationLevel.Default);
            }
        }
        private void TestWriteThroughHandler(ISparqlQueryProcessor processor, String query)
        {
            NTriplesFormatter formatter = new NTriplesFormatter();
            StringWriter      data      = new StringWriter();

            SparqlQuery q        = this._parser.ParseFromString(query);
            Graph       expected = processor.ProcessQuery(q) as Graph;

            Assert.NotNull(expected);

            WriteThroughHandler handler = new WriteThroughHandler(formatter, data, false);

            processor.ProcessQuery(handler, null, q);
            Console.WriteLine(data.ToString());

            Graph actual = new Graph();

            StringParser.Parse(actual, data.ToString(), new NTriplesParser());

            Assert.Equal(expected, actual);
        }
예제 #26
0
        /// <summary>
        /// Processes a SPARQL Query using given SPARQL procesor returning either an IGraph instance or SparqlResultSet, or AsyncError if the processing failed
        /// </summary>
        /// <returns>IGraph or SparqlResultSet or AsyncError or null</returns>
        public static Task <object> ProcessQuery(SparqlQuery query, ISparqlQueryProcessor processor)
        {
            TaskCompletionSource <object> taskComplSource = new TaskCompletionSource <object>();

            if (query == null || processor == null)
            {
                var asyncError = new AsyncError(new BrowserException("An internal error occured while processing the query."), null);
                taskComplSource.SetResult(asyncError);
            }
            else
            {
                //state will contain AsyncError
                //catches all exceptions inside, putting them into AsyncError
                processor.ProcessQuery(
                    query,
                    (IGraph g, object state) => { taskComplSource.SetResult(g ?? state); },
                    (SparqlResultSet results, object state) => { taskComplSource.SetResult(results ?? state); },
                    null
                    );
            }
            return(taskComplSource.Task);
        }
예제 #27
0
        public dotNetRDFStore(string[] schema)
        {
            _store           = new TripleStore();
            _updateProcessor = new LeviathanUpdateProcessor(_store);
            _queryProcessor  = new LeviathanQueryProcessor(_store);
            _parser          = new SparqlUpdateParser();

            if (schema == null)
            {
                return;
            }

            _reasoner = new RdfsReasoner();
            _store.AddInferenceEngine(_reasoner);

            foreach (string m in schema)
            {
                IGraph schemaGraph = LoadSchema(m);

                _store.Add(schemaGraph);
                _reasoner.Initialise(schemaGraph);
            }
        }
예제 #28
0
        /// <summary>
        /// Creates a new dotNetRDFStore.
        /// </summary>
        /// <param name="schemes">A list of ontology file paths relative to this assembly. The store will be populated with these ontologies.</param>
        public dotNetRDFStore(string[] schemes)
        {
            _store           = new TripleStore();
            _updateProcessor = new LeviathanUpdateProcessor(_store);
            _queryProcessor  = new LeviathanQueryProcessor(_store);
            _parser          = new SparqlUpdateParser();

            if (schemes != null)
            {
                _reasoner = new RdfsReasoner();
                _store.AddInferenceEngine(_reasoner);

                foreach (string s in schemes)
                {
                    var directory = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory;
                    var file      = new FileInfo(Path.Combine(directory.FullName, s));

                    IGraph schemaGraph = LoadSchema(file.FullName);

                    _store.Add(schemaGraph);
                    _reasoner.Initialise(schemaGraph);
                }
            }
        }
        private void TestWriteThroughHandler(ISparqlQueryProcessor processor, String query)
        {
            NTriplesFormatter formatter = new NTriplesFormatter();
            StringWriter      data      = new StringWriter();

            SparqlQuery q        = this._parser.ParseFromString(query);
            Graph       expected = processor.ProcessQuery(q) as Graph;

            if (expected == null)
            {
                Assert.Fail("Query did not produce a Graph as expected");
            }

            WriteThroughHandler handler = new WriteThroughHandler(formatter, data, false);

            processor.ProcessQuery(handler, null, q);
            Console.WriteLine(data.ToString());

            Graph actual = new Graph();

            StringParser.Parse(actual, data.ToString(), new NTriplesParser());

            Assert.AreEqual(expected, actual, "Graphs should be equal");
        }
예제 #30
0
 /// <summary>
 /// Processes the Query using the given Query Processor
 /// </summary>
 /// <param name="processor">SPARQL Query Processor</param>
 /// <returns></returns>
 public Object Process(ISparqlQueryProcessor processor)
 {
     return processor.ProcessQuery(this);
 }
예제 #31
0
 public MetadataProvider(Options options, ISparqlQueryProcessor queryProcessor, ISparqlUpdateProcessor updateProcessor)
 {
     _options         = options;
     _queryProcessor  = queryProcessor;
     _updateProcessor = updateProcessor;
 }
예제 #32
0
 public ProcessorBooleanQuery(String query, ISparqlQueryProcessor processor)
     : base(query)
 {
     this._processor = processor;
 }
        /// <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");
                }
            }
        }
예제 #34
0
        private static Collection<BaprLocation> ExecuteQuery(ISparqlQueryProcessor processor, SparqlQuery query)
        {
            try
            {
                object queryResult = processor.ProcessQuery(query);
                if (queryResult is SparqlResultSet)
                {
                    SparqlResultSet entities = (SparqlResultSet)queryResult;
                    return BaprAPI.Utils.Utils.ConvertFromSparqlSetToBaprLocations(entities);
                }
            }
            catch (VDS.RDF.Query.RdfQueryException ex)
            {

            }
            return new Collection<BaprLocation>();
        }
예제 #35
0
 /// <summary>
 /// Creates a new LINQ Triple Store that operates over a given pair of SPARQL Processors
 /// </summary>
 /// <param name="queryProcessor">Query Processor</param>
 /// <param name="updateProcessor">Update Processor</param>
 public LinqTripleStore(ISparqlQueryProcessor queryProcessor, ISparqlUpdateProcessor updateProcessor)
     : this(new LinqQueryProcessor(queryProcessor), new LinqUpdateProcessor(updateProcessor), LinqQueryMethod.CustomSparql)
 {
 }
 /// <summary>
 /// Creates a new Protocol to Update Processor
 /// </summary>
 /// <param name="queryProcessor">Query Processor</param>
 /// <param name="updateProcessor">Update Processor</param>
 public ProtocolToUpdateProcessor(ISparqlQueryProcessor queryProcessor, ISparqlUpdateProcessor updateProcessor)
 {
     this._queryProcessor = queryProcessor;
     this._updateProcessor = updateProcessor;
 }
예제 #37
0
파일: Query.cs 프로젝트: jbunzel/MvcRQ_git
 public ProcessorBooleanQuery(String query, ISparqlQueryProcessor processor)
     : base(query)
 {
     this._processor = processor;
 }
        public DotNetRdfDataObjectContext(ConnectionString connectionString)
        {
            try
            {
                _configuration = LoadConfiguration(connectionString.Configuration);
            }
            catch (Exception ex)
            {
                throw new BrightstarClientException(
                    String.Format("Error loading DotNetRDF configuration from {0}.", connectionString.Configuration), ex);
            }
            _configuredStoreName = connectionString.StoreName;
            if (!String.IsNullOrEmpty(connectionString.DnrStore))
            {
                var configObject = GetConfigurationObject(connectionString.DnrStore);
                if (configObject is IUpdateableTripleStore)
                {
                    _updateProcessor = new SimpleUpdateProcessor(configObject as IUpdateableTripleStore);
                }
                else if (configObject is IInMemoryQueryableStore)
                {
                    _updateProcessor = new LeviathanUpdateProcessor(configObject as IInMemoryQueryableStore);
                }
                else if (configObject is IStorageProvider)
                {
                    _updateProcessor = new GenericUpdateProcessor(configObject as IStorageProvider);
                }
                else
                {
                    throw new BrightstarClientException(
                        "Could not create a SPARQL Update processor for the configured store.");
                }

                if (configObject is INativelyQueryableStore)
                {
                    _queryProcessor = new SimpleQueryProcessor(configObject as INativelyQueryableStore);
                }
                else if (configObject is IInMemoryQueryableStore)
                {
                    _queryProcessor = new LeviathanQueryProcessor(configObject as IInMemoryQueryableStore);
                }
                else if (configObject is IQueryableStorage)
                {
                    _queryProcessor = new GenericQueryProcessor(configObject as IQueryableStorage);
                }
                else
                {
                    throw new BrightstarClientException(
                        "Could not create a SPARQL Query processor for the configured store.");
                }
            }
            else
            {
                if (String.IsNullOrEmpty(connectionString.DnrQuery) ||
                    String.IsNullOrEmpty(connectionString.DnrUpdate))
                {
                    throw new BrightstarClientException("DotNetRDF connection requires either a Store property or a Query and an Update property.");
                }

                var queryObject = GetConfigurationObject(connectionString.DnrQuery);
                if (queryObject == null)
                {
                    throw new BrightstarClientException("The configured Query property of the connection string could not be resolved.");
                }
                if (queryObject is ISparqlQueryProcessor)
                {
                    _queryProcessor = queryObject as ISparqlQueryProcessor;
                }
                else if (queryObject is SparqlRemoteEndpoint)
                {
                    _queryProcessor = new RemoteQueryProcessor(queryObject as SparqlRemoteEndpoint);
                }
                else
                {
                    throw new BrightstarClientException(
                        String.Format("Could not create a SPARQL Query processor from the configured Query property. Expected instance of {0} or {1}. Got an instance of {2}",
                        typeof(ISparqlQueryProcessor).FullName, typeof(SparqlRemoteEndpoint).FullName, queryObject.GetType().FullName));
                }

                var updateObject = GetConfigurationObject(connectionString.DnrUpdate);
                if (updateObject == null)
                {
                    throw new BrightstarClientException("The configured Update property of the connection string could not be resolved.");
                }
                if (updateObject is ISparqlUpdateProcessor)
                {
                    _updateProcessor = queryObject as ISparqlUpdateProcessor;
                }
#if !WINDOWS_PHONE && !PORTABLE
                else if (updateObject is SparqlRemoteUpdateEndpoint)
                {
                    _updateProcessor = new RemoteUpdateProcessor(updateObject as SparqlRemoteUpdateEndpoint);
                }
#endif
                else
                {
                    throw new BrightstarClientException(
                        String.Format("Could not create a SPARQL Update processor from the configured Update property. Expected instance of {0} or {1}. Got an instance of {2}",
                        typeof(ISparqlUpdateProcessor).FullName, typeof(SparqlRemoteUpdateEndpoint).FullName, updateObject.GetType().FullName));
                }
            }
        }
예제 #39
0
 private SparqlResultSet QueryWithResults(SparqlQuery q, ISparqlQueryProcessor processor)
 {
     Object results = processor.ProcessQuery(q);
     if (results is SparqlResultSet)
     {
         return (SparqlResultSet)results;
     }
     else
     {
         Assert.Fail("Query did not produce a Result Set as expected");
     }
     return null;
 }
예제 #40
0
 private IGraph QueryWithGraph(SparqlQuery q, ISparqlQueryProcessor processor)
 {
     Object results = processor.ProcessQuery(q);
     if (results is IGraph)
     {
         return (IGraph)results;
     }
     else
     {
         Assert.Fail("Query did not produce a Graph as expected");
     }
     return null;
 }
예제 #41
0
 public LinqQueryProcessor(ISparqlQueryProcessor processor)
 {
     this._underlyingProcessor = processor;
 }
예제 #42
0
 /// <summary>
 /// Creates a new LINQ Triple Store that operates over a given pair of SPARQL Processors
 /// </summary>
 /// <param name="queryProcessor">Query Processor</param>
 /// <param name="updateProcessor">Update Processor</param>
 public LinqTripleStore(ISparqlQueryProcessor queryProcessor, ISparqlUpdateProcessor updateProcessor)
     : this(new LinqQueryProcessor(queryProcessor), new LinqUpdateProcessor(updateProcessor), LinqQueryMethod.CustomSparql) { }
예제 #43
0
 public SparqlUpdatableStore(ISparqlQueryProcessor queryProcessor, ISparqlUpdateProcessor updateProcessor)
 {
     _queryProcessor = queryProcessor;
     _updateProcessor = updateProcessor;
 }
예제 #44
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");
                }
            }
        }
예제 #45
0
 /// <summary>
 /// Creates a new Protocol to Update Processor
 /// </summary>
 /// <param name="queryProcessor">Query Processor</param>
 /// <param name="updateProcessor">Update Processor</param>
 public ProtocolToUpdateProcessor(ISparqlQueryProcessor queryProcessor, ISparqlUpdateProcessor updateProcessor)
 {
     this._queryProcessor  = queryProcessor;
     this._updateProcessor = updateProcessor;
 }
        public DotNetRdfDataObjectContext(ConnectionString connectionString)
        {
            try
            {
                _configuration = LoadConfiguration(connectionString.Configuration);
            }
            catch (Exception ex)
            {
                throw new BrightstarClientException(
                    String.Format("Error loading DotNetRDF configuration from {0}.", connectionString.Configuration), ex);
            }
            _configuredStoreName = connectionString.StoreName;
            if (!String.IsNullOrEmpty(connectionString.DnrStore))
            {
                var configObject = GetConfigurationObject(connectionString.DnrStore);
                if (configObject is IUpdateableTripleStore)
                {
                    _updateProcessor = new SimpleUpdateProcessor(configObject as IUpdateableTripleStore);
                }
                else if (configObject is IInMemoryQueryableStore)
                {
                    _updateProcessor = new LeviathanUpdateProcessor(configObject as IInMemoryQueryableStore);
                }
                else if (configObject is IStorageProvider)
                {
                    _updateProcessor = new GenericUpdateProcessor(configObject as IStorageProvider);
                }
                else
                {
                    throw new BrightstarClientException(
                        "Could not create a SPARQL Update processor for the configured store.");
                }

                if (configObject is INativelyQueryableStore)
                {
                    _queryProcessor = new SimpleQueryProcessor(configObject as INativelyQueryableStore);
                }
                else if (configObject is IInMemoryQueryableStore)
                {
                    _queryProcessor = new LeviathanQueryProcessor(configObject as IInMemoryQueryableStore);
                }
                else if (configObject is IQueryableStorage)
                {
                    _queryProcessor = new GenericQueryProcessor(configObject as IQueryableStorage);
                }
                else
                {
                    throw new BrightstarClientException(
                        "Could not create a SPARQL Query processor for the configured store.");
                }
            }
            else
            {
                if (String.IsNullOrEmpty(connectionString.DnrQuery) ||
                    String.IsNullOrEmpty(connectionString.DnrUpdate))
                {
                    throw new BrightstarClientException("DotNetRDF connection requires either a Store property or a Query and an Update property.");
                }

                _queryProcessor = GetConfigurationObject(connectionString.DnrQuery) as ISparqlQueryProcessor;
                if (_queryProcessor == null)
                {
                    throw new BrightstarClientException("Could not create a SPARQL Query processor from the configured Query property.");
                }
                _updateProcessor = GetConfigurationObject(connectionString.DnrUpdate) as ISparqlUpdateProcessor;
                if (_updateProcessor == null)
                {
                    throw new BrightstarClientException("Could not create a SPARQL Update processor from the configured Update property.");
                }
            }
        }