I have another suggestion that I believe
- is user friendly,
- is fully backward compatible,
- does not involve changes to our descriptors,
- is not too kludgy,
- and only conservatively extends the API.
I hope I have your attention ;-)
I suggest we introduce a new built-in type and new built-in index as
follows.
- a type uima.cas.FsVariable that inherits from uima.cas.TOP with
features name:String, type:String and value:TOP.
- a built-in set index over FsVariable, sorted by the name feature.
One could imagine various approaches to APIs over these basic
datastructures. The simplest approach would be to add
CAS.setFsVariable(String name, FS fs)
CAS.getFsVariable(String name):FS
setFsVariable() would check if the variable existed. If so, it would
make sure the new value has the same type as the previous one (issues
surrounding null values need to be taken care of). This would be the
dynamic approach to variable declaration.
Alternatively, we could add more APIs:
CAS.declareFsVariable(String name, Type type)
CAS.isFsVariable(String name):boolean
CAS.getFsVariableType(String name):Type
declareFsVariable() would declare the variable and throw an exception if
it already existed. setFsVariable() and getFsVariable() would also
throw exceptions for non-declared variables. This would allow us to
ensure that a variable can be declared in one place only.
isFsVariable() would check if a variable of that name had been declared
already. getFsVariableType() would do the obvious.
I personally like this explicit approach to typing better, but it does
make the API more verbose.
The whole mechanism is completely transparent as it only uses existing
features. All data is kept in the CAS, there is nothing
CAS-implementation specific here. All the FsVariable APIs could be
implemented using public APIs only, so are easily portable to our other
implementation platforms if desired. There is no problem with
serialization as there are no changes to the CAS.
Please let me know if you think this is a good idea, and if so, if
you're in favor of the dynamically typed or the pseudo-statically typed
version.
--Thilo