It seems to me that your solution might be shortened by using Jena’s built-in
facilities for this kind of task. E.g.
Function<QuerySolution, Iterator<Triple>> myCustomTransform = qs -> {
// calculate triples from a query solution qs
return triplesForASolution;
};
Iterator<Triple> triples = WrappedIterator.createIteratorIterator( Iter.map(
myResultSet, myCustomTransform ));
// or
Iterator<Triple> triples = Iterators.concat( Iter.map( myResultSet,
myCustomTransform ));
I can tell you that some formats (and I believe that RDF/XML is a good example)
are inherently impossible to fully stream because they require a real buildup
of state along the way. Here:
https://jena.apache.org/documentation/io/rdf-output.html#streamed-block-formats
is some information about some options.
---
A. Soroka
The University of Virginia Library
> On Oct 15, 2015, at 12:00 PM, Enrico Daga (enridaga) <[email protected]>
> wrote:
>
> Thank you for your reply.
> Actually the problem is not really about the representation - for example I
> might use the DataCube vocabulary - but is more about how to use the Jena
> serialisers to stream custom triples adapted from a ResultSet efficiently.
> The ResultSetFormatter.toModel approach is not the one I like, as it requires
> the RDF to be generated in memory before serialisation.
> I posted my solution to SO:
> http://stackoverflow.com/questions/33136916/streaming-a-resultset-as-rdf-using-a-custom-vocabulary/33153024#33153024
>
> <http://stackoverflow.com/questions/33136916/streaming-a-resultset-as-rdf-using-a-custom-vocabulary/33153024#33153024>
> (Are there better ways of doing that?)
>
> However, it looks like the streaming features do not support all RDF syntax,
> as I got a RIOT exception when I ask for RDF/XML or RDF/JSON formats.
> So now my problem is how to support all serialisations.
> Or maybe my version of Jena is outdated (2.12.1) and I should use Jena 3?
>
> Thanks,
>
> Enrico
>
>
>> On 14 Oct 2015, at 18:53, A. Soroka <[email protected]> wrote:
>>
>> Perhaps you could say more about the representation you want to use?
>> ResultSetFormatter does feature methods that (to my understanding) do stream
>> using Jena serialization:
>>
>> https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/query/ResultSetFormatter.html#output-java.io.OutputStream-org.apache.jena.query.ResultSet-org.apache.jena.sparql.resultset.ResultsFormat-
>>
>> <https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/query/ResultSetFormatter.html#output-java.io.OutputStream-org.apache.jena.query.ResultSet-org.apache.jena.sparql.resultset.ResultsFormat->
>>
>> ---
>> A. Soroka
>> The University of Virginia Library
>>
>>> On Oct 14, 2015, at 6:39 PM, Enrico Daga (enridaga) <[email protected]
>>> <mailto:[email protected]>> wrote:
>>>
>>> Hi,
>>>
>>> in my use case I need to stream a ResultSet obtained from a query to a
>>> remote endpoint converted into an RDF output format.
>>> I know Jena provides a ResultSetFormatter.toModel facility for that,
>>> however I have the following constraints:
>>> - I want to use a different representation/vocabulary and not the one
>>> provided by Jena, and
>>> - I don't want to load the data in memory. In other words I don't want to
>>> create a Model and fill it with the ResultSet, but streaming out the
>>> triples while I iterate on it, to control memory consumption.
>>> - I still want to benefit by the Jena serializers
>>>
>>> I have seen the StreamRDF interface, but I am not very clear about how to
>>> use it effectively.
>>> What could be a correct approach in this scenario?
>>>
>>> Thank you,
>>>
>>> Enrico
>>>
>>> —
>>> Enrico Daga (enridaga)
>>> http://www.enridaga.net <http://www.enridaga.net/>
>>> <http://www.enridaga.net/ <http://www.enridaga.net/>>
>>> Il budda e’ nel parco.
>