开发者

Generating URIs in Jena for RDF

I am generating an RDF file programmatically in Jena i.e. when I am inserting data in the rdf (instances) i need to have an unique URI (which will refer to the resource), somewhat like primary key in rdbms. I want to know is it posiible to do in Jena like when I will create Resource for an instance I can generate the URI ?

Example :

Resource resAnswer = ModelCreation.md.createResource(RDFResourcesURI.Answer_Resource_URI + answer.getAnswer_id());

-- here I am hardcoding (or user input) the answer_id and then appending to a predefined URI. Instead of hardcoding can I generate it (like auto开发者_JS百科 increment in mysql ) ?


There's a URI scheme for UUIDs http://www.ietf.org/rfc/rfc4122.txt, so you can use that to turn UUIDs into URIs, e.g. e.g. urn:uuid:2238b240-f3eb-11e0-be50-0800200c9a66

Alternatively you can just append the UUID to some prefix, e.g. http://my.example/id/2238b240-f3eb-11e0-be50-0800200c9a66

HTTP based onetime URIs are good if you want to be able to make it resolvable.


If you want just unique ID, you may use something like UUID.randomUUID() or UUID.fromString(name)

UUID is in java.util package


I use URN's for identifying my RDF resources as URL's add not much value since I'm not publishing my resources. There's a Jena library to generate UUID in the form of URN's.

scala> import com.hp.hpl.jena.shared.uuid.JenaUUID
import com.hp.hpl.jena.shared.uuid.JenaUUID

scala> val resourceURN = JenaUUID.generate().asURN()
resourceURN: String = urn:uuid:0a9ac70c-2ad1-11b2-8012-10ddb1d60524
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜