Re: schemagen hangs

2017-02-27 Thread Florian Kleedorfer

Hi Dave!

Thanks to your comments I managed to get a configuration that produces 
the java classes the way I want them, so I think we can end this thread. 
Should I still create a JIRA ticket for it, @Andy?


A few remarks:

using --ontology without --inference on 'logiserv.ttl' leads to this 
failure: "Execution schemagen of goal 
org.apache.jena:jena-maven-tools:3.1.0:translate failed: Cannot convert 
node http://ontology.tno.nl/logico#Address to OntClass: it does not have 
rdf:type owl:Class or equivalent"


using --ontology without --inference on 'transport.ttl' leads to this 
failure: "Execution schemagen of goal 
org.apache.jena:jena-maven-tools:3.1.0:translate failed: Cannot convert 
node http://ontology.tno.nl/logico#Address to OntClass: it does not have 
rdf:type owl:Class or equivalent"


Using --ontology with --inference on these two seems to produce what I want.

Here's the maven configuration:


org.apache.jena
jena-maven-tools
3.1.0


src/main/vocabs/*.ttl



src/main/vocabs/logico.ttl
won.transport.ont
${project.build.directory}/generated-sources/java
false
true


src/main/vocabs/logiserv.ttl
won.transport.ont
${project.build.directory}/generated-sources/java
true
true

  

src/main/vocabs/transport.ttl
won.transport.ont
${project.build.directory}/generated-sources/java
true
true





schemagen

translate





Am 26.02.2017 um 22:18 schrieb Dave Reynolds:

Hi,

On 22/02/17 18:04, Florian Kleedorfer wrote:

Hi!

I am trying to use schemagen (jena 2.12.1) on three ontologies found
here: http://ontology.tno.nl/
namely
a) http://ontology.tno.nl/logico.ttl,
b) http://ontology.tno.nl/logiserv.ttl
c) http://ontology.tno.nl/transport.ttl

using these options (through maven in the example below, but I get the
same results from the command line)

-i [file] \
-e TTL \
--package won.transport.ont \
-o ${project.build.directory}/generated-sources/java \
-n [classname]

With these settings, no object properties are to be found in the
resulting files, which is not what I want.


[I've only looked at logico.ttl in the below.]

Use --ontology. With that (but no --inference) I get *lots* of 
ObjectProperties. You shouldn't need inference for a case like this.



If I add the '--inference' option, generating the class works for c) and
I get the properties - but neither for a) nor b):  in both cases, the
program seems to hang, probably indefinitely. I thread-debugged and it
seems to me that the program hangs in the writeRDFProperties() method
(schemagen:926 in jena 2.12.1) - iterating over the statements iterator
never ends. Code execution hangs in the loop in
com.hp.hpl.jena.reasoner.rulesys.impl.LPBRuleEngine#pump (line 304).
There are 3 generators in the collection called 'batch', and their ready
flag never seems to change to true.


I believe is this is just the inefficiency of the rule reasoner for an 
ontology like this with it's search space exploding.


It is getting lost trying to follow things like the nest of transitive 
and inverse properties declarations in the DUL part of the ontology.
Risking to be side-tracked here: What do you mean by DUL part of the 
ontology?



I tried to load the ontology files using a normal OntModel with the same
Reasoner that is used by schemagen( OWL_MEM_RULE_INF) and I can print
out the model after reasoning (which I suspect should do the same as
above: iterating over the statements in the model).


If I try a writeAll on an OWL_MEM_RULE_INF instance of that ontology I 
get exactly the same explosion in the reasoner as I see with 
schemagen. Might you have been trying a plain write in your test?

yes, correct. With writeAll I get the same behaviour as through schemagen.

Cheers,
Florian


Re: Extending Jena Text to Support ElasticSearch as Indexing/Querying Engine

2017-02-27 Thread anuj kumar
Hi All,

*Apologies for the long email.*

 As some of you know, I have been working on extending Jena to Support
ElasticSearch for Text Indexing (in addition to Lucene and Solr).

I have come to a point where I have a basic (read non-prod) code that can
index RDFS:label text data into ElasticSearch 5.2.1
The code is working and testable. You simply have to download elasticsearch
5.2.1 and run it locally for executing the test within  the ES
implementation.
The code is NOT production Ready but just a PoC code.  You can find the
first cut of the code here: https://github.com/EaseTech/jena (look inside
the module jena-text-es)

I need feedback from Jena maintainers and community, in terms of the
structuring of the code as this is important for me to finalize before I
move to implement the full blown Production Ready code for Jean Text
ElasticSearch Integration.

Here is the short description of what I did and the reasoning behind it:

1. Created a separate module : *jena-text-es *that extends from *jena-text*
AND excludes all the Lucene related and Solr related dependencies. The
reason I had to do it was that* jena-text* module depends on Lucene version
4.9.1 whereas ElasticSearch 5.2.1 version depends on Lucene 6.4.1. This was
resulting in the conflicts of Lucene version if I created the code for
ElasticSearch support within the *jena-text *module. Thus the need to
create a separate module.
2. A side effect of creating a separate module meant, I had to extend the
TextDataSetFactory.java class present in the *jena-text *module to include
methods for creating ElasticSearch index objects. I named it
ESTextDataSetFactory. At this point in time I do not know if this is the
right approach or if Jena ALWAYS instantiates Index objects using the
TextDataSetFactory.java class. My initial investigation showed it is fine,
but I want the people who are experts in Jena to please confirm.
3. I have tested a simple integration with ElasticSearch by defining a test
class under
src/test/java/org/apache/jena/query/text/TestBuildTextDataSet.java. You can
run this test by first starting an instance of Elasticsearch 5.2.1 locally.

*My Queries*
1. Is it acceptable by the Jena community that I create a separate module
for support of ElasticSearch and call it *jena-text-es*?
2. Is it fine if I extend the TextDataSetFactory.java class within the
*jena-text-es
*module?

*Food for Thought*

While implementing the ElasticSearch Integration, I could not help but
notice that the module *jena-text *not only contains the core classes for
performing text queries, but also contains technology specific (for eg.
Lucene and Solr) classes.
IMO, these should be separate and defined in their own modules to enable
separation of concerns.
This will also help in easier maintenance and extensions to be added later
on.

I think we should have the following modules:

jena-text - Containing core Jena text specific classes that are technology
agnostic.
jena-text-lucene - Lucene specific implementation of Jena-Text
jena-text-solr - Solr specific implementation of Jena-Text
jena-text-es - ElasticSearch specific implementation of Jena-Text

What does everyone think?

Thanks,
Anuj Kumar


On Tue, Feb 14, 2017 at 2:27 PM, anuj kumar  wrote:

> My saviour Osma. It worked :)
> Thanks for pointing that out. Really appreciate it.
> I am now to my next task. Implementing the actual code for ElasticSearch
> integration with Jena.
>
> Thanks once again.
>
> Anuj Kumar
>
> On Tue, Feb 14, 2017 at 2:22 PM, Osma Suominen 
> wrote:
>
>> 14.02.2017, 15:15, anuj kumar kirjoitti:
>>
>>> I will do it. But I need to first get the simple test working in order to
>>> move forward. I hope I someone here can help me.
>>>
>>
>> Maybe you need to add an implementWith declaration to TextAssembler.java?
>>
>>
>> -Osma
>>
>> --
>> Osma Suominen
>> D.Sc. (Tech), Information Systems Specialist
>> National Library of Finland
>> P.O. Box 26 (Kaikukatu 4)
>> 00014 HELSINGIN YLIOPISTO
>> Tel. +358 50 3199529
>> osma.suomi...@helsinki.fi
>> http://www.nationallibrary.fi
>>
>
>
>
> --
> *Anuj Kumar*
>



-- 
*Anuj Kumar*


SPARQL with UNION returning TDBTransactionException

2017-02-27 Thread George News
Hi,

I have a SELECT SPARQL query similar to the one below:

|PREFIX rdf:  PREFIX rdfs:
 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:  PREFIX rdfs:
 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 getSummaryStatistics() { String queryString
= "THE_ONE"; Map 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; } |

​




Re: SPARQL with UNION returning TDBTransactionException

2017-02-27 Thread George News
Sorry I forgot to include the full exception

Caused by: org.apache.jena.tdb.transaction.TDBTransactionException: Not in a 
transaction
at 
org.apache.jena.tdb.transaction.DatasetGraphTransaction.get(DatasetGraphTransaction.java:117)
at 
org.apache.jena.tdb.transaction.DatasetGraphTransaction.get(DatasetGraphTransaction.java:50)
at 
org.apache.jena.sparql.core.DatasetGraphWrapper.getR(DatasetGraphWrapper.java:61)
at 
org.apache.jena.sparql.core.DatasetGraphWrapper.find(DatasetGraphWrapper.java:146)
at 
org.apache.jena.sparql.core.GraphView.graphBaseFind(GraphView.java:121)
at org.apache.jena.graph.impl.GraphBase.find(GraphBase.java:255)
at 
org.apache.jena.sparql.path.eval.PathEngine.graphFind2(PathEngine.java:205)
at 
org.apache.jena.sparql.path.eval.PathEngine.graphFind(PathEngine.java:189)
at 
org.apache.jena.sparql.path.eval.PathEngine.graphFind(PathEngine.java:171)
at org.apache.jena.sparql.path.eval.PathEngine.doOne(PathEngine.java:92)
at 
org.apache.jena.sparql.path.eval.PathEvaluator.visit(PathEvaluator.java:57)
at org.apache.jena.sparql.path.P_Link.visit(P_Link.java:37)
at org.apache.jena.sparql.path.eval.PathEval.eval$(PathEval.java:68)
at org.apache.jena.sparql.path.eval.PathEval.eval$(PathEval.java:74)
at org.apache.jena.sparql.path.eval.PathEngine.eval(PathEngine.java:75)
at 
org.apache.jena.sparql.path.eval.PathEngineSPARQL.ALP_1(PathEngineSPARQL.java:119)
at 
org.apache.jena.sparql.path.eval.PathEngineSPARQL.doZeroOrMore(PathEngineSPARQL.java:92)
at 
org.apache.jena.sparql.path.eval.PathEvaluator.visit(PathEvaluator.java:115)
at 
org.apache.jena.sparql.path.P_ZeroOrMore1.visit(P_ZeroOrMore1.java:43)
at org.apache.jena.sparql.path.eval.PathEval.eval$(PathEval.java:68)
at org.apache.jena.sparql.path.eval.PathEval.eval$(PathEval.java:74)
at org.apache.jena.sparql.path.eval.PathEval.eval(PathEval.java:37)
at 
org.apache.jena.sparql.path.PathLib.evalGroundedPath(PathLib.java:166)
at org.apache.jena.sparql.path.PathLib.execTriplePath(PathLib.java:133)
at org.apache.jena.sparql.path.PathLib.execTriplePath(PathLib.java:108)
at 
org.apache.jena.sparql.engine.iterator.QueryIterPath.nextStage(QueryIterPath.java:47)
at 
org.apache.jena.sparql.engine.iterator.QueryIterRepeatApply.makeNextStage(QueryIterRepeatApply.java:108)
at 
org.apache.jena.sparql.engine.iterator.QueryIterRepeatApply.hasNextBinding(QueryIterRepeatApply.java:65)
at 
org.apache.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:114)
at org.apache.jena.atlas.iterator.Iter$2.hasNext(Iter.java:265)
at 
org.apache.jena.atlas.iterator.RepeatApplyIterator.hasNext(RepeatApplyIterator.java:45)
at 
org.apache.jena.tdb.solver.SolverLib$IterAbortable.hasNext(SolverLib.java:195)
at org.apache.jena.atlas.iterator.Iter$2.hasNext(Iter.java:265)
at 
org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper.hasNextBinding(QueryIterPlainWrapper.java:53)
at 
org.apache.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:114)
at 
org.apache.jena.sparql.engine.iterator.QueryIterRepeatApply.makeNextStage(QueryIterRepeatApply.java:101)
at 
org.apache.jena.sparql.engine.iterator.QueryIterRepeatApply.hasNextBinding(QueryIterRepeatApply.java:65)
at 
org.apache.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:114)
at 
org.apache.jena.sparql.engine.iterator.QueryIterRepeatApply.makeNextStage(QueryIterRepeatApply.java:101)
at 
org.apache.jena.sparql.engine.iterator.QueryIterRepeatApply.hasNextBinding(QueryIterRepeatApply.java:65)
at 
org.apache.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:114)
at 
org.apache.jena.sparql.engine.iterator.QueryIterGroup$1.initializeIterator(QueryIterGroup.java:86)
at 
org.apache.jena.atlas.iterator.IteratorDelayedInitialization.init(IteratorDelayedInitialization.java:40)
at 
org.apache.jena.atlas.iterator.IteratorDelayedInitialization.hasNext(IteratorDelayedInitialization.java:50)
at 
org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper.hasNextBinding(QueryIterPlainWrapper.java:53)
at 
org.apache.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:114)
at 
org.apache.jena.sparql.engine.iterator.QueryIterProcessBinding.hasNextBinding(QueryIterProcessBinding.java:66)
at 
org.apache.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:114)
at 
org.apache.jena.sparql.engine.iterator.QueryIterConvert.hasNextBinding(QueryIterConvert.java:58)
at 
org.apache.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:114)
at 
org.apache.jena.sparql.engine.it

Re: SPARQL with UNION returning TDBTransactionException

2017-02-27 Thread George News
More information... I have also noticed that if I don't close the
transaction (dataset.end()) it works. But, are the transactions garbage
collected?

What is the different between using UNION and not using it internally
for Jena? the other option is using RewindableResultSet, which somehow I
want to avoid. But if this is the solution, I will go though all my
ResultSets twice, one for retrieval (Rewindable creation) and another
for analysing the data.

On 27/02/2017 19:23, George News wrote:
> Sorry I forgot to include the full exception
> 
> Caused by: org.apache.jena.tdb.transaction.TDBTransactionException: Not in a 
> transaction
>   at 
> org.apache.jena.tdb.transaction.DatasetGraphTransaction.get(DatasetGraphTransaction.java:117)
>   at 
> org.apache.jena.tdb.transaction.DatasetGraphTransaction.get(DatasetGraphTransaction.java:50)
>   at 
> org.apache.jena.sparql.core.DatasetGraphWrapper.getR(DatasetGraphWrapper.java:61)
>   at 
> org.apache.jena.sparql.core.DatasetGraphWrapper.find(DatasetGraphWrapper.java:146)
>   at 
> org.apache.jena.sparql.core.GraphView.graphBaseFind(GraphView.java:121)
>   at org.apache.jena.graph.impl.GraphBase.find(GraphBase.java:255)
>   at 
> org.apache.jena.sparql.path.eval.PathEngine.graphFind2(PathEngine.java:205)
>   at 
> org.apache.jena.sparql.path.eval.PathEngine.graphFind(PathEngine.java:189)
>   at 
> org.apache.jena.sparql.path.eval.PathEngine.graphFind(PathEngine.java:171)
>   at org.apache.jena.sparql.path.eval.PathEngine.doOne(PathEngine.java:92)
>   at 
> org.apache.jena.sparql.path.eval.PathEvaluator.visit(PathEvaluator.java:57)
>   at org.apache.jena.sparql.path.P_Link.visit(P_Link.java:37)
>   at org.apache.jena.sparql.path.eval.PathEval.eval$(PathEval.java:68)
>   at org.apache.jena.sparql.path.eval.PathEval.eval$(PathEval.java:74)
>   at org.apache.jena.sparql.path.eval.PathEngine.eval(PathEngine.java:75)
>   at 
> org.apache.jena.sparql.path.eval.PathEngineSPARQL.ALP_1(PathEngineSPARQL.java:119)
>   at 
> org.apache.jena.sparql.path.eval.PathEngineSPARQL.doZeroOrMore(PathEngineSPARQL.java:92)
>   at 
> org.apache.jena.sparql.path.eval.PathEvaluator.visit(PathEvaluator.java:115)
>   at 
> org.apache.jena.sparql.path.P_ZeroOrMore1.visit(P_ZeroOrMore1.java:43)
>   at org.apache.jena.sparql.path.eval.PathEval.eval$(PathEval.java:68)
>   at org.apache.jena.sparql.path.eval.PathEval.eval$(PathEval.java:74)
>   at org.apache.jena.sparql.path.eval.PathEval.eval(PathEval.java:37)
>   at 
> org.apache.jena.sparql.path.PathLib.evalGroundedPath(PathLib.java:166)
>   at org.apache.jena.sparql.path.PathLib.execTriplePath(PathLib.java:133)
>   at org.apache.jena.sparql.path.PathLib.execTriplePath(PathLib.java:108)
>   at 
> org.apache.jena.sparql.engine.iterator.QueryIterPath.nextStage(QueryIterPath.java:47)
>   at 
> org.apache.jena.sparql.engine.iterator.QueryIterRepeatApply.makeNextStage(QueryIterRepeatApply.java:108)
>   at 
> org.apache.jena.sparql.engine.iterator.QueryIterRepeatApply.hasNextBinding(QueryIterRepeatApply.java:65)
>   at 
> org.apache.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:114)
>   at org.apache.jena.atlas.iterator.Iter$2.hasNext(Iter.java:265)
>   at 
> org.apache.jena.atlas.iterator.RepeatApplyIterator.hasNext(RepeatApplyIterator.java:45)
>   at 
> org.apache.jena.tdb.solver.SolverLib$IterAbortable.hasNext(SolverLib.java:195)
>   at org.apache.jena.atlas.iterator.Iter$2.hasNext(Iter.java:265)
>   at 
> org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper.hasNextBinding(QueryIterPlainWrapper.java:53)
>   at 
> org.apache.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:114)
>   at 
> org.apache.jena.sparql.engine.iterator.QueryIterRepeatApply.makeNextStage(QueryIterRepeatApply.java:101)
>   at 
> org.apache.jena.sparql.engine.iterator.QueryIterRepeatApply.hasNextBinding(QueryIterRepeatApply.java:65)
>   at 
> org.apache.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:114)
>   at 
> org.apache.jena.sparql.engine.iterator.QueryIterRepeatApply.makeNextStage(QueryIterRepeatApply.java:101)
>   at 
> org.apache.jena.sparql.engine.iterator.QueryIterRepeatApply.hasNextBinding(QueryIterRepeatApply.java:65)
>   at 
> org.apache.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:114)
>   at 
> org.apache.jena.sparql.engine.iterator.QueryIterGroup$1.initializeIterator(QueryIterGroup.java:86)
>   at 
> org.apache.jena.atlas.iterator.IteratorDelayedInitialization.init(IteratorDelayedInitialization.java:40)
>   at 
> org.apache.jena.atlas.iterator.IteratorDelayedInitialization.hasNext(IteratorDelayedInitialization.java:50)
>   at 
> org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper.hasNextBinding(QueryIterPlainWrapper.java:53)
>   at 
> org.apach

Re: SPARQL with UNION returning TDBTransactionException

2017-02-27 Thread Andy Seaborne

Unreadable.

-

Probably you are passing the result stream out of the transaction.

Reading a ResultSet requires reading the dataset and must be inside a 
transaction when the calls to hasNext/next are happening.


Andy

On 27/02/17 18:18, George News wrote:

|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 getSummaryStatistics() { String queryString
= "THE_ONE"; Map 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; } |


RE: SPARQL with UNION returning TDBTransactionException

2017-02-27 Thread George News
But the funny thing is that in both cases (with and without UNION) the code is 
the same. I know I close the transaction, but I don’t understand why in one 
case it works and in the other no.

I would like to ask another thing:  In a @requestscope is the reading 
transaction automatically close when finished the REST processing or is it 
mandatory to call dataset.end()?

I don't knw why example code is unreadable. I have perfectly seen the code.

Thanks a lot
Jorge

Sent from jlanza_lumia820

From: Andy Seaborne
Sent: martes, 28 de febrero de 2017 0:12
To: users@jena.apache.org
Subject: Re: SPARQL with UNION returning TDBTransactionException

Unreadable.

-

Probably you are passing the result stream out of the transaction.

Reading a ResultSet requires reading the dataset and must be inside a 
transaction when the calls to hasNext/next are happening.

 Andy

On 27/02/17 18:18, George News wrote:
> |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 getSummaryStatistics() { String queryString
> = "THE_ONE"; Map 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; } |