Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added an example with SERVICE and additional/optional query parameters.

  • Loading branch information...
commit 0ddeec89e0fc93c9d0ed29e69d0c1ac3251fbb25 1 parent 8fdb6d9
@castagna authored
View
13 .classpath
@@ -15,14 +15,18 @@
<classpathentry kind="var" path="M2_REPO/org/jruby/extras/constantine/0.6/constantine-0.6.jar"/>
<classpathentry kind="var" path="M2_REPO/nu/validator/htmlparser/htmlparser/1.2.1/htmlparser-1.2.1.jar" sourcepath="M2_REPO/nu/validator/htmlparser/htmlparser/1.2.1/htmlparser-1.2.1-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/org/apache/httpcomponents/httpclient/4.1.2/httpclient-4.1.2.jar" sourcepath="M2_REPO/org/apache/httpcomponents/httpclient/4.1.2/httpclient-4.1.2-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/apache/httpcomponents/httpcore/4.1.2/httpcore-4.1.2.jar" sourcepath="M2_REPO/org/apache/httpcomponents/httpcore/4.1.2/httpcore-4.1.2-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/httpcomponents/httpcore/4.1.3/httpcore-4.1.3.jar" sourcepath="M2_REPO/org/apache/httpcomponents/httpcore/4.1.3/httpcore-4.1.3-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/com/ibm/icu/icu4j/3.4.4/icu4j-3.4.4.jar" sourcepath="M2_REPO/com/ibm/icu/icu4j/3.4.4/icu4j-3.4.4-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/com/hp/hpl/jena/iri/0.8/iri-0.8.jar" sourcepath="M2_REPO/com/hp/hpl/jena/iri/0.8/iri-0.8-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/org/jruby/extras/jaffl/0.5.11/jaffl-0.5.11.jar"/>
<classpathentry kind="var" path="M2_REPO/net/rootdev/java-rdfa/0.4.2-RC2/java-rdfa-0.4.2-RC2.jar" sourcepath="M2_REPO/net/rootdev/java-rdfa/0.4.2-RC2/java-rdfa-0.4.2-RC2-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/net/rootdev/java-rdfa-htmlparser/0.4.2-RC2/java-rdfa-htmlparser-0.4.2-RC2.jar"/>
<classpathentry kind="var" path="M2_REPO/org/jruby/jcodings/jcodings/1.0.5/jcodings-1.0.5.jar" sourcepath="M2_REPO/org/jruby/jcodings/jcodings/1.0.5/jcodings-1.0.5-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/apache/jena/jena-arq/2.9.0-incubating/jena-arq-2.9.0-incubating.jar" sourcepath="M2_REPO/org/apache/jena/jena-arq/2.9.0-incubating/jena-arq-2.9.0-incubating-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/jena/jena-arq/2.9.1-incubating-SNAPSHOT/jena-arq-2.9.1-incubating-SNAPSHOT.jar" sourcepath="M2_REPO/org/apache/jena/jena-arq/2.9.1-incubating-SNAPSHOT/jena-arq-2.9.1-incubating-SNAPSHOT-sources.jar">
+ <attributes>
+ <attribute value="jar:file:/home/castagna/.m2/repository/org/apache/jena/jena-arq/2.9.1-incubating-SNAPSHOT/jena-arq-2.9.1-incubating-SNAPSHOT-javadoc.jar!/" name="javadoc_location"/>
+ </attributes>
+ </classpathentry>
<classpathentry kind="var" path="M2_REPO/org/apache/jena/jena-core/2.7.0-incubating/jena-core-2.7.0-incubating.jar" sourcepath="M2_REPO/org/apache/jena/jena-core/2.7.0-incubating/jena-core-2.7.0-incubating-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/org/apache/jena/jena-iri/0.9.0-incubating/jena-iri-0.9.0-incubating.jar" sourcepath="M2_REPO/org/apache/jena/jena-iri/0.9.0-incubating/jena-iri-0.9.0-incubating-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/org/apache/jena/jena-larq/0.2.2-incubating-SNAPSHOT/jena-larq-0.2.2-incubating-SNAPSHOT.jar" sourcepath="M2_REPO/org/apache/jena/jena-larq/0.2.2-incubating-SNAPSHOT/jena-larq-0.2.2-incubating-SNAPSHOT-sources.jar"/>
@@ -57,10 +61,9 @@
<classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-log4j12/1.6.4/slf4j-log4j12-1.6.4.jar" sourcepath="M2_REPO/org/slf4j/slf4j-log4j12/1.6.4/slf4j-log4j12-1.6.4-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/org/apache/clerezza/ext/slf4j-scala-api/1.6.2-incubating-SNAPSHOT/slf4j-scala-api-1.6.2-incubating-SNAPSHOT.jar" sourcepath="M2_REPO/org/apache/clerezza/ext/slf4j-scala-api/1.6.2-incubating-SNAPSHOT/slf4j-scala-api-1.6.2-incubating-SNAPSHOT-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/org/yaml/snakeyaml/1.9/snakeyaml-1.9.jar" sourcepath="M2_REPO/org/yaml/snakeyaml/1.9/snakeyaml-1.9-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/stax/stax-api/1.0.1/stax-api-1.0.1.jar"/>
<classpathentry kind="var" path="M2_REPO/org/apache/clerezza/utils/0.2-incubating-SNAPSHOT/utils-0.2-incubating-SNAPSHOT.jar" sourcepath="M2_REPO/org/apache/clerezza/utils/0.2-incubating-SNAPSHOT/utils-0.2-incubating-SNAPSHOT-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/codehaus/woodstox/wstx-asl/3.2.9/wstx-asl-3.2.9.jar" sourcepath="M2_REPO/org/codehaus/woodstox/wstx-asl/3.2.9/wstx-asl-3.2.9-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/org/wymiwyg/wymiwyg-commons-core/0.7.6/wymiwyg-commons-core-0.7.6.jar" sourcepath="M2_REPO/org/wymiwyg/wymiwyg-commons-core/0.7.6/wymiwyg-commons-core-0.7.6-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/xerces/xercesImpl/2.7.1/xercesImpl-2.7.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/xerces/xercesImpl/2.10.0/xercesImpl-2.10.0.jar" sourcepath="M2_REPO/xerces/xercesImpl/2.10.0/xercesImpl-2.10.0-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/xml-apis/xml-apis/1.4.01/xml-apis-1.4.01.jar" sourcepath="M2_REPO/xml-apis/xml-apis/1.4.01/xml-apis-1.4.01-sources.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
</classpath>
View
2  pom.xml
@@ -10,7 +10,7 @@
<properties>
<jena.version>2.7.0-incubating</jena.version>
- <arq.version>2.9.0-incubating</arq.version>
+ <arq.version>2.9.1-incubating-SNAPSHOT</arq.version>
<tdb.version>0.9.0-incubating-SNAPSHOT</tdb.version>
<larq.version>0.2.2-incubating-SNAPSHOT</larq.version>
<java-rdfa.version>0.4.2-RC2</java-rdfa.version>
View
67 src/main/java/org/apache/jena/examples/ExampleARQ_04.java
@@ -18,48 +18,57 @@
package org.apache.jena.examples;
-import java.io.File;
-import java.io.FilenameFilter;
-import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import com.hp.hpl.jena.query.ARQ;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
-import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.query.QuerySolution;
+import com.hp.hpl.jena.query.ResultSet;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.util.FileManager;
public class ExampleARQ_04 {
public static void main(String[] args) {
FileManager.get().addLocatorClassLoader(ExampleARQ_01.class.getClassLoader());
- Model model = FileManager.get().loadModel("data/data.ttl");
- System.out.println("Input data:");
- model.write(System.out, "TURTLE");
-
- File path = new File("src/main/resources/data/queries");
- File[] files = path.listFiles(new FilenameFilter() {
- @Override
- public boolean accept(File dir, String name) {
- return name.startsWith("construct-") && name.endsWith(".sparql");
- }
- });
- Arrays.sort(files);
+ String uri = "http://api.kasabi.com/dataset/italy/apis/sparql";
+ String apikey = System.getenv("KASABI_API_KEY");
- for (File file : files) {
- System.out.println("Executing " + file.getName() + " ...");
- Query query = QueryFactory.read(file.getAbsolutePath());
- QueryExecution qexec = QueryExecutionFactory.create(query, model);
- try {
- Model result = qexec.execConstruct();
- model.add(result);
- } finally {
- qexec.close();
- }
- }
+ String queryString =
+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" +
+ "PREFIX italy: <http://data.kasabi.com/dataset/italy/schema/>" +
+ "SELECT * WHERE { " +
+ " SERVICE <" + uri + "> { ?region rdf:type italy:Region }" +
+ "}";
+ Query query = QueryFactory.create(queryString);
+ QueryExecution qexec = QueryExecutionFactory.create(query, ModelFactory.createDefaultModel());
+
+ // Set additional parameters on a per SERVICE basis, see also: JENA-195
+ Map<String, Map<String,List<String>>> serviceParams = new HashMap<String, Map<String,List<String>>>();
+ Map<String,List<String>> params = new HashMap<String,List<String>>();
+ List<String> values = new ArrayList<String>();
+ values.add(apikey);
+ params.put("apikey", values);
+ serviceParams.put(uri, params);
+ qexec.getContext().set(ARQ.serviceParams, serviceParams);
- System.out.println("Output data:");
- model.write(System.out, "TURTLE");
+ try {
+ ResultSet results = qexec.execSelect();
+ while ( results.hasNext() ) {
+ QuerySolution soln = results.nextSolution();
+ Resource region = soln.getResource("region");
+ System.out.println(region.getURI());
+ }
+ } finally {
+ qexec.close();
+ }
}
}
View
65 src/main/java/org/apache/jena/examples/ExampleARQ_05.java
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.examples;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.util.Arrays;
+
+import com.hp.hpl.jena.query.Query;
+import com.hp.hpl.jena.query.QueryExecution;
+import com.hp.hpl.jena.query.QueryExecutionFactory;
+import com.hp.hpl.jena.query.QueryFactory;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.util.FileManager;
+
+public class ExampleARQ_05 {
+
+ public static void main(String[] args) {
+ FileManager.get().addLocatorClassLoader(ExampleARQ_01.class.getClassLoader());
+ Model model = FileManager.get().loadModel("data/data.ttl");
+ System.out.println("Input data:");
+ model.write(System.out, "TURTLE");
+
+ File path = new File("src/main/resources/data/queries");
+ File[] files = path.listFiles(new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String name) {
+ return name.startsWith("construct-") && name.endsWith(".sparql");
+ }
+ });
+ Arrays.sort(files);
+
+ for (File file : files) {
+ System.out.println("Executing " + file.getName() + " ...");
+ Query query = QueryFactory.read(file.getAbsolutePath());
+ QueryExecution qexec = QueryExecutionFactory.create(query, model);
+ try {
+ Model result = qexec.execConstruct();
+ model.add(result);
+ } finally {
+ qexec.close();
+ }
+ }
+
+ System.out.println("Output data:");
+ model.write(System.out, "TURTLE");
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.