Exemplo n.º 1
0
        public void SELECTUnionOrderByClauses()
        {
            var expectedQuery = "SELECT ?uri, ?label WHERE {{ ?uri <http://www.w3.org/2000/01/rdf-schema#label> ?label } {<http://dbpedia.org/resource/Paris> <http://www.w3.org/2000/01/rdf-schema#label> ?label} UNION {<http://dbpedia.org/resource/Montreal> <http://www.w3.org/2000/01/rdf-schema#label> ?label}} ORDER BY ASC(?label)";
            var subject       = new UriNode("http://dbpedia.org/resource/Paris");
            var predicate     = new UriNode("http://www.w3.org/2000/01/rdf-schema#label");
            var obj           = new VariableNode("label");
            var triple        = new Triple(subject, predicate, obj);
            var triples       = new List <Triple> {
                triple
            };

            subject = new UriNode("http://dbpedia.org/resource/Montreal");
            triple  = new Triple(subject, predicate, obj);
            triples.Add(triple);
            var unionClause = new dotNetSPARQL.Query.UnionClause(triples);

            triple = new Triple(
                new VariableNode("uri"),
                new UriNode("http://www.w3.org/2000/01/rdf-schema#label"),
                new VariableNode("label"));
            var orderByClause = new dotNetSPARQL.Query.OrderByClause("label");
            var select        = new dotNetSPARQL.Query.Select(new List <Triple>()
            {
                triple
            }, new dotNetSPARQL.Query.BaseClause[] { orderByClause, unionClause }, new string[] { "uri", "label" });

            Assert.AreEqual(expectedQuery, select.ToString());
        }
Exemplo n.º 2
0
        public void SELECTPredicateVariableNoLimit()
        {
            var expectedQuery = "SELECT DISTINCT ?predicate WHERE { <http://dbpedia.org/resource/Family_Guy> ?predicate <http://dbpedia.org/resource/Seth_MacFarlane> }";
            var subject       = new UriNode(new Uri("http://dbpedia.org/resource/Family_Guy"));
            var predicate     = new VariableNode("predicate");
            var obj           = new UriNode(new Uri("http://dbpedia.org/resource/Seth_MacFarlane"));
            var triple        = new Triple(subject, predicate, obj);

            var query = new dotNetSPARQL.Query.Select(triple, "predicate", true);

            Assert.AreEqual(expectedQuery, query.ToString());
        }
Exemplo n.º 3
0
        public void SELECTSubjectVariableNoLimit()
        {
            var expectedQuery = "SELECT DISTINCT ?subject WHERE { ?subject <http://dbpedia.org/ontology/author> <http://dbpedia.org/resource/Seth_MacFarlane> }";

            var subject   = new VariableNode("subject");
            var predicate = new UriNode(new Uri("http://dbpedia.org/ontology/author"));
            var obj       = new UriNode(new Uri("http://dbpedia.org/resource/Seth_MacFarlane"));
            var triple    = new Triple(subject, predicate, obj);

            var query = new dotNetSPARQL.Query.Select(triple, "subject", true);

            Assert.AreEqual(expectedQuery, query.ToString());
        }
Exemplo n.º 4
0
        public void SELECTObjectVariableNoLimit()
        {
            var expectedQuery = "SELECT DISTINCT ?uri WHERE { <http://dbpedia.org/resource/Paris> <http://dbpedia.org/ontology/mayor> ?uri }";

            var subject   = new UriNode(new Uri("http://dbpedia.org/resource/Paris"));
            var predicate = new UriNode(new Uri("http://dbpedia.org/ontology/mayor"));
            var obj       = new VariableNode("uri");
            var triple    = new Triple(subject, predicate, obj);

            var query = new dotNetSPARQL.Query.Select(triple, "uri", true);

            Assert.AreEqual(expectedQuery, query.ToString());
        }
Exemplo n.º 5
0
        public void SELECTPredicateObjectVariableLimit100()
        {
            var expectedQuery = "SELECT DISTINCT ?predicate, ?object WHERE { <http://dbpedia.org/resource/Family_Guy> ?predicate ?object } LIMIT 100";

            var subject   = new UriNode(new Uri("http://dbpedia.org/resource/Family_Guy"));
            var predicate = new VariableNode("predicate");
            var obj       = new VariableNode("object");
            var triple    = new Triple(subject, predicate, obj);
            var variables = new string[] { "predicate", "object" };

            var query = new dotNetSPARQL.Query.Select(new List <Triple> {
                triple
            }, variables, true, 100);

            Assert.AreEqual(expectedQuery, query.ToString());
        }
Exemplo n.º 6
0
        public void SELECTSubjectPredicateVariableNoLimit()
        {
            var expectedQuery = "SELECT DISTINCT ?subject, ?predicate WHERE { ?subject ?predicate <http://dbpedia.org/resource/Paris> }";

            var subject   = new VariableNode("subject");
            var predicate = new VariableNode("predicate");
            var obj       = new UriNode(new Uri("http://dbpedia.org/resource/Paris"));
            var triple    = new Triple(subject, predicate, obj);
            var variables = new string[] { "subject", "predicate" };

            var query = new dotNetSPARQL.Query.Select(new List <Triple> {
                triple
            }, variables, true);

            Assert.AreEqual(expectedQuery, query.ToString());
        }
Exemplo n.º 7
0
        public void SELECTMultipleTriples()
        {
            var expectedQuery = "SELECT DISTINCT ?object WHERE { <http://dbpedia.org/resource/Family_Guy> <http://dbpedia.org/ontology/author> ?uri . ?uri <http://dbpedia.org/ontology/birthPlace> ?object }";

            var subject      = new UriNode("http://dbpedia.org/resource/Family_Guy");
            var predicate    = new VariableNode("predicate");
            var obj          = new VariableNode("object");
            var firstTriple  = new Triple(new UriNode("http://dbpedia.org/resource/Family_Guy"), new UriNode("http://dbpedia.org/ontology/author"), new VariableNode("uri"));
            var secondTriple = new Triple(new VariableNode("uri"), new UriNode("http://dbpedia.org/ontology/birthPlace"), new VariableNode("object"));
            var variables    = new string[] { "object" };

            var query = new dotNetSPARQL.Query.Select(new List <Triple> {
                firstTriple, secondTriple
            }, variables, true);

            Assert.AreEqual(expectedQuery, query.ToString());
        }
Exemplo n.º 8
0
        public void ORDERBYQuery()
        {
            var expectedQuery = "SELECT WHERE { <http://dbpedia.org/resource/Paris> <http://dbpedia.org/ontology/wikiPageExternalLink> ?uri } ORDER BY DESC(?uri)";

            var subject       = new UriNode("http://dbpedia.org/resource/Paris");
            var predicate     = new UriNode("http://dbpedia.org/ontology/wikiPageExternalLink");
            var obj           = new VariableNode("uri");
            var triple        = new Triple(subject, predicate, obj);
            var orderByClause = new dotNetSPARQL.Query.OrderByClause("uri", true);

            var clauses = new dotNetSPARQL.Query.BaseClause[] { orderByClause };
            var triples = new List <Triple> {
                triple
            };
            var selectCountQuery = new dotNetSPARQL.Query.Select(
                triples, clauses, new string[0]);

            Assert.AreEqual(expectedQuery, selectCountQuery.ToString());
        }