public void SparqlGroupByAssignmentSimple2() { String query = "SELECT ?x (COUNT(?p) AS ?predicates) WHERE { ?s ?p ?o } GROUP BY ?s AS ?x"; SparqlQueryParser parser = new SparqlQueryParser(); SparqlQuery q = parser.ParseFromString(query); SparqlFormatter formatter = new SparqlFormatter(); Console.WriteLine(formatter.Format(q)); Console.WriteLine(); QueryableGraph g = new QueryableGraph(); FileLoader.Load(g, "resources\\InferenceTest.ttl"); Object results = g.ExecuteQuery(q); if (results is SparqlResultSet) { SparqlResultSet rset = (SparqlResultSet)results; TestTools.ShowResults(rset); Assert.True(rset.All(r => r.HasValue("x") && !r.HasValue("s") && r.HasValue("predicates")), "All Results should have a ?x and ?predicates variables and no ?s variable"); } else { Assert.True(false, "Didn't get a Result Set as expected"); } }
public void SparqlGroupByAssignmentExpression3() { if (!TestConfigManager.GetSettingAsBoolean(TestConfigManager.UseRemoteParsing)) { throw new SkipTestException("Test Config marks Remote Parsing as unavailable, test cannot be run"); } String query = "SELECT ?lang (SAMPLE(?o) AS ?example) WHERE { ?s ?p ?o . FILTER(ISLITERAL(?o)) } GROUP BY (LANG(?o) AS ?lang) HAVING LANGMATCHES(?lang, \"*\")"; SparqlQueryParser parser = new SparqlQueryParser(); SparqlQuery q = parser.ParseFromString(query); SparqlFormatter formatter = new SparqlFormatter(); Console.WriteLine(formatter.Format(q)); Console.WriteLine(); QueryableGraph g = new QueryableGraph(); UriLoader.Load(g, new Uri("http://dbpedia.org/resource/Southampton")); Object results = g.ExecuteQuery(q); if (results is SparqlResultSet) { SparqlResultSet rset = (SparqlResultSet)results; TestTools.ShowResults(rset); Assert.True(rset.All(r => r.HasValue("lang") && r.HasValue("example")), "All Results should have a ?lang and a ?example variable"); } else { Assert.True(false, "Didn't get a Result Set as expected"); } }
public void SparqlGroupByAssignmentExpression3() { String query = "SELECT ?lang (SAMPLE(?o) AS ?example) WHERE { ?s ?p ?o . FILTER(ISLITERAL(?o)) } GROUP BY (LANG(?o) AS ?lang) HAVING LANGMATCHES(?lang, \"*\")"; SparqlQueryParser parser = new SparqlQueryParser(); SparqlQuery q = parser.ParseFromString(query); SparqlFormatter formatter = new SparqlFormatter(); Console.WriteLine(formatter.Format(q)); Console.WriteLine(); QueryableGraph g = new QueryableGraph(); UriLoader.Load(g, new Uri("http://dbpedia.org/resource/Southampton")); Object results = g.ExecuteQuery(q); if (results is SparqlResultSet) { SparqlResultSet rset = (SparqlResultSet)results; TestTools.ShowResults(rset); Assert.IsTrue(rset.All(r => r.HasValue("lang") && r.HasValue("example")), "All Results should have a ?lang and a ?example variable"); } else { Assert.Fail("Didn't get a Result Set as expected"); } }
public void SparqlGroupByAssignmentExpression() { String query = "SELECT ?s ?sum WHERE { ?s ?p ?o } GROUP BY ?s (1 + 2 AS ?sum)"; SparqlQueryParser parser = new SparqlQueryParser(); SparqlQuery q = parser.ParseFromString(query); SparqlFormatter formatter = new SparqlFormatter(); Console.WriteLine(formatter.Format(q)); Console.WriteLine(); QueryableGraph g = new QueryableGraph(); FileLoader.Load(g, "InferenceTest.ttl"); Object results = g.ExecuteQuery(q); if (results is SparqlResultSet) { SparqlResultSet rset = (SparqlResultSet)results; TestTools.ShowResults(rset); Assert.IsTrue(rset.All(r => r.HasValue("s") && r.HasValue("sum")), "All Results should have a ?s and a ?sum variable"); } else { Assert.Fail("Didn't get a Result Set as expected"); } }
public void SparqlGroupByAssignmentSimple2() { String query = "SELECT ?x (COUNT(?p) AS ?predicates) WHERE { ?s ?p ?o } GROUP BY ?s AS ?x"; SparqlQueryParser parser = new SparqlQueryParser(); SparqlQuery q = parser.ParseFromString(query); SparqlFormatter formatter = new SparqlFormatter(); Console.WriteLine(formatter.Format(q)); Console.WriteLine(); QueryableGraph g = new QueryableGraph(); FileLoader.Load(g, "InferenceTest.ttl"); Object results = g.ExecuteQuery(q); if (results is SparqlResultSet) { SparqlResultSet rset = (SparqlResultSet)results; TestTools.ShowResults(rset); Assert.IsTrue(rset.All(r => r.HasValue("x") && !r.HasValue("s") && r.HasValue("predicates")), "All Results should have a ?x and ?predicates variables and no ?s variable"); } else { Assert.Fail("Didn't get a Result Set as expected"); } }
public void SparqlGroupByWithValues2() { String query = @"SELECT ?a ?b WHERE { VALUES ( ?a ?b ) { ( 1 2 ) ( 1 UNDEF ) ( UNDEF 2 ) } } GROUP BY ?a ?b"; QueryableGraph g = new QueryableGraph(); SparqlResultSet results = g.ExecuteQuery(query) as SparqlResultSet; Assert.NotNull(results); Assert.False(results.IsEmpty); Assert.Equal(3, results.Count); }
public void SparqlGroupByWithValues1() { String query = @"SELECT ?a WHERE { VALUES ( ?a ) { ( 1 ) ( 2 ) } } GROUP BY ?a"; QueryableGraph g = new QueryableGraph(); SparqlResultSet results = g.ExecuteQuery(query) as SparqlResultSet; Assert.IsNotNull(results); Assert.IsFalse(results.IsEmpty); Assert.AreEqual(2, results.Count); }
public void SparqlSimplePropertyPathDuplicates() { QueryableGraph g = new QueryableGraph(); FileLoader.Load(g, "property-path-duplicates.ttl"); String foafPrefix = "PREFIX foaf: <http://xmlns.com/foaf/0.1/>\n"; String twoStepQuery = foafPrefix + "SELECT ?x ?y WHERE { ?x foaf:knows ?z . ?z foaf:knows ?y }"; String pathQuery = foafPrefix + "SELECT ?x ?y WHERE {?x foaf:knows{2} ?y}"; Object resultsA = g.ExecuteQuery(twoStepQuery); Object resultsB = g.ExecuteQuery(pathQuery); Console.WriteLine("Two Step Query"); Console.WriteLine(); Console.WriteLine(twoStepQuery); TestTools.ShowResults(resultsA); Console.WriteLine(); Console.WriteLine("Equivalent Path Query"); Console.WriteLine(); Console.WriteLine(pathQuery); TestTools.ShowResults(resultsB); Console.WriteLine(); Assert.AreEqual(resultsA, resultsB, "Result Sets should have been equivalent"); }