You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@uima.apache.org by Jörn Kottmann <ko...@gmail.com> on 2011/06/06 12:12:37 UTC

How to deal with types which define allowed values?

Hi all,

the Cas Editor does not support types which have features which
are restricted by allowedValues.

It would be nice if I could get a little help to implement this correctly.

The CAS defines methods to retrieve the value of a feature, in case it is
a primitive feature the Cas Editor needs a method which retrieves the
primitive feature as a "primitive" java Object (e.g. Integer, Boolean, 
String, etc.).

The util method which does this, cannot deal with the case of allowedValues.

org.apache.uima.caseditor.editor.util.Primitives.getPrimitiv(...)

I believe it should test based on the primitive Type objects instead of 
the type name
and check if the input type is equal or a subtype. Based on that it 
should be possible
to call the CAS methods to retrieve the value.

Is it possible to determine if a Type restricts the values via allowed 
values,
and if so get a list of all allowed values? I would need both to create 
a combo
box where a user can select a value out of the allowed values.

Thanks,
Jörn




Re: How to deal with types which define allowed values?

Posted by Jörn Kottmann <ko...@gmail.com>.
I think the idea of a type system is that all feature structures are 
compliant to it.

If it says that a certain feature only can have two values, then that 
should always be true.
In the case the user does not care he can simply remove the allowed 
values from
the type definition.

Jörn

On 6/6/11 2:56 PM, Richard Eckart de Castilho wrote:
> Am 06.06.2011 um 14:15 schrieb Jörn Kottmann:
>
>> Shouldn't the call FeatureStructure.setStringFeature(...) fail if the
>> new string value is not
>> defined in the allowed values set?
> That is an interesting question. In fact I believe that it should not because that can cause trouble if somebody changes the TypeSystem retroactively.
>
>> Anyway that is not an issue for me since the Cas Editor will restrict it to set only allowed values.
> The CAS Editor should gracefully deal with the case that the CAS contains a value that is not currently allowed by the TypeSystem. It should not fail with an error, and it should allow to open and close the drop-down without selecting a valid value.
>
> I think such a behavior would be the most convenient for the users.
>
> Richard
>


Re: How to deal with types which define allowed values?

Posted by Richard Eckart de Castilho <ec...@tk.informatik.tu-darmstadt.de>.
Am 06.06.2011 um 14:15 schrieb Jörn Kottmann:

> Shouldn't the call FeatureStructure.setStringFeature(...) fail if the 
> new string value is not
> defined in the allowed values set?

That is an interesting question. In fact I believe that it should not because that can cause trouble if somebody changes the TypeSystem retroactively.

> Anyway that is not an issue for me since the Cas Editor will restrict it to set only allowed values.

The CAS Editor should gracefully deal with the case that the CAS contains a value that is not currently allowed by the TypeSystem. It should not fail with an error, and it should allow to open and close the drop-down without selecting a valid value.

I think such a behavior would be the most convenient for the users.

Richard

-- 
------------------------------------------------------------------- 
Richard Eckart de Castilho
Technical Lead
Ubiquitous Knowledge Processing Lab 
FB 20 Computer Science Department      
Technische Universität Darmstadt 
Hochschulstr. 10, D-64289 Darmstadt, Germany 
phone [+49] (0)6151 16-7477, fax -5455, room S2/02/B117
eckartde@tk.informatik.tu-darmstadt.de 
www.ukp.tu-darmstadt.de 
Web Research at TU Darmstadt (WeRC) www.werc.tu-darmstadt.de
------------------------------------------------------------------- 





Re: How to deal with types which define allowed values?

Posted by Jörn Kottmann <ko...@gmail.com>.
On 6/6/11 12:12 PM, Jörn Kottmann wrote:
> Hi all,
>
> the Cas Editor does not support types which have features which
> are restricted by allowedValues.
>
> It would be nice if I could get a little help to implement this 
> correctly.
>
> The CAS defines methods to retrieve the value of a feature, in case it is
> a primitive feature the Cas Editor needs a method which retrieves the
> primitive feature as a "primitive" java Object (e.g. Integer, Boolean, 
> String, etc.).
>
> The util method which does this, cannot deal with the case of 
> allowedValues.
>
> org.apache.uima.caseditor.editor.util.Primitives.getPrimitiv(...)
>
> I believe it should test based on the primitive Type objects instead 
> of the type name
> and check if the input type is equal or a subtype. Based on that it 
> should be possible
> to call the CAS methods to retrieve the value.

I re-factored the Primitives class a little, and now all tests are done 
on type objects
and noticed that it is possible to set a feature with a few allowed 
values just to anything?

Shouldn't the call FeatureStructure.setStringFeature(...) fail if the 
new string value is not
defined in the allowed values set?

Anyway that is not an issue for me since the Cas Editor will restrict it 
to set only
allowed values.

>
> Is it possible to determine if a Type restricts the values via allowed 
> values,
> and if so get a list of all allowed values? I would need both to 
> create a combo
> box where a user can select a value out of the allowed values.
I will use the LowLevelTypeSystem for this as proposed by Richard.

Jörn


Re: How to deal with types which define allowed values?

Posted by Richard Eckart de Castilho <ec...@tk.informatik.tu-darmstadt.de>.
Hi Jörn,

> Does LowLevelTypeSystem.getStringSet simply return an empty array in the case someone defined a string subtype but does not define allowed values? Or is it possible to define a string subtype with an empty set of allowed values?


It is possible to define a string sub-type without any allowed values and it this case you get an empty array. I used this little test case:

		TypeSystemDescription tsd = TypeSystemDescriptionFactory
				.createTypeSystemDescriptionFromPath("TypeSystem.xml");
		CAS cas = CasCreationUtils.createCas(tsd, null, null);

		ResourceSpecifierFactory factory = UIMAFramework.getResourceSpecifierFactory();
		TypeSystem typeSystem = cas.getTypeSystem();
		Type type = typeSystem.getType("POS");

		// check for string subtypes
		LowLevelTypeSystem lts = typeSystem.getLowLevelTypeSystem();
		final int typeCode = lts.ll_getCodeForType(type);
		String[] strings = lts.ll_getStringSet(typeCode);
		System.out.println(strings.length);
		for (int i = 0; i < strings.length; i++) {
			System.out.println(strings[i]);
		}

Cheers,

Richard

-- 
------------------------------------------------------------------- 
Richard Eckart de Castilho
Technical Lead
Ubiquitous Knowledge Processing Lab 
FB 20 Computer Science Department      
Technische Universität Darmstadt 
Hochschulstr. 10, D-64289 Darmstadt, Germany 
phone [+49] (0)6151 16-7477, fax -5455, room S2/02/B117
eckartde@tk.informatik.tu-darmstadt.de 
www.ukp.tu-darmstadt.de 
Web Research at TU Darmstadt (WeRC) www.werc.tu-darmstadt.de
------------------------------------------------------------------- 





Re: How to deal with types which define allowed values?

Posted by Jörn Kottmann <ko...@gmail.com>.
On 6/6/11 12:24 PM, Richard Eckart de Castilho wrote:
>        // check for string subtypes
>        if (type instanceof StringTypeImpl) {
> 	LowLevelTypeSystem lts = aTypeSystem.getLowLevelTypeSystem();
> 	final int typeCode = lts.ll_getCodeForType(type);
>          String[] strings = lts.ll_getStringSet(typeCode);
>          AllowedValue[] allowedVals = new AllowedValue[strings.length];
>          for (int i = 0; i<  strings.length; i++) {
>            allowedVals[i] = factory.createAllowedValue();
>            allowedVals[i].setString(strings[i]);
>          }
>          typeDesc.setAllowedValues(allowedVals);
>        }

Does LowLevelTypeSystem.getStringSet simply return an empty array in the 
case
someone defined a string subtype but does not define
allowed values? Or is it possible to define a string subtype
with an empty set of allowed values?

Jörn

Re: How to deal with types which define allowed values?

Posted by Richard Eckart de Castilho <ec...@tk.informatik.tu-darmstadt.de>.
Hi Jörn,

> Is it possible to determine if a Type restricts the values via allowed 
> values, and if so get a list of all allowed values? I would need both to create 
> a combo box where a user can select a value out of the allowed values.


there is a piece of code in TypeSystem2Xml.class which seems to extract AllowedValues from TypeSystem instance. I'd guess that's what you need.

UIMA 2.3.1 - TypeSystem2Xml.java:159ff

      // check for string subtypes
      if (type instanceof StringTypeImpl) {
	LowLevelTypeSystem lts = aTypeSystem.getLowLevelTypeSystem();
	final int typeCode = lts.ll_getCodeForType(type);
        String[] strings = lts.ll_getStringSet(typeCode);
        AllowedValue[] allowedVals = new AllowedValue[strings.length];
        for (int i = 0; i < strings.length; i++) {
          allowedVals[i] = factory.createAllowedValue();
          allowedVals[i].setString(strings[i]);
        }
        typeDesc.setAllowedValues(allowedVals);
      }

Cheers,

Richard

-- 
------------------------------------------------------------------- 
Richard Eckart de Castilho
Technical Lead
Ubiquitous Knowledge Processing Lab 
FB 20 Computer Science Department      
Technische Universität Darmstadt 
Hochschulstr. 10, D-64289 Darmstadt, Germany 
phone [+49] (0)6151 16-7477, fax -5455, room S2/02/B117
eckartde@tk.informatik.tu-darmstadt.de 
www.ukp.tu-darmstadt.de 
Web Research at TU Darmstadt (WeRC) www.werc.tu-darmstadt.de
-------------------------------------------------------------------