コード例 #1
0
ファイル: BaseController.cs プロジェクト: robertbrook/OData
        public static object Execute(ODataQueryOptions options, string sparqlEndpoint, string nameSpace)
        {
            Uri    NamespaceUri = new Uri(nameSpace);
            string queryString  = new SparqlBuilder(options, NamespaceUri).BuildSparql();
            IGraph graph        = null;

            using (var connector = new SparqlConnector(new Uri(sparqlEndpoint)))
            {
                graph = connector.Query(queryString) as IGraph;
            }

            RdfSerializer serializer = new RdfSerializer();
            IEnumerable <BaseResource> ontologyInstances = serializer.Deserialize(graph, typeof(Person).Assembly, NamespaceUri);

            return(ontologyInstances);
        }
コード例 #2
0
ファイル: BaseController.cs プロジェクト: ukparliament/OData
        public static object Execute(ODataQueryOptions options, string sparqlEndpoint, string nameSpace)
        {
            Uri    namespaceUri = new Uri(nameSpace);
            string queryString  = new SparqlBuilder(options, namespaceUri).BuildSparql();

            if (options.Count != null && options.Count.Value)
            {
                string selectStr;
                var    entitySeg = options.Context.Path.Segments.Last() as EntitySetSegment;;
                if (entitySeg != null)
                {
                    selectStr = $" SELECT (count(?{entitySeg.EntitySet.Name}) as ?count) ";
                }
                else
                {
                    var seg = options.Context.Path.Segments.Last() as NavigationPropertySegment;
                    selectStr = $" SELECT (count(?{seg.NavigationProperty.Name}) as ?count) ";
                }
                queryString = queryString.Substring(0, queryString.IndexOf("CONSTRUCT")) +
                              selectStr + queryString.Substring(queryString.IndexOf("WHERE"));

                string count = null;
                using (var connector = new SparqlConnector(new Uri(sparqlEndpoint)))
                {
                    var results = connector.Query(queryString) as SparqlResultSet;
                    foreach (var result in results)
                    {
                        count = (result["count"] as LiteralNode).Value;
                    }
                }
                return(count);
            }
            else
            {
                IGraph graph = null;
                using (var connector = new SparqlConnector(new Uri(sparqlEndpoint)))
                {
                    graph = connector.Query(queryString) as IGraph;
                }

                RdfSerializer serializer = new RdfSerializer();
                IEnumerable <BaseResource> ontologyInstances = serializer.Deserialize(graph, typeof(Person).Assembly, namespaceUri);

                return(ontologyInstances);
            }
        }