You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Fajar Juang <fa...@gmail.com> on 2018/07/27 17:06:12 UTC

Converting BNode to Resource

Dear all, 

I am curious whether there is exist a method in Jena that can conveniently “convert” a blank node to a resource.

e.g., suppose that I have a model M1 that contains a blank node _:a which has several properties (e.g., rdfs:label, etc),
I would like to execute something like:  M1.convertBNodeToResource(M1, _:a, “http://example.org/ns#test <http://example.org/ns#test>”)
to replace BNode _:a with Resource with URI “http://example.org/ns#test <http://example.org/ns#test>” (note: the URI in my use case will be taken from the BNode label + namespace)

The current (naive) solution that I have is to:
- add statements (?s ?p <http://example.org/ns#test <http://example.org/ns#test>> & <http://example.org/ns#test <http://example.org/ns#test>> ?p ?o); and 
- remove (?s ?p _:a & _:a ?p ?o) afterwards.

Do you have any suggestions to improve this code?

Thanks in advance for your help!

Best regards, 
--
Fajar J. Ekaputra
194/1 Information & Software Engineering Group,
Technische Universität Wien (TUWien).
W: http://juang.id Skype: fajar.juang


Re: Converting BNode to Resource

Posted by Fajar Juang <fa...@gmail.com>.
Thanks a lot for the pointers Charles and Andy!
Indeed, scalability is part of the considerations for the use case.
I’ll do some test to see which one would be more suitable.

Best regards,
--
Fajar J. Ekaputra
194/1 Information & Software Engineering Group,
Technische Universität Wien (TUWien).
W: http://juang.id Skype: fajar.juang

> On 28.07.2018, at 11:37, Andy Seaborne <an...@apache.org> wrote:
> 
> ResourceUtils.renameResource (the Resource class covers both blank nodes and URIs) provides some machinery for this task.
> 
> As Charles says, if you have a large amount of data in syntax form, then treating as a text processing problem is well-worth considering.
> 
> 	Andy
> 
> 
> On 27/07/18 18:09, Charles Greer wrote:
>> It looks like a reasonable solution to me if you have to work with parsed RDF.
>> It might be higher performance to treat it as a text processing problem... if your data is available in ntriples or nquads
>> you can use regular expressions to accomplish the task.
>> Charles
>> Charles Greer
>> Lead Engineer
>> MarkLogic Corporation
>> cgreer@marklogic.com
>> Cell:  +1 707 318 0442
>> @grechaw
>> www.marklogic.com
>> ________________________________
>> From: Fajar Juang <fa...@gmail.com>
>> Sent: Friday, July 27, 2018 10:06:12 AM
>> To: users@jena.apache.org
>> Subject: Converting BNode to Resource
>> Dear all,
>> I am curious whether there is exist a method in Jena that can conveniently “convert” a blank node to a resource.
>> e.g., suppose that I have a model M1 that contains a blank node _:a which has several properties (e.g., rdfs:label, etc),
>> I would like to execute something like:  M1.convertBNodeToResource(M1, _:a, “http://example.org/ns#test <http://example.org/ns#test>”)
>> to replace BNode _:a with Resource with URI “http://example.org/ns#test <http://example.org/ns#test>” (note: the URI in my use case will be taken from the BNode label + namespace)
>> The current (naive) solution that I have is to:
>> - add statements (?s ?p <http://example.org/ns#test <http://example.org/ns#test>> & <http://example.org/ns#test <http://example.org/ns#test>> ?p ?o); and
>> - remove (?s ?p _:a & _:a ?p ?o) afterwards.
>> Do you have any suggestions to improve this code?
>> Thanks in advance for your help!
>> Best regards,
>> --
>> Fajar J. Ekaputra
>> 194/1 Information & Software Engineering Group,
>> Technische Universität Wien (TUWien).
>> W: http://juang.id Skype: fajar.juang


Re: Converting BNode to Resource

Posted by Andy Seaborne <an...@apache.org>.
ResourceUtils.renameResource (the Resource class covers both blank nodes 
and URIs) provides some machinery for this task.

As Charles says, if you have a large amount of data in syntax form, then 
treating as a text processing problem is well-worth considering.

	Andy


On 27/07/18 18:09, Charles Greer wrote:
> It looks like a reasonable solution to me if you have to work with parsed RDF.
> 
> It might be higher performance to treat it as a text processing problem... if your data is available in ntriples or nquads
> 
> you can use regular expressions to accomplish the task.
> 
> 
> Charles
> 
> 
> Charles Greer
> Lead Engineer
> MarkLogic Corporation
> cgreer@marklogic.com
> Cell:  +1 707 318 0442
> @grechaw
> www.marklogic.com
> 
> ________________________________
> From: Fajar Juang <fa...@gmail.com>
> Sent: Friday, July 27, 2018 10:06:12 AM
> To: users@jena.apache.org
> Subject: Converting BNode to Resource
> 
> Dear all,
> 
> I am curious whether there is exist a method in Jena that can conveniently “convert” a blank node to a resource.
> 
> e.g., suppose that I have a model M1 that contains a blank node _:a which has several properties (e.g., rdfs:label, etc),
> I would like to execute something like:  M1.convertBNodeToResource(M1, _:a, “http://example.org/ns#test <http://example.org/ns#test>”)
> to replace BNode _:a with Resource with URI “http://example.org/ns#test <http://example.org/ns#test>” (note: the URI in my use case will be taken from the BNode label + namespace)
> 
> The current (naive) solution that I have is to:
> - add statements (?s ?p <http://example.org/ns#test <http://example.org/ns#test>> & <http://example.org/ns#test <http://example.org/ns#test>> ?p ?o); and
> - remove (?s ?p _:a & _:a ?p ?o) afterwards.
> 
> Do you have any suggestions to improve this code?
> 
> Thanks in advance for your help!
> 
> Best regards,
> --
> Fajar J. Ekaputra
> 194/1 Information & Software Engineering Group,
> Technische Universität Wien (TUWien).
> W: http://juang.id Skype: fajar.juang
> 
> 

Re: Converting BNode to Resource

Posted by Charles Greer <Ch...@marklogic.com>.
It looks like a reasonable solution to me if you have to work with parsed RDF.

It might be higher performance to treat it as a text processing problem... if your data is available in ntriples or nquads

you can use regular expressions to accomplish the task.


Charles


Charles Greer
Lead Engineer
MarkLogic Corporation
cgreer@marklogic.com
Cell:  +1 707 318 0442
@grechaw
www.marklogic.com

________________________________
From: Fajar Juang <fa...@gmail.com>
Sent: Friday, July 27, 2018 10:06:12 AM
To: users@jena.apache.org
Subject: Converting BNode to Resource

Dear all,

I am curious whether there is exist a method in Jena that can conveniently “convert” a blank node to a resource.

e.g., suppose that I have a model M1 that contains a blank node _:a which has several properties (e.g., rdfs:label, etc),
I would like to execute something like:  M1.convertBNodeToResource(M1, _:a, “http://example.org/ns#test <http://example.org/ns#test>”)
to replace BNode _:a with Resource with URI “http://example.org/ns#test <http://example.org/ns#test>” (note: the URI in my use case will be taken from the BNode label + namespace)

The current (naive) solution that I have is to:
- add statements (?s ?p <http://example.org/ns#test <http://example.org/ns#test>> & <http://example.org/ns#test <http://example.org/ns#test>> ?p ?o); and
- remove (?s ?p _:a & _:a ?p ?o) afterwards.

Do you have any suggestions to improve this code?

Thanks in advance for your help!

Best regards,
--
Fajar J. Ekaputra
194/1 Information & Software Engineering Group,
Technische Universität Wien (TUWien).
W: http://juang.id Skype: fajar.juang