public void TestDBPediaQuery() { IStore store = StoreFactory.CreateSparqlEndpointStore(new Uri("http://live.dbpedia.org/sparql")); IModel model = store.GetModel(new Uri("http://dbpedia.org")); SparqlQuery query = new SparqlQuery(@"SELECT ?s ?p ?o WHERE { ?s ?p ?o . ?s <http://dbpedia.org/ontology/wikiPageID> @id . }"); query.Bind("@id", 445980); Assert.AreEqual(1, model.ExecuteQuery(query).GetResources().Count()); }
public void TestSetLimit() { SparqlQuery query = new SparqlQuery(@" SELECT ?s0 ?p0 ?o0 WHERE { ?s0 ?p0 ?o0 . { SELECT DISTINCT ?s0 WHERE { ?s ?p ?o. ?s @type @class . { ?s ?p1 ?o1 . FILTER ISLITERAL(?o1) . FILTER REGEX(STR(?o1), '', 'i') . } UNION { ?s ?p1 ?s1 . ?s1 ?p2 ?o2 . FILTER ISLITERAL(?o2) . FILTER REGEX(STR(?o2), '', 'i') . } } ORDER BY ?o } }"); query.Bind("@type", rdf.type); query.Bind("@class", tmo.Task); MethodInfo method = query.GetType().GetMethod("SetLimit", BindingFlags.NonPublic | BindingFlags.Instance); method.Invoke(query, new object[] { 10 }); ISparqlQueryResult result = Model.ExecuteQuery(query); List <Resource> resources = result.GetResources().ToList(); }
public void TestSetModel() { Regex expression = new Regex(Regex.Escape("FROM")); SparqlQuery query = new SparqlQuery("SELECT COUNT(?s) AS ?count WHERE { ?s ?p ?o . }"); Assert.IsNull(query.Model); Assert.AreEqual(0, expression.Matches(query.ToString()).Count); query.Model = Model; Assert.NotNull(query.Model); Assert.AreEqual(1, expression.Matches(query.ToString()).Count); SparqlQuery query2 = new SparqlQuery("ASK FROM <http://example.org/TestModel> WHERE { ?s ?p ?o . }"); Assert.IsNull(query2.Model); Assert.AreEqual(1, expression.Matches(query2.ToString()).Count); query2.Model = Model; Assert.IsNotNull(query2.Model); Assert.AreEqual(1, expression.Matches(query2.ToString()).Count); SparqlQuery query3 = new SparqlQuery("ASK FROM @graph WHERE { ?s ?p ?o . }"); query3.Bind("@graph", Model); Assert.IsNull(query3.Model); Assert.AreEqual(1, expression.Matches(query3.ToString()).Count); query3.Model = Model; Assert.IsNotNull(query3.Model); Assert.AreEqual(1, expression.Matches(query3.ToString()).Count); SparqlQuery query4 = new SparqlQuery("ASK FROM @graph WHERE { ?s ?p ?o . }"); query4.Model = Model; Assert.IsNotNull(query4.Model); Assert.Throws <ArgumentException>(delegate { query4.Bind("@graph", Model); }); }
public void TestQueryParameters() { SparqlQuery query = new SparqlQuery(@"SELECT ?s WHERE { ?s ?p ?o . ?s ?p @someValue . }"); query.Bind("@someValue", "Value"); string queryString = query.ToString(); Assert.IsFalse(string.IsNullOrEmpty(queryString)); query = new SparqlQuery(@"SELECT ?s WHERE { ?s ?p 'Hallo'@de . }"); queryString = query.ToString(); Assert.AreEqual(queryString, @"SELECT ?s WHERE { ?s ?p 'Hallo'@de . }"); query = new SparqlQuery(@"SELECT ?s WHERE { ?s ?p 'Hallo'@de-de . }"); queryString = query.ToString(); Assert.AreEqual(queryString, @"SELECT ?s WHERE { ?s ?p 'Hallo'@de-de . }"); }
public void TestIsOrdered() { Assert.Inconclusive("Reevaluate with more recent version of virtuoso client library."); MethodInfo isOrdered; SparqlQuery query = new SparqlQuery(@" SELECT ?s0 ?p0 ?o0 WHERE { ?s0 ?p0 ?o0 . { SELECT DISTINCT ?s0 WHERE { ?s ?p ?o. ?s @type @class . { ?s ?p1 ?o1 . FILTER ISLITERAL(?o1) . FILTER REGEX(STR(?o1), '', 'i') . } UNION { ?s ?p1 ?s1 . ?s1 ?p2 ?o2 . FILTER ISLITERAL(?o2) . FILTER REGEX(STR(?o2), '', 'i') . } } ORDER BY ?o } }"); query.Bind("@type", rdf.type); query.Bind("@class", tmo.Task); isOrdered = query.GetType().GetMethod("IsOrdered", BindingFlags.NonPublic | BindingFlags.Instance); Assert.AreEqual(true, isOrdered.Invoke(query, null)); query = new SparqlQuery(@" SELECT ?s0 ?p0 ?o0 WHERE { ?s0 ?p0 ?o0 . { SELECT DISTINCT ?s0 WHERE { ?s ?p ?o. ?s @type @class . { ?s ?p1 ?o1 . FILTER ISLITERAL(?o1) . FILTER REGEX(STR(?o1), '', 'i') . } UNION { ?s ?p1 ?s1 . ?s1 ?p2 ?o2 . FILTER ISLITERAL(?o2) . FILTER REGEX(STR(?o2), '', 'i') . } } } }"); query.Bind("@type", rdf.type); query.Bind("@class", tmo.Task); isOrdered = query.GetType().GetMethod("IsOrdered", BindingFlags.NonPublic | BindingFlags.Instance); Assert.AreEqual(false, isOrdered.Invoke(query, null)); query = new SparqlQuery(@" SELECT DISTINCT ?s0 FROM <http://semiodesk.com/id/8083cf10-5f90-40d4-b30a-c18fea31177b/> WHERE { ?s0 ?p0 ?o0 . ?s0 a nfo:Visual . ?s0 nexif:dateTime ?o1 . } ORDER BY ASC(?o1) LIMIT 50"); isOrdered = query.GetType().GetMethod("IsOrdered", BindingFlags.NonPublic | BindingFlags.Instance); Assert.AreEqual(true, isOrdered.Invoke(query, null)); }
public void TestIsOrdered() { SparqlQuery query = new SparqlQuery(@" SELECT ?s0 ?p0 ?o0 WHERE { ?s0 ?p0 ?o0 . { SELECT DISTINCT ?s0 WHERE { ?s ?p ?o . ?s @type @class . { ?s ?p1 ?o1 . FILTER ISLITERAL(?o1) . FILTER REGEX(STR(?o1), '', 'i') . } UNION { ?s ?p1 ?s1 . ?s1 ?p2 ?o2 . FILTER ISLITERAL(?o2) . FILTER REGEX(STR(?o2), '', 'i') . } } ORDER BY ?o } } "); query.Bind("@type", rdf.type); query.Bind("@class", tmo.Task); Assert.IsTrue(string.IsNullOrEmpty(query.GetRootOrderByClause())); query = new SparqlQuery(@" SELECT ?s0 ?p0 ?o0 WHERE { ?s0 ?p0 ?o0 . { SELECT DISTINCT ?s0 WHERE { ?s ?p ?o . ?s @type @class . { ?s ?p1 ?o1 . FILTER ISLITERAL(?o1) . FILTER REGEX(STR(?o1), '', 'i') . } UNION { ?s ?p1 ?s1 . ?s1 ?p2 ?o2 . FILTER ISLITERAL(?o2) . FILTER REGEX(STR(?o2), '', 'i') . } } } } "); query.Bind("@type", rdf.type); query.Bind("@class", tmo.Task); Assert.IsTrue(string.IsNullOrEmpty(query.GetRootOrderByClause())); query = new SparqlQuery(@" SELECT DISTINCT ?s0 FROM <http://semiodesk.com/id/8083cf10-5f90-40d4-b30a-c18fea31177b/> WHERE { ?s0 ?p0 ?o0 . ?s0 a <http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Visual> . ?s0 <http://www.semanticdesktop.org/ontologies/2007/05/10/nexif#dateTime> ?o1 . } ORDER BY ASC(?o1) LIMIT 50 "); Assert.IsFalse(string.IsNullOrEmpty(query.GetRootOrderByClause())); }