On 15/07/15 19:50, Neil Macwan wrote:
I am building a model in Jena and am able to add resources, statements, and 
properties to it.  I also want to add information to this model on its own 
provenance (the provenance of the model).  An example of this is Example 2 at 
http://www.w3.org/TR/prov-o/#narrative-example-expanded-1.   I've pulled out 
the part I'm interested in below:
@prefix xsd:  <http://www.w3.org/2001/XMLSchema#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix sioc: <http://rdfs.org/sioc/ns#> .
@prefix prov: <http://www.w3.org/ns/prov#> .
@prefix my:   <http://www.example.org/vocab#> .
@prefix :     <http://www.example.org#> .
@base         <http://www.example.com/derek-bundle.ttl> .

<>
    a prov:Bundle, prov:Entity;
    prov:wasAttributedTo :postEditor;
    prov:generatedAtTime "2011-07-16T02:52:02Z"^^xsd:dateTime;
.

:derek
    a prov:Person, prov:Agent; ## prov:Agent is inferred from prov:Person
    foaf:givenName       "Derek";
    foaf:mbox            <mailto:de...@example.org>;
    prov:actedOnBehalfOf :national_newspaper_inc;
.The resource described by "<>" describes the document itself.  It is a 
prov:Bundle and a prov:Entity with other attributes.  I am trying to do something similar for 
my models in Jena and have not been successful.  You can create resources, statements, and 
properties from a model and then link them and add them to the model but there does not seem to 
be a way of adding statements and properties to a model to describe the model itself.  Am I 
missing something or is there a way of doing this? Some sample code I have tried to achieve 
this is below, this outputs an anonymous resource.  How do I add statements to a model 
describing the model itself?
         Namespace provns =  new Namespace("prov","http://www.w3.org/ns/prov#";);                Model model = 
ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);        Property provEntity = model.createProperty(provns.getUri() + 
"Entity");        Property provBundle = model.createProperty(provns.getUri() + "Bundle");        Statement 
stmt =                model.createStatement(model.createResource(),provEntity,provBundle);        model.add(stmt);        
System.out.println("model=");        RDFDataMgr.write(System.out,model,Lang.TURTLE);
Output:model=@prefix owl:   <http://www.w3.org/2002/07/owl#> .@prefix rdf:   
<http://www.w3.org/1999/02/22-rdf-syntax-ns#> .@prefix xsd:   
<http://www.w3.org/2001/XMLSchema#> .@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> 
.
[ <http://www.w3.org/ns/prov#Entity>          
<http://www.w3.org/ns/prov#Bundle> ] .
Neil
                                        


Neil,

<> is a shorthand. RDF always works with absolute URIs. <> (which is the relative URI of the empty string, will be resolved to the base URI for the document. Try parsing your Turtle file to N-Triples and you will see what the <> becomes.

Try adding statements with that subject URI (absolute URI).

If you really want to force the <> in the output, writing with a base URI should do it:

String baseURI = "file:/// ....." ;
Model model = ..

WriterGraphRIOT w = RDFDataMgr.createGraphWriter(Lang.TTL) ;
w.write(System.out, model.getGraph(), null, baseURI, null) ;

which puts in @base.

        Andy

Reply via email to