Esempio n. 1
0
        public void TestSelectProvidesStatements()
        {
            SparqlQuery query = new SparqlQuery("SELECT ?s ?p ?o WHERE { ?s ?p ?o . }");

            string[] vars = query.GetGlobalScopeVariableNames();

            Assert.IsTrue(query.ProvidesStatements());
            Assert.AreEqual("s", vars[0]);
            Assert.AreEqual("p", vars[1]);
            Assert.AreEqual("o", vars[2]);

            query = new SparqlQuery("SELECT * WHERE { ?s ?p ?o . }");

            vars = query.GetGlobalScopeVariableNames();

            Assert.IsTrue(query.ProvidesStatements());
            Assert.AreEqual("s", vars[0]);
            Assert.AreEqual("p", vars[1]);
            Assert.AreEqual("o", vars[2]);

            query = new SparqlQuery("SELECT ?s ?p ?o WHERE { ?s ?p ?o . ?x ?y ?z . }");

            vars = query.GetGlobalScopeVariableNames();

            Assert.IsTrue(query.ProvidesStatements());
            Assert.AreEqual("s", vars[0]);
            Assert.AreEqual("p", vars[1]);
            Assert.AreEqual("o", vars[2]);

            query = new SparqlQuery("SELECT * WHERE { ?s ?p ?o . ?x ?y ?z . }");

            vars = query.GetGlobalScopeVariableNames();

            Assert.IsFalse(query.ProvidesStatements());
            Assert.AreEqual(6, vars.Length);

            query = new SparqlQuery(@"
                PREFIX nie: <http://www.semanticdesktop.org/ontologies/2007/01/19/nie#>
                PREFIX artpro: <http://semiodesk.com/artivitypro/1.0/>

                SELECT ?s ?p ?o WHERE
                {
                       ?s ?p ?o .
                       ?s a artpro:Project .
                       ?s nie:lastModified ?lastModified .

                       FILTER isIRI(?s)
                }
                ORDER BY DESC(?lastModified)");

            vars = query.GetGlobalScopeVariableNames();

            Assert.IsTrue(query.ProvidesStatements());
            Assert.AreEqual("s", vars[0]);
            Assert.AreEqual("p", vars[1]);
            Assert.AreEqual("o", vars[2]);
        }
Esempio n. 2
0
 public IEnumerable <T> GetResources <T>() where T : Resource
 {
     if (_query.ProvidesStatements())
     {
         return(GenerateResources <T>());
     }
     else
     {
         throw new ArgumentException("Error: The given SELECT query cannot be resolved into statements.");
     }
 }