Skip to content

Commit b2362d5

Browse files
committed
Created new module sparql, externalized related classes and tests from module basil. See #5
1 parent 8bc4d89 commit b2362d5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+478
-10
lines changed

basil/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@
165165
<artifactId>rendering</artifactId>
166166
<version>${basil.version}</version>
167167
</dependency>
168+
<dependency>
169+
<groupId>io.github.basilapi</groupId>
170+
<artifactId>sparql</artifactId>
171+
<version>${basil.version}</version>
172+
</dependency>
168173
</dependencies>
169174

170175
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package io.github.basilapi.basil;
2+
3+
import io.github.basilapi.basil.sparql.QueryParameter;
4+
import io.github.basilapi.basil.sparql.Specification;
5+
import io.github.basilapi.basil.sparql.SpecificationFactory;
6+
import io.github.basilapi.basil.sparql.UnknownQueryTypeException;
7+
import org.apache.commons.io.IOUtils;
8+
9+
import java.io.IOException;
10+
11+
public class TestUtils {
12+
//
13+
public static String loadQueryString(String qname) throws IOException {
14+
return IOUtils.toString(TestUtils.class.getClassLoader().getResourceAsStream("./sparql/" + qname + ".txt"),
15+
"UTF-8");
16+
}
17+
//
18+
public static String endpoint(String qname) {
19+
int pos = qname.indexOf("X-Basil-Endpoint:");
20+
int len = ("X-Basil-Endpoint:").length();
21+
int eol = qname.indexOf('\n', pos);
22+
return qname.substring(pos + len, eol).trim();
23+
}
24+
//
25+
public static Specification loadQuery(String fileName) throws IOException {
26+
String sparql = loadQueryString(fileName);
27+
String endpoint = endpoint(sparql);
28+
// System.out.println(endpoint);
29+
try {
30+
return SpecificationFactory.create(endpoint, sparql);
31+
} catch (UnknownQueryTypeException e) {
32+
throw new IOException(e);
33+
}
34+
}
35+
36+
37+
public static String loadTemplate(String type, String qname) throws IOException {
38+
return IOUtils.toString(
39+
TestUtils.class.getClassLoader().getResourceAsStream("./" + type + "/" + qname + ".tmpl"), "UTF-8");
40+
}
41+
}

basil/src/test/java/io/github/basilapi/basil/store/FileStoreTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import java.util.List;
1010
import java.util.Set;
1111

12-
import io.github.basilapi.basil.sparql.TestUtils;
12+
import io.github.basilapi.basil.TestUtils;
1313
import org.apache.commons.io.FileUtils;
1414
import org.junit.Assert;
1515
import org.junit.Before;
@@ -55,7 +55,7 @@ public void before() throws IOException {
5555
@Test
5656
public void serializeQueryParameter() throws IOException,
5757
ClassNotFoundException {
58-
QueryParameter param = TestUtils.buildQueryParameter("param1",
58+
QueryParameter param = QueryParameter.buildQueryParameter("param1",
5959
Type.LangedLiteral, "en", null);
6060
store.write(testName.getMethodName(), param, "qp");
6161
QueryParameter param2 = (QueryParameter) store.read(

basil/src/test/java/io/github/basilapi/basil/test/ConfigTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.github.basilapi.basil.test;
22

3-
import io.github.basilapi.basil.sparql.TestUtils;
3+
import io.github.basilapi.basil.TestUtils;
44
import org.apache.shiro.config.Ini;
55
import org.junit.Assert;
66
import org.junit.Before;

basil/src/test/java/io/github/basilapi/basil/view/JavascriptTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import java.util.List;
1010
import java.util.Map;
1111

12-
import io.github.basilapi.basil.sparql.TestUtils;
12+
import io.github.basilapi.basil.TestUtils;
1313
import org.junit.Assert;
1414
import org.junit.Before;
1515
import org.junit.Rule;

basil/src/test/java/io/github/basilapi/basil/view/MustacheTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import java.util.List;
1010
import java.util.Map;
1111

12-
import io.github.basilapi.basil.sparql.TestUtils;
12+
import io.github.basilapi.basil.TestUtils;
1313
import org.junit.Before;
1414
import org.junit.Rule;
1515
import org.junit.Test;

parent/pom.xml

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@
3030

3131
<!-- github server corresponds to entry in ~/.m2/settings.xml -->
3232
<github.global.server>github</github.global.server>
33+
<localRepo>file://${project.build.directory}/mvn-repo</localRepo>
3334
</properties>
3435

3536
<distributionManagement>
3637
<repository>
3738
<id>internal.repo</id>
3839
<name>Temporary Staging Repository</name>
39-
<url>file://${project.build.directory}/mvn-repo</url>
40+
<url>${localRepo}</url>
4041
</repository>
4142
</distributionManagement>
4243

@@ -294,7 +295,7 @@
294295
<artifactId>maven-deploy-plugin</artifactId>
295296
<version>2.8.1</version>
296297
<configuration>
297-
<altDeploymentRepository>internal.repo::default::file://${project.build.directory}/mvn-repo</altDeploymentRepository>
298+
<altDeploymentRepository>internal.repo::default::${localRepo}</altDeploymentRepository>
298299
</configuration>
299300
</plugin>
300301

pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<module>rendering</module>
2121
<module>basil</module>
2222
<module>server</module>
23+
<module>sparql</module>
2324
</modules>
2425
<profiles>
2526
<profile>

sparql/pom.xml

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>reactor</artifactId>
7+
<groupId>io.github.basilapi</groupId>
8+
<version>0.8.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>sparql</artifactId>
13+
<name>BASIL :: SPARQL</name>
14+
15+
16+
<dependencies>
17+
18+
<!-- Logging -->
19+
<dependency>
20+
<groupId>org.slf4j</groupId>
21+
<artifactId>slf4j-api</artifactId>
22+
</dependency>
23+
24+
<!-- Test -->
25+
<dependency>
26+
<groupId>junit</groupId>
27+
<artifactId>junit</artifactId>
28+
<scope>test</scope>
29+
</dependency>
30+
31+
32+
<dependency>
33+
<groupId>org.apache.jena</groupId>
34+
<artifactId>jena-core</artifactId>
35+
<exclusions>
36+
<exclusion>
37+
<groupId>log4j</groupId>
38+
<artifactId>log4j</artifactId>
39+
</exclusion>
40+
<exclusion>
41+
<groupId>org.slf4j</groupId>
42+
<artifactId>slf4j-log4j12</artifactId>
43+
</exclusion>
44+
</exclusions>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.apache.jena</groupId>
48+
<artifactId>jena-arq</artifactId>
49+
<exclusions>
50+
<exclusion>
51+
<groupId>log4j</groupId>
52+
<artifactId>log4j</artifactId>
53+
</exclusion>
54+
<exclusion>
55+
<groupId>org.slf4j</groupId>
56+
<artifactId>slf4j-log4j12</artifactId>
57+
</exclusion>
58+
</exclusions>
59+
</dependency>
60+
</dependencies>
61+
</project>

basil/src/main/java/io/github/basilapi/basil/sparql/QueryParameter.java renamed to sparql/src/main/java/io/github/basilapi/basil/sparql/QueryParameter.java

+15
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,19 @@ public void setNumber() {
186186
this.datatype = null;
187187
this.lang = null;
188188
}
189+
190+
public static QueryParameter buildQueryParameter(String name, QueryParameter.Type type, String lang, String datatype) {
191+
QueryParameter qp = new QueryParameter();
192+
qp.setName(name);
193+
if (type == Type.IRI) {
194+
qp.setIri();
195+
} else if (type == Type.TypedLiteral) {
196+
qp.setDatatype(datatype);
197+
} else if (type == Type.LangedLiteral) {
198+
qp.setLang(lang);
199+
} else if (type == Type.PlainLiteral) {
200+
qp.setPlainLiteral();
201+
}
202+
return qp;
203+
}
189204
}

basil/src/test/java/io/github/basilapi/basil/sparql/TestUtils.java renamed to sparql/src/test/java/io/github/basilapi/basil/sparql/TestUtils.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.github.basilapi.basil.sparql;
22

33
import org.apache.commons.io.IOUtils;
4-
import io.github.basilapi.basil.rest.core.Headers;
4+
//import io.github.basilapi.basil.rest.core.Headers;
55
import io.github.basilapi.basil.sparql.QueryParameter.Type;
66

77
import java.io.IOException;
@@ -14,8 +14,8 @@ public static String loadQueryString(String qname) throws IOException {
1414
}
1515

1616
public static String endpoint(String qname) {
17-
int pos = qname.indexOf(Headers.Endpoint + ":");
18-
int len = (Headers.Endpoint + ":").length();
17+
int pos = qname.indexOf("X-Basil-Endpoint:");
18+
int len = ("X-Basil-Endpoint:").length();
1919
int eol = qname.indexOf('\n', pos);
2020
return qname.substring(pos + len, eol).trim();
2121
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# X-Basil-Endpoint: http://data.open.ac.uk/sparql
2+
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
3+
PREFIX mlo: <http://purl.org/net/mlo/>
4+
PREFIX aiiso: <http://purl.org/vocab/aiiso/schema#>
5+
6+
# Eg value for ?_geoid 2328926
7+
ASK {
8+
BIND(iri(CONCAT('http://sws.geonames.org/',?_geoid,'/')) as ?location) .
9+
?course mlo:location ?location . ?course a aiiso:Module
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# X-Basil-Endpoint: http://data.open.ac.uk/sparql
2+
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
3+
PREFIX mlo: <http://purl.org/net/mlo/>
4+
PREFIX aiiso: <http://purl.org/vocab/aiiso/schema#>
5+
6+
# Eg value for ?_geoid 2328926
7+
CONSTRUCT {
8+
?course mlo:location ?location . ?course a aiiso:Module
9+
}WHERE{
10+
BIND(iri(CONCAT('http://sws.geonames.org/',?_geoid,'/')) as ?location) .
11+
?course mlo:location ?location . ?course a aiiso:Module
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
PREFIX dc: <http://purl.org/dc/elements/1.1/>
2+
3+
DELETE DATA
4+
{
5+
<http://example/book2> dc:title ?_title ;
6+
dc:creator ?_creator .
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
PREFIX dc: <http://purl.org/dc/elements/1.1/>
2+
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
3+
4+
DELETE
5+
{ ?book ?p ?v }
6+
WHERE
7+
{ ?book dc:date ?date .
8+
FILTER ( ?date > ?_date_dateTime )
9+
?book ?p ?v
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
2+
3+
WITH <http://example/addresses>
4+
DELETE { ?person ?property ?value }
5+
WHERE { ?person ?property ?value ; foaf:givenName ?_givenName ; rdfs:label "$This $is ?not a ?_variable" }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
PREFIX dc: <http://purl.org/dc/elements/1.1/>
2+
DELETE DATA
3+
{ GRAPH <http://example/bookStore> { <http://example/book1> dc:title ?_delete } } ;
4+
5+
PREFIX dc: <http://purl.org/dc/elements/1.1/>
6+
INSERT DATA
7+
{ GRAPH <http://example/bookStore> { <http://example/book1> dc:title ?_insert } }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
2+
3+
WITH <http://example/addresses>
4+
DELETE { ?person foaf:givenName ?_delete }
5+
INSERT { ?person foaf:givenName ?_insert }
6+
WHERE
7+
{ ?person foaf:givenName ?_delete }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# X-Basil-Endpoint: http://data.open.ac.uk/sparql
2+
PREFIX dc: <http://purl.org/dc/elements/1.1/>
3+
INSERT { <http://example/egbook> dc:title ?_title } WHERE {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
PREFIX dc: <http://purl.org/dc/elements/1.1/>
2+
INSERT DATA
3+
{
4+
<http://example/book1> dc:title ?_title_string ;
5+
dc:creator ?_creator .
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
PREFIX dc: <http://purl.org/dc/elements/1.1/>
2+
PREFIX ns: <http://example.org/ns#>
3+
INSERT DATA
4+
{ GRAPH <http://example/bookStore> { <http://example/book1> ns:price ?_price_number } }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
PREFIX dc: <http://purl.org/dc/elements/1.1/>
2+
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
3+
4+
INSERT
5+
{ GRAPH ?_target_iri { ?book ?p ?v } }
6+
WHERE
7+
{ GRAPH <http://example/bookStore>
8+
{ ?book dc:date ?date .
9+
FILTER ( ?date > ?_date_dateTime )
10+
?book ?p ?v
11+
} }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# X-Basil-Endpoint: http://data.open.ac.uk/sparql
2+
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
3+
PREFIX mlo: <http://purl.org/net/mlo/>
4+
PREFIX aiiso: <http://purl.org/vocab/aiiso/schema#>
5+
6+
# Eg value for ?_geoid 2328926
7+
SELECT ?course FROM <http://data.open.ac.uk/context/course>
8+
WHERE {
9+
BIND(iri(CONCAT('http://sws.geonames.org/',?_geoid,'/')) as ?location) .
10+
?course mlo:location ?location . ?course a aiiso:Module
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# X-Basil-Endpoint: http://dbpedia.org/sparql
2+
3+
PREFIX some: <http://www.example.com/insert#> .
4+
5+
select ?subject ?label ?nationality where {
6+
?subject a <http://dbpedia.org/ontology/Person> ;
7+
<http://www.w3.org/2000/01/rdf-schema#label> ?label ;
8+
<http://dbpedia.org/property/dateOfBirth> ?_year_number ;
9+
<http://dbpedia.org/ontology/nationality> ?nationality .
10+
filter(lang(?label)="en")
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# X-Basil-Endpoint: http://dbpedia.org/sparql
2+
3+
# a DELETE command should be considered in a comment
4+
5+
select
6+
7+
?insert ?subject ?label ?nationality where { # insert a comment here
8+
9+
10+
?subject a <http://dbpedia.org/ontology/Person> ;
11+
<http://www.w3.org/2000/01/rdf-schema#label> ?label ;
12+
<http://dbpedia.org/property/dateOfBirth> ?_year_number ;
13+
<http://dbpedia.org/ontology/nationality> ?nationality .
14+
filter(lang(?label)="en")
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# X-Basil-Endpoint: http://dbpedia.org/sparql
2+
select ?subject ?label ?nationality where {
3+
?subject a <http://dbpedia.org/ontology/Person> ;
4+
<http://www.w3.org/2000/01/rdf-schema#label> ?label ;
5+
<http://dbpedia.org/property/dateOfBirth> 1964 ;
6+
<http://dbpedia.org/ontology/nationality> ?nationality .
7+
filter(lang(?label)="en")
8+
}
9+
LIMIT ?_limit_number
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# X-Basil-Endpoint: http://dbpedia.org/sparql
2+
select ?subject ?label ?nationality where {
3+
?subject a <http://dbpedia.org/ontology/Person> ;
4+
<http://www.w3.org/2000/01/rdf-schema#label> ?label ;
5+
<http://dbpedia.org/property/dateOfBirth> 1964 ;
6+
<http://dbpedia.org/ontology/nationality> ?nationality .
7+
filter(lang(?label)="en")
8+
}
9+
LIMIT ?_limit_number
10+
OFFSET ?_offset_number

0 commit comments

Comments
 (0)