Permalink
Browse files

address some todo's for ask/construct/describe queries and examples.

  • Loading branch information...
1 parent dd2dfc1 commit 5abf3fdb6164f19b97aec926ee560dc1dba0a0dd Bill Millar committed Dec 11, 2009
Showing with 27 additions and 21 deletions.
  1. +24 −17 src/com/franz/agraph/jena/AGQueryExecution.java
  2. +3 −4 src/tutorial/JenaTutorialExamples.java
View
41 src/com/franz/agraph/jena/AGQueryExecution.java
@@ -13,6 +13,7 @@
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.sparql.util.Context;
import com.hp.hpl.jena.util.FileManager;
@@ -35,15 +36,14 @@ public void abort() {
@Override
public void close() {
- // TODO Auto-generated method stub
-
}
@Override
public boolean execAsk() {
AGBooleanQuery bq = model.getGraph().getConnection().prepareBooleanQuery(AGQueryLanguage.SPARQL, query.getQueryString());
boolean result;
try {
+ bq.setDataset(model.getGraph().getDataset());
result = bq.evaluate();
} catch (QueryEvaluationException e) {
throw new RuntimeException(e);
@@ -52,35 +52,42 @@ public boolean execAsk() {
}
@Override
- public AGModel execConstruct() {
+ public Model execConstruct() {
+ return execConstruct(null);
+ }
+
+ @Override
+ public Model execConstruct(Model m) {
AGGraphQuery gq = model.getGraph().getConnection().prepareGraphQuery(AGQueryLanguage.SPARQL, query.getQueryString());
GraphQueryResult result;
try {
+ gq.setDataset(model.getGraph().getDataset());
result = gq.evaluate();
- // TODO:
- result.close();
} catch (QueryEvaluationException e) {
throw new RuntimeException(e);
}
- return null; // TODO: new AGModel(result, model);
- }
-
- @Override
- public Model execConstruct(Model model) {
- // TODO Auto-generated method stub
- return null;
+ if (m==null) {
+ m = ModelFactory.createDefaultModel();
+ }
+ try {
+ m.setNsPrefixes(result.getNamespaces());
+ while (result.hasNext()) {
+ m.add(model.asStatement(AGNodeFactory.asTriple(result.next())));
+ }
+ } catch (QueryEvaluationException e) {
+ throw new RuntimeException(e);
+ }
+ return m;
}
@Override
public Model execDescribe() {
- // TODO Auto-generated method stub
- return null;
+ return execDescribe(null);
}
@Override
- public Model execDescribe(Model model) {
- // TODO Auto-generated method stub
- return null;
+ public Model execDescribe(Model m) {
+ return execConstruct(m);
}
@Override
View
7 src/tutorial/JenaTutorialExamples.java
@@ -409,7 +409,7 @@ public static void example7() throws Exception {
public static void example8() throws Exception {
AGGraphMaker maker = example6();
AGModel model = new AGModel(maker.getGraph());
- AGModel model_vcards = new AGModel(maker.openGraph("http://example.org#vcards"));
+ // TODO AGModel model_vcards = new AGModel(maker.openGraph("http://example.org#vcards"));
String outputFile = TEMPORARY_DIRECTORY + "temp.nt";
// outputFile = null;
if (outputFile == null) {
@@ -429,7 +429,7 @@ public static void example8() throws Exception {
}
output = (outputFile2 != null) ? new FileOutputStream(outputFile2)
: System.out;
- model_vcards.write(output);
+ // TODO model_vcards.write(output);
}
/**
@@ -495,7 +495,6 @@ public static void example13() throws Exception {
} finally {
qe.close();
}
- /*TODO:
queryString = "construct {?s ?p ?o} where { ?s ?p ?o . filter (?o = \"Alice\") } ";
query = AGQueryFactory.create(queryString);
qe = AGQueryExecutionFactory.create(query, model);
@@ -515,7 +514,7 @@ public static void example13() throws Exception {
m.write(System.out);
} finally {
qe.close();
- }*/
+ }
}
/**

0 comments on commit 5abf3fd

Please sign in to comment.