Generating Jena Bnode IDs

2019-08-25 10:03发布

问题:

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.