George News
2017-02-27 18:18:59 UTC
Hi,
I have a SELECT SPARQL query similar to the one below:
|PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs:
<http://www.w3.org/2000/01/rdf-schema#> SELECT (count(distinct ?o) as
?count_o) (count(distinct ?device) as ?count_devices) WHERE { {?o
rdf:type/rdfs:subClassOf CLASS1 .} UNION {?device
rdf:type/rdfs:subClassOf CLASS2 .} } |
If I execute it as it is, I get
|org.apache.jena.tdb.transaction.TDBTransactionException: Not in a
transaction |
However if I execute it like
|PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs:
<http://www.w3.org/2000/01/rdf-schema#> SELECT (count(distinct ?o) as
?count_observations) WHERE { {?o rdf:type/rdfs:subClassOf CLASS1 .} } |
everything is working ok. It doesnât matter if I use one or the other
part of the union, as it works ok independently but not together.
Any idea? Any help is more than welcome.
Find below part of the code:
|public SparqlResult executeSparql(String sparql) throws
SparqlExecutionException { String queryString = sparql; Query query =
QueryFactory.create(queryString); dataset.begin(ReadWrite.READ); try {
QueryExecution qExec = QueryExecutionFactory.create(query, getModel());
// System.out.println(qExec.getQuery().serialize()); //
System.out.println(qExec.getQuery().toString()); SparqlResult result; if
(query.isSelectType()) { result = new SparqlResult(qExec.execSelect(),
qExec); } else if (query.isDescribeType()) { result = new
SparqlResult(qExec.execDescribe(), qExec); } else if (query.isAskType())
{ result = new SparqlResult(qExec.execAsk(), qExec); } else if
(query.isConstructType()) { result = new
SparqlResult(qExec.execConstruct(), qExec); } else { throw new
SparqlExecutionException("Unsupported query type: " +
query.getQueryType()); } return result; } finally { dataset.end(); }
private Map<String, Integer> getSummaryStatistics() { String queryString
= "THE_ONE"; Map<String, Integer> statistics = new HashMap<>();
GlobalTripleStore gts = new GlobalTripleStore(); try (SparqlResult
result = gts.executeSparql(queryString)) { ResultSet resultSet =
(ResultSet) result.getResult(); while (resultSet.hasNext()) {
QuerySolution sol = resultSet.next(); int devices =
sol.get("count_devices").asLiteral().getInt(); int observations
=sol.get("count_o").asLiteral().getInt(); statistics.put("devices",
resources); statistics.put("o", observations); } } catch
(SparqlExecutionException e) { // TODO Auto-generated catch block
e.printStackTrace(); } return statistics; } |
â
I have a SELECT SPARQL query similar to the one below:
|PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs:
<http://www.w3.org/2000/01/rdf-schema#> SELECT (count(distinct ?o) as
?count_o) (count(distinct ?device) as ?count_devices) WHERE { {?o
rdf:type/rdfs:subClassOf CLASS1 .} UNION {?device
rdf:type/rdfs:subClassOf CLASS2 .} } |
If I execute it as it is, I get
|org.apache.jena.tdb.transaction.TDBTransactionException: Not in a
transaction |
However if I execute it like
|PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs:
<http://www.w3.org/2000/01/rdf-schema#> SELECT (count(distinct ?o) as
?count_observations) WHERE { {?o rdf:type/rdfs:subClassOf CLASS1 .} } |
everything is working ok. It doesnât matter if I use one or the other
part of the union, as it works ok independently but not together.
Any idea? Any help is more than welcome.
Find below part of the code:
|public SparqlResult executeSparql(String sparql) throws
SparqlExecutionException { String queryString = sparql; Query query =
QueryFactory.create(queryString); dataset.begin(ReadWrite.READ); try {
QueryExecution qExec = QueryExecutionFactory.create(query, getModel());
// System.out.println(qExec.getQuery().serialize()); //
System.out.println(qExec.getQuery().toString()); SparqlResult result; if
(query.isSelectType()) { result = new SparqlResult(qExec.execSelect(),
qExec); } else if (query.isDescribeType()) { result = new
SparqlResult(qExec.execDescribe(), qExec); } else if (query.isAskType())
{ result = new SparqlResult(qExec.execAsk(), qExec); } else if
(query.isConstructType()) { result = new
SparqlResult(qExec.execConstruct(), qExec); } else { throw new
SparqlExecutionException("Unsupported query type: " +
query.getQueryType()); } return result; } finally { dataset.end(); }
private Map<String, Integer> getSummaryStatistics() { String queryString
= "THE_ONE"; Map<String, Integer> statistics = new HashMap<>();
GlobalTripleStore gts = new GlobalTripleStore(); try (SparqlResult
result = gts.executeSparql(queryString)) { ResultSet resultSet =
(ResultSet) result.getResult(); while (resultSet.hasNext()) {
QuerySolution sol = resultSet.next(); int devices =
sol.get("count_devices").asLiteral().getInt(); int observations
=sol.get("count_o").asLiteral().getInt(); statistics.put("devices",
resources); statistics.put("o", observations); } } catch
(SparqlExecutionException e) { // TODO Auto-generated catch block
e.printStackTrace(); } return statistics; } |
â