The Dicer library
The Dicer Java library (groupId: org.incenp
, artifactId: dicer-lib
) provides several classes to work with OBO Foundry-style identifiers policy.
Using a ID policy file
Use the IDPolicyReader to parse a ID policy file:
IDPolicyReader reader = new IDPolicyReader(); IDPolicy policy = reader.read("myont-idranges.owl");
The returned IDPolicy object then allows to
- get details about the policy, such as the format of identifiers;
- get a list of all ID ranges in the policy, or unallocated ranges;
- find a range allocated to a given user;
- allocate a new range in the unallocated ID space.
When the policy object has been modified (by allocating new ranges), use the IDPolicyWriter class to write it back to a file.
The IDPolicyHelper class provides static methods to facilitate working with a ID policy. Notably, if all that is needed is to get the ID range allocated to a given user, the getRange()
method provides an easy way to do that:
IDRange range = getRange("Alice", null, null);
This will automatically get the range allocated to the user Alice in the default policy file (any file in the current directory with a name ending with -idranges.owl
).
Minting new identifiers
TheIAutoIDGenerator interface represents any object that can generate new identifiers. The library provides two different implementations of it:
- SequentialIDGenerator, to generate IDs with numerical suffixes picked sequentially within a range;
- RandomizedIDGenerator, to generate IDs with numerical suffixes picked randomly within a range.
Once a generator has been identified, simply call the nextID()
method to mint a new identifier.
The generators can be identified with an implementation of IExistenceChecker to ensure they only generate IDs that are not already in use.