Generating Jena Bnode IDs

喜夏-厌秋 提交于 2019-12-11 15:13:31

问题


Is there a way to override Jena's default method for generating anonymous node IDs?

Ideally, I'd like to pass Jena a functor that would generate IDs so that I can make them globally unique (rather than just unique to the machine). The functor should be used whenever an AnonId is constructed.

public interface IdGenerator {
   public String createId() {
      // create a globally unique ID
      ...
      return uid;
   }
}

This is somewhat related to my previous question.

Edit: I realize that AnonId has a constructor that takes an id parameter. I'm hoping to avoid invoking this constructor all over the place, and instead simply tell Jena (once) how to generate IDs.

Edit 2: Even if I didn't mind invoking that constructor all over the place, it may not be possible because anonymous nodes may be created by library code that I don't have access to.


回答1:


Jena doesn't have any hooks for plugging in a different AnonId generator. Creation of AnonIds isn't centralised in one place either, so there isn't an easy way to enforce the use of new AnonId(String) either. The best way of achieving your goal would be to patch the AnonId source, which would be straightforward enough.

FWIW, the AnonId code already has two different ways of generating the IDs, so adding an abstraction for this to the Jena codebase might be a reasonable idea.



来源:https://stackoverflow.com/questions/728025/generating-jena-bnode-ids

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!