PA4RDF works by mapping java methods to values in the graph and returning
those values converted to the proper Java type.  It uses the graph data
directly (i.e. it does not make a copy)

so that given a properly annotated interface like:

interface X {
  String getName();
  void setName(String name);
}


and a triple in a graph of

<foo> <name> "bart";

A call to the entity manager like
X xinst = entityManager.read( <foo>, X.class);

will allow you to call
System.out.println( xinst.getName())
xinst.setName("Simpson");
System.out.println( xinst.getName())

to print out
bart Simpson

If the interface returns another (or the same) annotated class, the entity
manager is automatically invoked to create the instance.

for example
interface Y {
X getThing();
setThing( X x );
}

and triples
<bar> <thing> <foo>
<foo> <name> "bart"

Y yinst = entityManager.read( <bar>, Y.class);

will allow you to call
X xinst = Y.getThing();
System.out.println( xinst.getName())
xinst.setName("Simpson");
System.out.println( xinst.getName())

full access to the underlying Resource object (e.g. <foo>) is also provided.

On Fri, Nov 28, 2014 at 1:59 AM, Stian Soiland-Reyes <
soiland-re...@cs.manchester.ac.uk> wrote:

> I have find it really nice to use the OntModel and the more specific
> types there, like Individual.
>
> It means I have to pre-load an ontology or RDFS schema (from URI or
> classpath) and set static fields for the different properties and
> classes I will enquire/construct with.
>
> See
> https://github.com/taverna/taverna-prov/blob/master/prov-taverna-owl-bindings/src/main/java/org/purl/wf4ever/provtaverna/owl/ProvModel.java
>
>
> When I have loaded I do null-checks as getObjectProperty returns null
> if I misspell the property name - thus I can catch this here rather
> than six steps later when trying to consume the broken RDF.
>
>
> After that I just use Individual as my domain objects and pass them to
> an instance of ProvModel (e.g. a graph) for any getters and setters.
> Example usage:
>
>
> https://github.com/taverna/taverna-prov/blob/master/prov-taverna-export/src/main/java/org/purl/wf4ever/provtaverna/export/W3ProvenanceExport.java#L253
>
> Saving is straight forward:
>
> https://github.com/taverna/taverna-prov/blob/master/prov-taverna-export/src/main/java/org/purl/wf4ever/provtaverna/export/W3ProvenanceExport.java#L388
>
>
>
> (You might notice that my approach fell apart as soon as I had
> multiple ontologies to use.. I did this as subclasses of ProvModel
> here
>
>
> https://github.com/taverna/taverna-prov/blob/master/prov-taverna-owl-bindings/src/main/java/org/purl/wf4ever/provtaverna/owl/TavernaProvModel.java
>
> .. but I was unable to get the inferencing right (you might not need
> this) - probably because I did the mistake of loading always a new
> OntModel instead of adding to it - I was hampered by my
> loadModelFromClassPath :) )
>
>
>
> Some of the things I wish was better:
>
> null-safe getObjectProperty etc.
> looking up values of object properties to get back pre-casted
> Individuals - my workaround:
>
> https://github.com/wf4ever/robundle/blob/master/src/main/java/org/purl/wf4ever/robundle/manifest/RDFToManifest.java#L214
>
> (one day I should prepare a patch to add that as a method on
> Individual or ObjectProperty)
>
>
>
>
> On 20 November 2014 at 22:13, David Moss <admo...@gmail.com> wrote:
> > Until now I have been treating Jena and RDF like a database connection.
> > I retrieved data and immediately converted it to familiar Java objects
> with
> > fields, getters, setters and methods.
> >
> >
> > Recently I have been wondering if it might be better to keep the data as
> a
> > Jena Model within the object and use Jena to do the manipulation.
> >
> >
> >
> > Retrieving a property value seems overly complex in syntax however.
> > Is there a better way to do this?
> >
> > .
> >
> > Model m = qe.execConstruct();
> >
> > m.setNsPrefixes(p);
> >
> > System.out.println(m.getProperty(null,
> >
> m.getProperty(m.expandPrefix("dc:title"))).getObject().asLiteral().toString(
> > ));
> >
> > .
> >
> >
> >
> > DM
> >
>
>
>
> --
> Stian Soiland-Reyes, myGrid team
> School of Computer Science
> The University of Manchester
> http://soiland-reyes.com/stian/work/ http://orcid.org/0000-0001-9842-9718
>



-- 
I like: Like Like - The likeliest place on the web
<http://like-like.xenei.com>
LinkedIn: http://www.linkedin.com/in/claudewarren

Reply via email to