You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Ralph Perniciaro <ra...@eagles.usm.edu> on 2013/10/17 19:15:50 UTC

Export Resource/Individual to RDF

All,

What is the best way to export an individual from a Model to RDF.  I don't
want to export the entire Model to RDF, just a specific individual or
resource.  Also, I would like to include any resources that the individual
is related to, along with it's properties, if it is defined in that model.
 Another way of looking at this would be replicating a resource and its
associated resources to another model.

Thanks in advance!

Ralph

Re: Export Resource/Individual to RDF

Posted by Andy Seaborne <an...@apache.org>.
On 18/10/13 13:35, Joshua TAYLOR wrote:
> On Fri, Oct 18, 2013 at 3:28 AM, Dave Reynolds
> <da...@gmail.com> wrote:
>> If the description of a resource that you want is a "closed, bounded
>> description" then you can use the Closure utility:
>>
>>     Closure.closure(startingResource, false, mymodel)
>>
>> Which would be equivalent to using ARQ's describe query.
>
> This isn't new, is it?  I don't remember seeing it before, but I wish
> I had!  (And given that no one else mentioned it, I guess not too many
> others (who follow the list, anyhow) have either.  Pity.)
>

It's what backs DESCRIBE (by default).

	Andy


Re: Export Resource/Individual to RDF

Posted by Joshua TAYLOR <jo...@gmail.com>.
On Fri, Oct 18, 2013 at 3:28 AM, Dave Reynolds
<da...@gmail.com> wrote:
> If the description of a resource that you want is a "closed, bounded
> description" then you can use the Closure utility:
>
>    Closure.closure(startingResource, false, mymodel)
>
> Which would be equivalent to using ARQ's describe query.

This isn't new, is it?  I don't remember seeing it before, but I wish
I had!  (And given that no one else mentioned it, I guess not too many
others (who follow the list, anyhow) have either.  Pity.)

-- 
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/

Re: Export Resource/Individual to RDF

Posted by Dave Reynolds <da...@gmail.com>.
On 18/10/13 15:07, Ralph Perniciaro wrote:
> This is great.  I also found this utility as well.  Not sure of the
> difference, but it does what I needed.
>
>          Model m = ResourceUtils.reachableClosure(Resource r);

The difference is that Closure.closure is a bNode closure, it doesn't 
follow connections through URI resources. Whereas 
ResourceUtils.reachableClosure finds connected subgraphs and does follow 
connections through URI resources.

Dave

> On Fri, Oct 18, 2013 at 2:28 AM, Dave Reynolds <da...@gmail.com>wrote:
>
>> If the description of a resource that you want is a "closed, bounded
>> description" then you can use the Closure utility:
>>
>>     Closure.closure(**startingResource, false, mymodel)
>>
>> Which would be equivalent to using ARQ's describe query.
>>
>> Dave
>>
>>
>> On 17/10/13 21:52, Ralph Perniciaro wrote:
>>
>>> Thanks for the info.  I am doing exactly what you mention in your first
>>> email(Copying statements into another model).  Using a recursive function
>>> to handle the depth.  I'm still not completely happy with the function
>>> yet,
>>> that is why I thought to ask in case I was making this harder then it
>>> needed to be.
>>>
>>> Ralph
>>>
>>>
>>> On Thu, Oct 17, 2013 at 2:09 PM, Joshua TAYLOR <joshuaaaron@gmail.com
>>>> wrote:
>>>
>>>   On Thu, Oct 17, 2013 at 3:07 PM, Joshua TAYLOR <jo...@gmail.com>
>>>> wrote:
>>>>
>>>>> On Thu, Oct 17, 2013 at 1:15 PM, Ralph Perniciaro
>>>>> <ralph.perniciaro@eagles.usm.**edu <ra...@eagles.usm.edu>>
>>>>> wrote:
>>>>>
>>>>>> What is the best way to export an individual from a Model to RDF.  I
>>>>>>
>>>>> don't
>>>>
>>>>> want to export the entire Model to RDF, just a specific individual or
>>>>>> resource.  Also, I would like to include any resources that the
>>>>>>
>>>>> individual
>>>>
>>>>> is related to, along with it's properties, if it is defined in that
>>>>>>
>>>>> model.
>>>>
>>>>>    Another way of looking at this would be replicating a resource and its
>>>>>> associated resources to another model.
>>>>>>
>>>>>
>>>>> It's probably creating a new model, iterating through the statements
>>>>> that have that resource as a subject, and adding those statements to
>>>>> the new model. You could do this with Model.listStatements(...) [1],
>>>>> which returns a StmtIterator, and model.add(StmtIterator) [2].  I
>>>>> would look more or less like:
>>>>>
>>>>> newModel.add( oldModel.listStatements( theResource, null, null ));
>>>>>
>>>>
>>>> Rereading your original email, it seems like you might have wanted
>>>> another level deep, in which case you could do it with listStatements,
>>>> but it's probably easier to just run a SPARQL construct query that
>>>> will return a model to you.  It'd look like
>>>>
>>>> construct { <theResource> ?p ?o . ?o ?p2 ?o2 . }
>>>>
>>>>
>>>> --
>>>> Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
>>>>
>>>>
>>>
>>
>


Re: Export Resource/Individual to RDF

Posted by Ralph Perniciaro <ra...@eagles.usm.edu>.
This is great.  I also found this utility as well.  Not sure of the
difference, but it does what I needed.

        Model m = ResourceUtils.reachableClosure(Resource r);



On Fri, Oct 18, 2013 at 2:28 AM, Dave Reynolds <da...@gmail.com>wrote:

> If the description of a resource that you want is a "closed, bounded
> description" then you can use the Closure utility:
>
>    Closure.closure(**startingResource, false, mymodel)
>
> Which would be equivalent to using ARQ's describe query.
>
> Dave
>
>
> On 17/10/13 21:52, Ralph Perniciaro wrote:
>
>> Thanks for the info.  I am doing exactly what you mention in your first
>> email(Copying statements into another model).  Using a recursive function
>> to handle the depth.  I'm still not completely happy with the function
>> yet,
>> that is why I thought to ask in case I was making this harder then it
>> needed to be.
>>
>> Ralph
>>
>>
>> On Thu, Oct 17, 2013 at 2:09 PM, Joshua TAYLOR <joshuaaaron@gmail.com
>> >wrote:
>>
>>  On Thu, Oct 17, 2013 at 3:07 PM, Joshua TAYLOR <jo...@gmail.com>
>>> wrote:
>>>
>>>> On Thu, Oct 17, 2013 at 1:15 PM, Ralph Perniciaro
>>>> <ralph.perniciaro@eagles.usm.**edu <ra...@eagles.usm.edu>>
>>>> wrote:
>>>>
>>>>> What is the best way to export an individual from a Model to RDF.  I
>>>>>
>>>> don't
>>>
>>>> want to export the entire Model to RDF, just a specific individual or
>>>>> resource.  Also, I would like to include any resources that the
>>>>>
>>>> individual
>>>
>>>> is related to, along with it's properties, if it is defined in that
>>>>>
>>>> model.
>>>
>>>>   Another way of looking at this would be replicating a resource and its
>>>>> associated resources to another model.
>>>>>
>>>>
>>>> It's probably creating a new model, iterating through the statements
>>>> that have that resource as a subject, and adding those statements to
>>>> the new model. You could do this with Model.listStatements(...) [1],
>>>> which returns a StmtIterator, and model.add(StmtIterator) [2].  I
>>>> would look more or less like:
>>>>
>>>> newModel.add( oldModel.listStatements( theResource, null, null ));
>>>>
>>>
>>> Rereading your original email, it seems like you might have wanted
>>> another level deep, in which case you could do it with listStatements,
>>> but it's probably easier to just run a SPARQL construct query that
>>> will return a model to you.  It'd look like
>>>
>>> construct { <theResource> ?p ?o . ?o ?p2 ?o2 . }
>>>
>>>
>>> --
>>> Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
>>>
>>>
>>
>

Re: Export Resource/Individual to RDF

Posted by Dave Reynolds <da...@gmail.com>.
If the description of a resource that you want is a "closed, bounded 
description" then you can use the Closure utility:

    Closure.closure(startingResource, false, mymodel)

Which would be equivalent to using ARQ's describe query.

Dave

On 17/10/13 21:52, Ralph Perniciaro wrote:
> Thanks for the info.  I am doing exactly what you mention in your first
> email(Copying statements into another model).  Using a recursive function
> to handle the depth.  I'm still not completely happy with the function yet,
> that is why I thought to ask in case I was making this harder then it
> needed to be.
>
> Ralph
>
>
> On Thu, Oct 17, 2013 at 2:09 PM, Joshua TAYLOR <jo...@gmail.com>wrote:
>
>> On Thu, Oct 17, 2013 at 3:07 PM, Joshua TAYLOR <jo...@gmail.com>
>> wrote:
>>> On Thu, Oct 17, 2013 at 1:15 PM, Ralph Perniciaro
>>> <ra...@eagles.usm.edu> wrote:
>>>> What is the best way to export an individual from a Model to RDF.  I
>> don't
>>>> want to export the entire Model to RDF, just a specific individual or
>>>> resource.  Also, I would like to include any resources that the
>> individual
>>>> is related to, along with it's properties, if it is defined in that
>> model.
>>>>   Another way of looking at this would be replicating a resource and its
>>>> associated resources to another model.
>>>
>>> It's probably creating a new model, iterating through the statements
>>> that have that resource as a subject, and adding those statements to
>>> the new model. You could do this with Model.listStatements(...) [1],
>>> which returns a StmtIterator, and model.add(StmtIterator) [2].  I
>>> would look more or less like:
>>>
>>> newModel.add( oldModel.listStatements( theResource, null, null ));
>>
>> Rereading your original email, it seems like you might have wanted
>> another level deep, in which case you could do it with listStatements,
>> but it's probably easier to just run a SPARQL construct query that
>> will return a model to you.  It'd look like
>>
>> construct { <theResource> ?p ?o . ?o ?p2 ?o2 . }
>>
>>
>> --
>> Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
>>
>


Re: Export Resource/Individual to RDF

Posted by Ralph Perniciaro <ra...@eagles.usm.edu>.
Thanks for the info.  I am doing exactly what you mention in your first
email(Copying statements into another model).  Using a recursive function
to handle the depth.  I'm still not completely happy with the function yet,
that is why I thought to ask in case I was making this harder then it
needed to be.

Ralph


On Thu, Oct 17, 2013 at 2:09 PM, Joshua TAYLOR <jo...@gmail.com>wrote:

> On Thu, Oct 17, 2013 at 3:07 PM, Joshua TAYLOR <jo...@gmail.com>
> wrote:
> > On Thu, Oct 17, 2013 at 1:15 PM, Ralph Perniciaro
> > <ra...@eagles.usm.edu> wrote:
> >> What is the best way to export an individual from a Model to RDF.  I
> don't
> >> want to export the entire Model to RDF, just a specific individual or
> >> resource.  Also, I would like to include any resources that the
> individual
> >> is related to, along with it's properties, if it is defined in that
> model.
> >>  Another way of looking at this would be replicating a resource and its
> >> associated resources to another model.
> >
> > It's probably creating a new model, iterating through the statements
> > that have that resource as a subject, and adding those statements to
> > the new model. You could do this with Model.listStatements(...) [1],
> > which returns a StmtIterator, and model.add(StmtIterator) [2].  I
> > would look more or less like:
> >
> > newModel.add( oldModel.listStatements( theResource, null, null ));
>
> Rereading your original email, it seems like you might have wanted
> another level deep, in which case you could do it with listStatements,
> but it's probably easier to just run a SPARQL construct query that
> will return a model to you.  It'd look like
>
> construct { <theResource> ?p ?o . ?o ?p2 ?o2 . }
>
>
> --
> Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
>

Re: Export Resource/Individual to RDF

Posted by Joshua TAYLOR <jo...@gmail.com>.
On Thu, Oct 17, 2013 at 3:07 PM, Joshua TAYLOR <jo...@gmail.com> wrote:
> On Thu, Oct 17, 2013 at 1:15 PM, Ralph Perniciaro
> <ra...@eagles.usm.edu> wrote:
>> What is the best way to export an individual from a Model to RDF.  I don't
>> want to export the entire Model to RDF, just a specific individual or
>> resource.  Also, I would like to include any resources that the individual
>> is related to, along with it's properties, if it is defined in that model.
>>  Another way of looking at this would be replicating a resource and its
>> associated resources to another model.
>
> It's probably creating a new model, iterating through the statements
> that have that resource as a subject, and adding those statements to
> the new model. You could do this with Model.listStatements(...) [1],
> which returns a StmtIterator, and model.add(StmtIterator) [2].  I
> would look more or less like:
>
> newModel.add( oldModel.listStatements( theResource, null, null ));

Rereading your original email, it seems like you might have wanted
another level deep, in which case you could do it with listStatements,
but it's probably easier to just run a SPARQL construct query that
will return a model to you.  It'd look like

construct { <theResource> ?p ?o . ?o ?p2 ?o2 . }


-- 
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/

Re: Export Resource/Individual to RDF

Posted by Chris_Dollin <eh...@gmail.com>.
On Thursday, October 17, 2013 03:07:07 PM Joshua TAYLOR wrote:
> On Thu, Oct 17, 2013 at 1:15 PM, Ralph Perniciaro
> 
> <ra...@eagles.usm.edu> wrote:
> > What is the best way to export an individual from a Model to RDF.  I don't
> > want to export the entire Model to RDF, just a specific individual or
> > resource.  Also, I would like to include any resources that the individual
> > is related to, along with it's properties, if it is defined in that model.
> > 
> >  Another way of looking at this would be replicating a resource and its
> > 
> > associated resources to another model.
> 
> It's probably creating a new model, iterating through the statements
> that have that resource as a subject, and adding those statements to
> the new model. You could do this with Model.listStatements(...) [1],
> which returns a StmtIterator, and model.add(StmtIterator) [2].  I
> would look more or less like:
> 
> newModel.add( oldModel.listStatements( theResource, null, null ));

If the object of a property is a blank node, probably want to copy
/its/ properties also. Making sure that repetition and loops are 
handled.

Chris

Re: Export Resource/Individual to RDF

Posted by Joshua TAYLOR <jo...@gmail.com>.
On Thu, Oct 17, 2013 at 1:15 PM, Ralph Perniciaro
<ra...@eagles.usm.edu> wrote:
> What is the best way to export an individual from a Model to RDF.  I don't
> want to export the entire Model to RDF, just a specific individual or
> resource.  Also, I would like to include any resources that the individual
> is related to, along with it's properties, if it is defined in that model.
>  Another way of looking at this would be replicating a resource and its
> associated resources to another model.

It's probably creating a new model, iterating through the statements
that have that resource as a subject, and adding those statements to
the new model. You could do this with Model.listStatements(...) [1],
which returns a StmtIterator, and model.add(StmtIterator) [2].  I
would look more or less like:

newModel.add( oldModel.listStatements( theResource, null, null ));

//JT

[1] http://jena.apache.org/documentation/javadoc/jena/com/hp/hpl/jena/rdf/model/Model.html#listStatements(com.hp.hpl.jena.rdf.model.Resource,
com.hp.hpl.jena.rdf.model.Property, com.hp.hpl.jena.rdf.model.RDFNode)
[2] http://jena.apache.org/documentation/javadoc/jena/com/hp/hpl/jena/rdf/model/Model.html#add(com.hp.hpl.jena.rdf.model.StmtIterator)

-- 
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/