예제 #1
0
        private T Get <T>(Uri uri)
            where T : class
        {
            var query = new SparqlParameterizedString(Resource.AsString("SparqlQueries.GetSingle.rq"));

            query.SetUri("source", uri);
            var graph = (IGraph)this.queryProcessor.Value.ProcessQuery(this.parser.ParseFromString(query.ToString()));

            if (graph.Triples.Count > 0)
            {
                var dataset = StringWriter.Write(graph, new NTriplesWriter(NTriplesSyntax.Rdf11));

                return(this.serializer.Deserialize <T>(dataset));
            }

            return(null);
        }
예제 #2
0
        private async Task <TCollection> GetAll <T, TCollection>(Uri collectionUri, int page, int pageSize = 10)
            where T : class
            where TCollection : SearchableCollection <T>, new()
        {
            var query = new SparqlParameterizedString(Resource.AsString("SparqlQueries.GetSourcesPage.rq"));

            query.SetUri("type", GetTypeUri(typeof(T)));
            query.SetUri("collection", collectionUri);
            query.SetLiteral("page", page);
            query.SetLiteral("limit", pageSize);
            query.SetLiteral("offset", (page - 1) * pageSize);
            var graph = (IGraph)this.queryProcessor.Value.ProcessQuery(this.parser.ParseFromString(query.ToString()));

            if (graph.Triples.Count > 0)
            {
                var dataset = StringWriter.Write(graph, new NTriplesWriter(NTriplesSyntax.Rdf11));

                return(this.serializer.Deserialize <TCollection>(dataset));
            }

            return(new TCollection());
        }