Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
luigi-asprino committed May 24, 2024
1 parent a89c87f commit d26e363
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,7 @@ public void testIssue280() throws URISyntaxException {
boolean tdbFolderCreated = TDBfile.mkdirs();
log.trace("Has TDB folder been deleted? {}", tdbFolderCreated);
log.debug("TDB temp location: {}", TDBLocation);
Query qs = QueryFactory.create(
"PREFIX fx: <http://sparql.xyz/facade-x/ns/> " +
"PREFIX xyz: <http://sparql.xyz/facade-x/data/> " +
"SELECT * WHERE { " +
"SERVICE <x-sparql-anything:location=" + location + ",ondisk=" + TDBLocation + "> { " +
" ?s xyz:name ?o } }");
Query qs = QueryFactory.create("PREFIX fx: <http://sparql.xyz/facade-x/ns/> " + "PREFIX xyz: <http://sparql.xyz/facade-x/data/> " + "SELECT * WHERE { " + "SERVICE <x-sparql-anything:location=" + location + ",ondisk=" + TDBLocation + "> { " + " ?s xyz:name ?o } }");

// System.out.println(location);
// System.out.println(qs.toString(Syntax.defaultSyntax));
Expand All @@ -88,9 +83,7 @@ public void testIssue280() throws URISyntaxException {
assertTrue(results.contains("Cougar Town"));


qs = QueryFactory.create(
"PREFIX fx: <http://sparql.xyz/facade-x/ns/> PREFIX xyz: <http://sparql.xyz/facade-x/data/> SELECT * WHERE { SERVICE <x-sparql-anything:> { fx:properties fx:location \"" + location + "\" ; fx:ondisk \"" + TDBLocation + "\" . " +
" ?s xyz:name ?o } }");
qs = QueryFactory.create("PREFIX fx: <http://sparql.xyz/facade-x/ns/> PREFIX xyz: <http://sparql.xyz/facade-x/data/> SELECT * WHERE { SERVICE <x-sparql-anything:> { fx:properties fx:location \"" + location + "\" ; fx:ondisk \"" + TDBLocation + "\" . " + " ?s xyz:name ?o } }");


rs = QueryExecutionFactory.create(qs, ds).execSelect();
Expand Down Expand Up @@ -134,23 +127,7 @@ public void testIssue284_2() throws URISyntaxException {
// System.out.println(ResultSetFormatter.asText(rs));


Query qs = QueryFactory.create("PREFIX fx: <http://sparql.xyz/facade-x/ns/>\n" +
"PREFIX xyz: <http://sparql.xyz/facade-x/data/>\n" +
"base <http://example.com/base/> \n" +
"\n" +
"CONSTRUCT\n" +
" {\n" +
" ?subject0 <http://example.com/id> ?0 .\n" +
" }\n" +
"WHERE\n" +
" {\n" +
" SERVICE <x-sparql-anything:location=" + location + ">\n" +
" {\n" +
" \t?s0 xyz:students/fx:anySlot ?iterator0 . \n" +
" ?iterator0 xyz:ID ?0;\n" +
" bind(fx:entity(\"http://example.com/\", ?0) as ?subject0)\n" +
" }\n" +
" }");
Query qs = QueryFactory.create("PREFIX fx: <http://sparql.xyz/facade-x/ns/>\n" + "PREFIX xyz: <http://sparql.xyz/facade-x/data/>\n" + "base <http://example.com/base/> \n" + "\n" + "CONSTRUCT\n" + " {\n" + " ?subject0 <http://example.com/id> ?0 .\n" + " }\n" + "WHERE\n" + " {\n" + " SERVICE <x-sparql-anything:location=" + location + ">\n" + " {\n" + " \t?s0 xyz:students/fx:anySlot ?iterator0 . \n" + " ?iterator0 xyz:ID ?0;\n" + " bind(fx:entity(\"http://example.com/\", ?0) as ?subject0)\n" + " }\n" + " }");

// System.out.println(qs.toString());

Expand Down Expand Up @@ -184,9 +161,7 @@ public void testIssue356() throws URISyntaxException, IOException {
public void testIssue356CLI() throws Exception {
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything", "Trace");
String query = IOUtils.toString(Objects.requireNonNull(getClass().getClassLoader().getResource("issues/issue356.sparql")).toURI(), StandardCharsets.UTF_8);
String output = SPARQLAnything.callMain(new String[]{
"-q", query
});
String output = SPARQLAnything.callMain(new String[]{"-q", query});
Assert.assertTrue(output.contains("http://www.w3.org/1999/02/22-rdf-syntax-ns#type,http://sparql.xyz/facade-x/ns/root"));
}

Expand Down Expand Up @@ -508,7 +483,7 @@ public void testIssue280_2() throws URISyntaxException {
boolean hasTDBFolderCreated = TDBfile.mkdirs();
//log.trace("Has TDB Folder been created? {}, {}", hasTDBFolderCreated, TDBfile.exists());

String queryString = "PREFIX fx: <http://sparql.xyz/facade-x/ns/> PREFIX xyz: <http://sparql.xyz/facade-x/data/> SELECT * WHERE { SERVICE <x-sparql-anything:> { fx:properties fx:location \""+location+"\" ; fx:ondisk \""+TDBLocation+"\" . ?s xyz:name ?o } }";
String queryString = "PREFIX fx: <http://sparql.xyz/facade-x/ns/> PREFIX xyz: <http://sparql.xyz/facade-x/data/> SELECT * WHERE { SERVICE <x-sparql-anything:> { fx:properties fx:location \"" + location + "\" ; fx:ondisk \"" + TDBLocation + "\" . ?s xyz:name ?o } }";
//log.debug("TDB temp location: {}", TDBLocation);
//log.debug("Query string\n{}", queryString);
Query qs = QueryFactory.create(queryString);
Expand Down Expand Up @@ -663,7 +638,7 @@ public void testIssue295() throws URISyntaxException, IOException {
Query query;
String TDBLocation = "tmp/testIssue295";
File tmpTBDFolder = new File(TDBLocation);
if(tmpTBDFolder.exists()){
if (tmpTBDFolder.exists()) {
FileUtils.deleteDirectory(tmpTBDFolder);
}
String queryStr = IOUtils.toString(Objects.requireNonNull(getClass().getClassLoader().getResource("issues/issue295.sparql")).toURI(), StandardCharsets.UTF_8);
Expand All @@ -685,8 +660,8 @@ public void testIssue295() throws URISyntaxException, IOException {
assertEquals(expectedNames, actualNames);
try {
FileUtils.deleteDirectory(tmpTBDFolder);
}catch(IOException e){
log.warn("Unable to delete {}, delete it once the program terminates.",tmpTBDFolder.getAbsolutePath());
} catch (IOException e) {
log.warn("Unable to delete {}, delete it once the program terminates.", tmpTBDFolder.getAbsolutePath());
}
}

Expand Down Expand Up @@ -803,7 +778,7 @@ public void testIssue352() throws URISyntaxException, IOException {

query = QueryFactory.create(queryStr);
qExec = QueryExecutionFactory.create(query, ds);
rs = qExec.execSelect();
rs = qExec.execSelect();

assertTrue(rs.hasNext());
qs = rs.next();
Expand Down Expand Up @@ -855,7 +830,7 @@ public void testIssue386() throws URISyntaxException, IOException {
QueryExecution qExec = QueryExecutionFactory.create(query, ds);
ResultSet rs = qExec.execSelect();
assertTrue(rs.hasNext());
assertEquals("http://example.org/document",rs.next().get("root").asResource().getURI());
assertEquals("http://example.org/document", rs.next().get("root").asResource().getURI());
assertFalse(rs.hasNext());
}

Expand Down Expand Up @@ -905,7 +880,7 @@ public void testIssue421() throws URISyntaxException, IOException {
// System.out.println(ResultSetFormatter.asText(qExec1.execSelect()));
Set<String> result = new HashSet<>();
ResultSet rs = qExec1.execSelect();
while (rs.hasNext()){
while (rs.hasNext()) {
result.add(rs.next().get("a").asLiteral().toString());
}
assertEquals(Sets.newHashSet("abc", "cde"), result);
Expand All @@ -927,7 +902,7 @@ public void testIssue330() throws URISyntaxException, IOException {
// System.out.println(ResultSetFormatter.asText(qExec1.execSelect()));
Set<String> result = new HashSet<>();
ResultSet rs = qExec1.execSelect();
while (rs.hasNext()){
while (rs.hasNext()) {
result.add(rs.next().get("a").asLiteral().toString());
}
assertEquals(Sets.newHashSet("abc", "cde"), result);
Expand All @@ -953,4 +928,42 @@ public void testIssue330() throws URISyntaxException, IOException {
}


@Ignore
@Test
public void testIssue478() throws URISyntaxException, IOException {
executeTest("issues/issue478.sparql", "issues/issue 478.xls", false, false, true);
executeTest("issues/issue478-2.sparql", "issues/issue 478.xls", false, false, true);
}

private QueryExecution executeTest(String queryPath, String resourcePath, boolean printQueryString, boolean printFormattedQuery, boolean printResults) throws IOException, URISyntaxException {
Dataset ds = DatasetFactory.createGeneral();
QC.setFactory(ARQ.getContext(), FacadeX.ExecutorFactory);
Query query;
String queryStr = IOUtils.toString(Objects.requireNonNull(getClass().getClassLoader().getResource(queryPath)).toURI(), StandardCharsets.UTF_8);
String loc = Paths.get(Objects.requireNonNull(getClass().getClassLoader().getResource(resourcePath)).toURI()).toUri().toString();
queryStr = queryStr.replace("%%%LOCATION%%%", loc);
if (printQueryString) {
System.out.println(queryStr);
}
query = QueryFactory.create(queryStr);

QueryExecution qExec1 = QueryExecutionFactory.create(query, ds);
if (printResults) {
if (query.isSelectType()) {
ResultSet rs = qExec1.execSelect();
Assert.assertTrue(rs.hasNext());
System.out.println(ResultSetFormatter.asText(rs));
} else {
qExec1.execConstruct().write(System.out, "TTL");
}
}
if (printFormattedQuery) {
System.out.println(query.toString(Syntax.defaultSyntax));
}

return QueryExecutionFactory.create(query, ds);

}


}
Binary file not shown.
13 changes: 13 additions & 0 deletions sparql-anything-it/src/test/resources/issues/issue478-2.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX xyz: <http://sparql.xyz/facade-x/data/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT * WHERE {
SERVICE <x-sparql-anything:> {
fx:properties fx:location "%%%LOCATION%%%" .
GRAPH ?g {
?s ?p ?o
}
FILTER (STR(?g) = "file:///Users/lgu/workspace/SPARQLAnything/sparql.anything/sparql-anything-it/target/test-classes/issues/issue%20478.xls#Sheet1")
}
}
12 changes: 12 additions & 0 deletions sparql-anything-it/src/test/resources/issues/issue478.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX xyz: <http://sparql.xyz/facade-x/data/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT * WHERE {
SERVICE <x-sparql-anything:> {
fx:properties fx:location "%%%LOCATION%%%" .
GRAPH <file:///Users/lgu/workspace/SPARQLAnything/sparql.anything/sparql-anything-it/target/test-classes/issues/issue%20478.xls#Sheet2> {
?s ?p ?o
}
}
}

0 comments on commit d26e363

Please sign in to comment.