コード例 #1
0
        private UnionGraph GetUnionGraph()
        {
            SparqlQuery restaurantsQuery = GetRestaurantsQuery();
            SparqlQuery hotelsQuery = GetHotelsQuery();
            SparqlQuery museumsQuery = GetGeneralQuery("Museum");
            SparqlQuery hospitalsQuery = GetGeneralQuery("Hospital");
            SparqlQuery shopsQuery = GetGeneralQuery("ShoppingMall");

            Uri uri = new Uri(@"http://dbpedia.org/sparql");
            SparqlRemoteEndpoint endPoint = new SparqlRemoteEndpoint(uri);
            ISparqlQueryProcessor processor = new RemoteQueryProcessor(endPoint);
            Graph restaurantsGraph = (Graph)processor.ProcessQuery(restaurantsQuery);
            Graph hotelsGraph = (Graph)processor.ProcessQuery(hotelsQuery);
            Graph museumsGraph = (Graph)processor.ProcessQuery(museumsQuery);
            Graph hospitalsGraph = (Graph)processor.ProcessQuery(hospitalsQuery);
            Graph shopsGraph = (Graph)processor.ProcessQuery(shopsQuery);

            List<Graph> all = new List<Graph>();
            all.Add(restaurantsGraph);
            all.Add(hotelsGraph);
            all.Add(museumsGraph);
            all.Add(hospitalsGraph);
            all.Add(shopsGraph);
            return new UnionGraph(new Graph(), all);
        }
コード例 #2
0
        private static IDataObjectContext MakeSparqlDataObjectContext(ConnectionString connectionString)
        {
            var queryEndpoint = new SparqlRemoteEndpoint(new Uri(connectionString.DnrQuery));
            if (!String.IsNullOrEmpty(connectionString.UserName) && !String.IsNullOrEmpty(connectionString.Password))
            {
                queryEndpoint.SetCredentials(connectionString.UserName, connectionString.Password);
            }
            var queryProcessor = new RemoteQueryProcessor(queryEndpoint);

            ISparqlUpdateProcessor updateProcessor = null;
            if (!String.IsNullOrEmpty(connectionString.DnrUpdate))
            {
#if PORTABLE || SILVERLIGHT
                throw new NotSupportedException("The PCL and mobile builds of BrightstarDB do not currently support stores that use SPARQL Update. The store may be opened as a read-only store by removing the update= parameter in the connection string.");
#else
                var updateEndpoint = new SparqlRemoteUpdateEndpoint(new Uri(connectionString.DnrUpdate));
                if (!String.IsNullOrEmpty(connectionString.UserName) && !String.IsNullOrEmpty(connectionString.Password))
                {
                    updateEndpoint.SetCredentials(connectionString.UserName, connectionString.Password);
                }
                updateProcessor = new RemoteUpdateProcessor(updateEndpoint);
#endif
            }
            return new SparqlDataObjectContext(queryProcessor, updateProcessor, connectionString.OptimisticLocking);
        }
コード例 #3
0
        /// <summary>
        /// Tries to load a SPARQL Query Processor based on information from the Configuration Graph
        /// </summary>
        /// <param name="g">Configuration Graph</param>
        /// <param name="objNode">Object Node</param>
        /// <param name="targetType">Target Type</param>
        /// <param name="obj">Output Object</param>
        /// <returns></returns>
        public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj)
        {
            obj = null;
            ISparqlQueryProcessor processor = null;
            INode storeObj;
            Object temp;

            switch (targetType.FullName)
            {
                case LeviathanQueryProcessor:
                    INode datasetObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUsingDataset));
                    if (datasetObj != null)
                    {
                        temp = ConfigurationLoader.LoadObject(g, datasetObj);
                        if (temp is ISparqlDataset)
                        {
                            processor = new LeviathanQueryProcessor((ISparqlDataset)temp);
                        }
                        else
                        {
                            throw new DotNetRdfConfigurationException("Unable to load the Leviathan Query Processor identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingDataset property points to an Object that cannot be loaded as an object which implements the ISparqlDataset interface");
                        }
                    }
                    else
                    {
                        //If no dnr:usingDataset try dnr:usingStore instead
                        storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUsingStore));
                        if (storeObj == null) return false;
                        temp = ConfigurationLoader.LoadObject(g, storeObj);
                        if (temp is IInMemoryQueryableStore)
                        {
                            processor = new LeviathanQueryProcessor((IInMemoryQueryableStore)temp);
                        }
                        else
                        {
                            throw new DotNetRdfConfigurationException("Unable to load the Leviathan Query Processor identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingStore property points to an Object that cannot be loaded as an object which implements the IInMemoryQueryableStore interface");
                        }
                    }
                    break;

                case SimpleQueryProcessor:
                    storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUsingStore));
                    if (storeObj == null) return false;
                    temp = ConfigurationLoader.LoadObject(g, storeObj);
                    if (temp is INativelyQueryableStore)
                    {
                        processor = new SimpleQueryProcessor((INativelyQueryableStore)temp);
                    }
                    else
                    {
                        throw new DotNetRdfConfigurationException("Unable to load the Simple Query Processor identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingStore property points to an Object that cannot be loaded as an object which implements the INativelyQueryableStore interface");
                    }
                    break;

#if !NO_STORAGE

                case GenericQueryProcessor:
                    INode managerObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyGenericManager));
                    if (managerObj == null) return false;
                    temp = ConfigurationLoader.LoadObject(g, managerObj);
                    if (temp is IQueryableGenericIOManager)
                    {
                        processor = new GenericQueryProcessor((IQueryableGenericIOManager)temp);
                    }
                    else
                    {
                        throw new DotNetRdfConfigurationException("Unable to load the Generic Query Processor identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:genericManager property points to an Object that cannot be loaded as an object which implements the IQueryableGenericIOManager interface");
                    }
                    break;

#endif

#if !SILVERLIGHT
                case RemoteQueryProcessor:
                    INode endpointObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyEndpoint));
                    if (endpointObj == null) return false;
                    temp = ConfigurationLoader.LoadObject(g, endpointObj);
                    if (temp is SparqlRemoteEndpoint)
                    {
                        processor = new RemoteQueryProcessor((SparqlRemoteEndpoint)temp);
                    }
                    else
                    {
                        throw new DotNetRdfConfigurationException("Unable to load the Remote Query Processor identified by the Node '" + objNode.ToSafeString() + "' as the value given for the dnr:endpoint property points to an Object that cannot be loaded as an object which is a SparqlRemoteEndpoint");
                    }
                    break;


                case PelletQueryProcessor:
                    String server = ConfigurationLoader.GetConfigurationValue(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyServer));
                    if (server == null) return false;
                    String kb = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyStore));
                    if (kb == null) return false;

                    processor = new PelletQueryProcessor(new Uri(server), kb);
                    break;
#endif
            }

            obj = processor;
            return (processor != null);
        }
コード例 #4
0
ファイル: Utils.cs プロジェクト: backpackerrecommender/bapr
        public static Collection<BaprLocation> ParseSparqlQuery(SparqlParameterizedString queryString, string endpointUrl)
        {
            try
            {
                SparqlQueryParser parser = new SparqlQueryParser();
                SparqlQuery query = parser.ParseFromString(queryString);

                Uri uri = new Uri(endpointUrl);
                SparqlRemoteEndpoint endPoint = new SparqlRemoteEndpoint(uri);
                ISparqlQueryProcessor processor = new RemoteQueryProcessor(endPoint);
                return BaprAPI.Utils.Utils.ExecuteQuery(processor, query);
            }
            catch (VDS.RDF.RdfException ex)
            {

            }
            return new Collection<BaprLocation>();
        }