Reading an rdf:List into a Java list

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Reading an rdf:List into a Java list

David Booth-2
I see that Josh Shinavier and Peter Ansell have implemented some
rdf:List support in Java that looks very useful:
https://github.com/joshsh/sesametools/blob/develop/common/src/main/java/net/fortytwo/sesametools/RdfListUtil.java

Can anyone point me to instructions for its use?  From scanning through
the code, I am guessing that it is intended to be linked into the Sesame
server for direct access via an API call.  I'm using AllegroGraph, and
accessing the server remotely via a RepositoryConnection.

Thanks,
David

------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
Sesame-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sesame-general
Reply | Threaded
Open this post in threaded view
|

Re: Reading an rdf:List into a Java list

Peter Ansell-2
RdfListUtil currently uses the Graph API (the more commonly used Model
API which extends the Graph API was added, and is recommended, from
Sesame-2.7. However, SesameTools is still on Sesame-2.6). Both the
Graph and Model APIs have only been used (so far) for in-memory
collections. It has been on my todo list for a few years now to make a
GraphRepositoryConnection or ModelRepositoryConnection to use the
Graph/Model API with a RepositoryConnection backend. The biggest
design issue with combining the two is the RepositoryConnection uses
checked exceptions for its operations, while Graph/Model do not and I
am not sure what is the best strategy for reconciling that yet. The
same basic operations are available across the two interfaces, so
there shouldn't be a semantic difference.

Feel free to open a pull request at GitHub to add support for
RepositoryConnection entry methods in RdfListUtil, although I am not
sure yet how we would avoid duplicating the code to support it.

One workaround, if you have a small set of statements would be to load
it into a local in-memory Graph first and then use RdfListUtil on it.

tl;dr: It would not be difficult to extend RdfListUtil to use the
RepositoryConnection API, but it doesn't use it at this stage.

Cheers,

Peter

On 16 October 2013 06:56, David Booth <[hidden email]> wrote:

> I see that Josh Shinavier and Peter Ansell have implemented some rdf:List
> support in Java that looks very useful:
> https://github.com/joshsh/sesametools/blob/develop/common/src/main/java/net/fortytwo/sesametools/RdfListUtil.java
>
> Can anyone point me to instructions for its use?  From scanning through the
> code, I am guessing that it is intended to be linked into the Sesame server
> for direct access via an API call.  I'm using AllegroGraph, and accessing
> the server remotely via a RepositoryConnection.
>
> Thanks,
> David

------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
Sesame-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sesame-general
Reply | Threaded
Open this post in threaded view
|

Re: Reading an rdf:List into a Java list

Peter Ansell-2
FYI: The OpenRDF Jira issue that has been tracking this feature so far is:

    https://openrdf.atlassian.net/browse/SES-860

It can be retargeted to 2.8.0 if there is significant interest in it.

Peter

On 16 October 2013 09:01, Peter Ansell <[hidden email]> wrote:

> RdfListUtil currently uses the Graph API (the more commonly used Model
> API which extends the Graph API was added, and is recommended, from
> Sesame-2.7. However, SesameTools is still on Sesame-2.6). Both the
> Graph and Model APIs have only been used (so far) for in-memory
> collections. It has been on my todo list for a few years now to make a
> GraphRepositoryConnection or ModelRepositoryConnection to use the
> Graph/Model API with a RepositoryConnection backend. The biggest
> design issue with combining the two is the RepositoryConnection uses
> checked exceptions for its operations, while Graph/Model do not and I
> am not sure what is the best strategy for reconciling that yet. The
> same basic operations are available across the two interfaces, so
> there shouldn't be a semantic difference.
>
> Feel free to open a pull request at GitHub to add support for
> RepositoryConnection entry methods in RdfListUtil, although I am not
> sure yet how we would avoid duplicating the code to support it.
>
> One workaround, if you have a small set of statements would be to load
> it into a local in-memory Graph first and then use RdfListUtil on it.
>
> tl;dr: It would not be difficult to extend RdfListUtil to use the
> RepositoryConnection API, but it doesn't use it at this stage.
>
> Cheers,
>
> Peter
>
> On 16 October 2013 06:56, David Booth <[hidden email]> wrote:
>> I see that Josh Shinavier and Peter Ansell have implemented some rdf:List
>> support in Java that looks very useful:
>> https://github.com/joshsh/sesametools/blob/develop/common/src/main/java/net/fortytwo/sesametools/RdfListUtil.java
>>
>> Can anyone point me to instructions for its use?  From scanning through the
>> code, I am guessing that it is intended to be linked into the Sesame server
>> for direct access via an API call.  I'm using AllegroGraph, and accessing
>> the server remotely via a RepositoryConnection.
>>
>> Thanks,
>> David

------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
Sesame-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sesame-general
Reply | Threaded
Open this post in threaded view
|

Re: Reading an rdf:List into a Java list

josh
In reply to this post by Peter Ansell-2

On Tue, Oct 15, 2013 at 6:01 PM, Peter Ansell <[hidden email]> wrote:
RdfListUtil currently uses the Graph API (the more commonly used Model
API which extends the Graph API was added, and is recommended, from
Sesame-2.7. However, SesameTools is still on Sesame-2.6).


Note: Model is now an option, as I have just finished moving SesameTools to Sesame 2.7.  Most of the Sail implementations required extensive tweaking due to the transaction API changes:


W.r.t. using the Repository API with RdfListUtil, I have added a wrapper called RepositoryGraph (not yet RepositoryModel, although it could be extended to that) which seems to do the trick:


I modified one of Peter's test cases to use a Graph which wraps a Repository, and it passes.  For the sake of just trying something out, I propagated the exceptions up through graph as RuntimeExceptions.  There are two other issues to be aware of, which are:

1) RepositoryGraph creates and wraps a RepositoryConnection, so you need to call its close() function when you are finished with it
2) the Iterators it returns wrap CloseableIterations, and there is currently no way to close them

Suggestions, comments, pull requests are welcome.

Best regards,

Josh


 
Both the
Graph and Model APIs have only been used (so far) for in-memory
collections. It has been on my todo list for a few years now to make a
GraphRepositoryConnection or ModelRepositoryConnection to use the
Graph/Model API with a RepositoryConnection backend. The biggest
design issue with combining the two is the RepositoryConnection uses
checked exceptions for its operations, while Graph/Model do not and I
am not sure what is the best strategy for reconciling that yet. The
same basic operations are available across the two interfaces, so
there shouldn't be a semantic difference.

Feel free to open a pull request at GitHub to add support for
RepositoryConnection entry methods in RdfListUtil, although I am not
sure yet how we would avoid duplicating the code to support it.

One workaround, if you have a small set of statements would be to load
it into a local in-memory Graph first and then use RdfListUtil on it.

tl;dr: It would not be difficult to extend RdfListUtil to use the
RepositoryConnection API, but it doesn't use it at this stage.

Cheers,

Peter

On 16 October 2013 06:56, David Booth <[hidden email]> wrote:
> I see that Josh Shinavier and Peter Ansell have implemented some rdf:List
> support in Java that looks very useful:
> https://github.com/joshsh/sesametools/blob/develop/common/src/main/java/net/fortytwo/sesametools/RdfListUtil.java
>
> Can anyone point me to instructions for its use?  From scanning through the
> code, I am guessing that it is intended to be linked into the Sesame server
> for direct access via an API call.  I'm using AllegroGraph, and accessing
> the server remotely via a RepositoryConnection.
>
> Thanks,
> David


------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
Sesame-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sesame-general
Reply | Threaded
Open this post in threaded view
|

Re: Reading an rdf:List into a Java list

Peter Ansell-2
On 18 October 2013 02:00, Joshua Shinavier <[hidden email]> wrote:

>
> On Tue, Oct 15, 2013 at 6:01 PM, Peter Ansell <[hidden email]>
> wrote:
>>
>> RdfListUtil currently uses the Graph API (the more commonly used Model
>> API which extends the Graph API was added, and is recommended, from
>> Sesame-2.7. However, SesameTools is still on Sesame-2.6).
>
>
>
> Note: Model is now an option, as I have just finished moving SesameTools to
> Sesame 2.7.  Most of the Sail implementations required extensive tweaking
> due to the transaction API changes:

Some of the RdfListUtil functions may be slightly simpler using the
new Model functions, and may be more efficient on large statement sets
as Model can optimise some of the new functions.

>
> https://github.com/joshsh/sesametools/commit/99c647d44bbbbc5bc9dbc9472a44435788da9367
>
> W.r.t. using the Repository API with RdfListUtil, I have added a wrapper
> called RepositoryGraph (not yet RepositoryModel, although it could be
> extended to that) which seems to do the trick:
>
>
> https://github.com/joshsh/sesametools/commit/3db50f7591c2f26f5f8a271757f3f612453ea7bf

Looks good, see comments below about specifics:

> I modified one of Peter's test cases to use a Graph which wraps a
> Repository, and it passes.  For the sake of just trying something out, I
> propagated the exceptions up through graph as RuntimeExceptions.  There are
> two other issues to be aware of, which are:

The only issue with RuntimeException is that to catch them, for
legitimate purposes, you need to catch some exceptions such as NPEs
that you really don't want to catch. The alternative may be to define
specific runtime exception base class for SesameTools, say
SesameToolsRuntimeException. (I tend to use RuntimeException too often
in my code where I should either subclass it or create a checked
exception!)

> 1) RepositoryGraph creates and wraps a RepositoryConnection, so you need to
> call its close() function when you are finished with it

Given that RepositoryGraph is likely to be used for a shorttime,
possibly only one function, it may be easier to make it take a
RepositoryConnection that the user still has to close, while making it
clear that they need to do so in the same way as other functions.

> 2) the Iterators it returns wrap CloseableIterations, and there is currently
> no way to close them

The usual way to close these would be to exhaust them, but that may
not always be done by every code path...

Cheers,

Peter

------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
Sesame-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sesame-general
Reply | Threaded
Open this post in threaded view
|

Re: Reading an rdf:List into a Java list

josh
See:

    https://github.com/joshsh/sesametools/commit/02e1669ec61fad08f112006e9b5d7f98d4a72c71


On Thu, Oct 17, 2013 at 6:59 PM, Peter Ansell <[hidden email]> wrote:
[...]
The only issue with RuntimeException is that to catch them, for
legitimate purposes, you need to catch some exceptions such as NPEs
that you really don't want to catch. The alternative may be to define
specific runtime exception base class for SesameTools, say
SesameToolsRuntimeException. (I tend to use RuntimeException too often
in my code where I should either subclass it or create a checked
exception!)


I have taken basically that suggestion, only making the exception specific to RepositoryGraph (i.e. RepositoryGraphRuntimeException).


 

> 1) RepositoryGraph creates and wraps a RepositoryConnection, so you need to
> call its close() function when you are finished with it

Given that RepositoryGraph is likely to be used for a shorttime,
possibly only one function, it may be easier to make it take a
RepositoryConnection that the user still has to close, while making it
clear that they need to do so in the same way as other functions.


Changed.  Initially, I thought it would simplify the constructor to pass in a Repository instead of a RepositoryConnection, since Graph needs a ValueFactory.  However, a Repository's ValueFactory is available through its connections (unlike a Sail's).

 

> 2) the Iterators it returns wrap CloseableIterations, and there is currently
> no way to close them

The usual way to close these would be to exhaust them, but that may
not always be done by every code path...


Yes; for example, it's not unusual for an application to test for the existence of at least one matching statement, simply calling hasNext() on the iterator once without consuming any statements.


Josh



 

Cheers,

Peter


------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
Sesame-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sesame-general