org.apache.uima.cas.impl
Class TypeSystemImpl

java.lang.Object
  extended by org.apache.uima.cas.impl.TypeSystemImpl
All Implemented Interfaces:
TypeSystemMgr, LowLevelTypeSystem, TypeSystem

public class TypeSystemImpl
extends java.lang.Object
implements TypeSystemMgr, LowLevelTypeSystem

Type system implementation.


Field Summary
 int annotSofaFeatCode
           
 int sofaNumFeatCode
           
 
Fields inherited from interface org.apache.uima.cas.TypeSystem
FEATURE_SEPARATOR, NAMESPACE_SEPARATOR
 
Fields inherited from interface org.apache.uima.cas.impl.LowLevelTypeSystem
UNKNOWN_FEATURE_CODE, UNKNOWN_TYPE_CODE
 
Constructor Summary
TypeSystemImpl()
           
TypeSystemImpl(CASImpl cas)
          Deprecated. Use 0 arg constructor. Type Systems are shared by many CASes, and can't point to one. Change also your possible calls to ts.commit() - see comment on that method.
 
Method Summary
 Feature addFeature(java.lang.String featureName, Type domainType, Type rangeType)
          Add an feature to the type system.
 Feature addFeature(java.lang.String featureName, Type domainType, Type rangeType, boolean multipleReferencesAllowed)
          Add an feature to the type system.
 Type addStringSubtype(java.lang.String typeName, java.lang.String[] stringList)
          Inherit from String.
 Type addTopType(java.lang.String name)
          Add a top type to the (empty) type system.
 Type addType(java.lang.String typeName, Type mother)
          Add a new type to the type system.
 void commit()
          Commit the type system.
 boolean directlySubsumes(int t1, int t2)
           
 Type getArrayType(Type componentType)
          Obtain an array type with component type componentType.
 java.util.Vector<Type> getDirectlySubsumedTypes(Type type)
          Get a vector of the types directly subsumed by a given type.
 java.util.List<Type> getDirectSubtypes(Type type)
          Get a List of the types directly subsumed by a given type.
 Feature getFeature(java.lang.String featureName)
          Deprecated.  
 Feature getFeatureByFullName(java.lang.String featureName)
          Get an feature object for a given name.
 java.util.Iterator<Feature> getFeatures()
          Get a list of features, in no particular order.
 java.util.Vector<Feature> getIntroFeatures(Type type)
           
 int getLargestTypeCode()
           
 LowLevelTypeSystem getLowLevelTypeSystem()
          Return the low-level view of this type system.
 int getNumberOfFeatures()
          Get the overall number of features defined in the type system.
 int getNumberOfTypes()
          Get the overall number of types defined in the type system.
 Type getParent(Type t)
          Get the parent type for input type.
 java.util.List<Type> getProperlySubsumedTypes(Type type)
          Return the list of all types subsumed by the input type.
 java.lang.String[] getStringSet(int i)
           
 Type getTopType()
          Get the top type, i.e., the root of the type system.
 Type getType(java.lang.String typeName)
          Get a type object for a given name.
 java.util.Iterator<Type> getTypeIterator()
          Get an iterator over all types, in no particular order.
 TypeNameSpace getTypeNameSpace(java.lang.String name)
          Create a type name space object for the name parameter.
 int intro(int feat)
          Get the domain type for a feature.
 boolean isApprop(int type, int feat)
          Check if feature is appropriate for type (i.e., type is subsumed by domain type of feature).
 boolean isCommitted()
          Check if this instance has been committed.
 boolean isType(int type)
           
 int[] ll_getAppropriateFeatures(int type)
          Get an array of the appropriate features for this type.
 int ll_getArrayType(int componentTypeCode)
          Get the type code for the array type with componentTypeCode as component type code.
 int ll_getCodeForFeature(Feature feature)
          Get the code for a given feature object.
 int ll_getCodeForFeatureName(java.lang.String featureName)
          Get the feature code for a given feature name.
 int ll_getCodeForType(Type type)
          Get the code of an existing type object.
 int ll_getCodeForTypeName(java.lang.String typeName)
          Get the type code for a given type name.
 int ll_getComponentType(int arrayTypeCode)
          Get the component type of an array type code.
 int ll_getDomainType(int featureCode)
          Get the domain type for a given feature.
 Feature ll_getFeatureForCode(int featureCode)
          Get a feature object for a given code.
 int ll_getParentType(int typeCode)
          Get the parent type for the input type.
 int ll_getRangeType(int featureCode)
          Get the range type for a given feature.
 java.lang.String[] ll_getStringSet(int typeCode)
          Get the string set (sorted) for a string subtype.
 int ll_getTypeClass(int typeCode)
          Determine the type class of a type.
 Type ll_getTypeForCode(int typeCode)
          Get a type object for a given code.
 boolean ll_isArrayType(int typeCode)
          Check if typeCode is the type code of an array type.
 boolean ll_isPrimitiveType(int typeCode)
          Check if typeCode is the type code of a primitive type.
 boolean ll_isRefType(int typeCode)
          Checks if the type code is that of a reference type (anything that's not a basic type, currently Integer, String, Float, Boolean, Byte, Short, Long, Double, and subtypes of String - specifying allowed-values).
 boolean ll_isStringSubtype(int type)
          Check if type is a string subtype.
 boolean ll_isValidTypeCode(int typeCode)
          Check the input type code.
 boolean ll_subsumes(int superType, int type)
          Check subsumption between two types.
 int range(int feat)
          Get the range type for a feature.
 void setFeatureFinal(Type type)
          Make type feature final in the sense that no new features can be added to this type.
 void setInheritanceFinal(Type type)
          Block any further inheritance from this type.
 boolean subsumes(int superType, int type)
          Check if the first argument subsumes the second
 boolean subsumes(Type superType, Type subType)
          Does one type inherit from the other?
 java.lang.String toString()
          This writes out the type hierarchy in a human-readable form.
 int unify(int t1, int t2)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

sofaNumFeatCode

public int sofaNumFeatCode

annotSofaFeatCode

public int annotSofaFeatCode
Constructor Detail

TypeSystemImpl

@Deprecated
public TypeSystemImpl(CASImpl cas)
Deprecated. Use 0 arg constructor. Type Systems are shared by many CASes, and can't point to one. Change also your possible calls to ts.commit() - see comment on that method.

Default constructor.


TypeSystemImpl

public TypeSystemImpl()
Method Detail

getIntroFeatures

public java.util.Vector<Feature> getIntroFeatures(Type type)

getParent

public Type getParent(Type t)
Description copied from interface: TypeSystem
Get the parent type for input type.

Specified by:
getParent in interface TypeSystem
Parameters:
t - The type we want to know the parent of.
Returns:
The parent type, or null for the top type.

ll_getParentType

public int ll_getParentType(int typeCode)
Description copied from interface: LowLevelTypeSystem
Get the parent type for the input type.

Specified by:
ll_getParentType in interface LowLevelTypeSystem
Parameters:
typeCode - The type code we want the parent for.
Returns:
The type code of the parent type.

isApprop

public boolean isApprop(int type,
                        int feat)
Check if feature is appropriate for type (i.e., type is subsumed by domain type of feature).


getLargestTypeCode

public final int getLargestTypeCode()

isType

public boolean isType(int type)

getType

public Type getType(java.lang.String typeName)
Get a type object for a given name.

Specified by:
getType in interface TypeSystem
Parameters:
typeName - The name of the type.
Returns:
A type object, or null if no such type exists.

getFeatureByFullName

public Feature getFeatureByFullName(java.lang.String featureName)
Get an feature object for a given name.

Specified by:
getFeatureByFullName in interface TypeSystem
Parameters:
featureName - The name of the feature.
Returns:
An feature object, or null if no such feature exists.

addType

public Type addType(java.lang.String typeName,
                    Type mother)
             throws CASAdminException
Add a new type to the type system.

Specified by:
addType in interface TypeSystemMgr
Parameters:
typeName - The name of the new type.
mother - The type node under which the new type should be attached.
Returns:
The new type, or null if typeName is already in use.
Throws:
CASAdminException - If typeName is not a legal type name, type system is locked, or mother is inheritance final.

addFeature

public Feature addFeature(java.lang.String featureName,
                          Type domainType,
                          Type rangeType)
                   throws CASAdminException
Description copied from interface: TypeSystemMgr
Add an feature to the type system.

Specified by:
addFeature in interface TypeSystemMgr
Parameters:
featureName - The name of the new feature.
domainType - The type that defines the domain of the feature.
rangeType - The type that defines the range of the feature.
Returns:
The new feature object, or null if featureName is already in use for domainType with the same range (if the range is different, an exception is thrown).
Throws:
CASAdminException - If featureName is not a legal feature name, the type system is locked or domainType is feature final. Also if featureName has already been defined on domainType (or a supertype) with a different range than rangeType.

addFeature

public Feature addFeature(java.lang.String featureName,
                          Type domainType,
                          Type rangeType,
                          boolean multipleReferencesAllowed)
                   throws CASAdminException
Description copied from interface: TypeSystemMgr
Add an feature to the type system.

Specified by:
addFeature in interface TypeSystemMgr
Parameters:
featureName - The name of the new feature.
domainType - The type that defines the domain of the feature.
rangeType - The type that defines the range of the feature.
multipleReferencesAllowed - If the rangeType is an array type, you can use this flag to enforce that the feature value is not referenced anywhere else. This is currently only used for XMI serialization. Defaults to true.
Returns:
The new feature object, or null if featureName is already in use for domainType with the same range (if the range is different, an exception is thrown).
Throws:
CASAdminException - If featureName is not a legal feature name, the type system is locked or domainType is feature final. Also if featureName has already been defined on domainType (or a supertype) with a different range than rangeType.
See Also:
TypeSystemMgr.addFeature(String, Type, Type)

getTypeIterator

public java.util.Iterator<Type> getTypeIterator()
Get an iterator over all types, in no particular order.

Specified by:
getTypeIterator in interface TypeSystem
Returns:
The iterator.

getFeatures

public java.util.Iterator<Feature> getFeatures()
Description copied from interface: TypeSystem
Get a list of features, in no particular order.

Specified by:
getFeatures in interface TypeSystem
Returns:
An iterator over the features.

getTopType

public Type getTopType()
Get the top type, i.e., the root of the type system.

Specified by:
getTopType in interface TypeSystem
Returns:
The top type.

getProperlySubsumedTypes

public java.util.List<Type> getProperlySubsumedTypes(Type type)
Return the list of all types subsumed by the input type. Note: the list does not include the type itself.

Specified by:
getProperlySubsumedTypes in interface TypeSystem
Parameters:
type - Input type.
Returns:
The list of types subsumed by type.

getDirectlySubsumedTypes

public java.util.Vector<Type> getDirectlySubsumedTypes(Type type)
Get a vector of the types directly subsumed by a given type.

Specified by:
getDirectlySubsumedTypes in interface TypeSystem
Parameters:
type - The input type.
Returns:
A vector of the directly subsumed types.

getDirectSubtypes

public java.util.List<Type> getDirectSubtypes(Type type)
Description copied from interface: TypeSystem
Get a List of the types directly subsumed by a given type.

Specified by:
getDirectSubtypes in interface TypeSystem
Parameters:
type - The input type.
Returns:
A List of the directly subsumed types.

directlySubsumes

public boolean directlySubsumes(int t1,
                                int t2)

subsumes

public boolean subsumes(Type superType,
                        Type subType)
Does one type inherit from the other?

Specified by:
subsumes in interface TypeSystem
Parameters:
superType - Supertype.
subType - Subtype.
Returns:
true iff sub inherits from super.

ll_getAppropriateFeatures

public int[] ll_getAppropriateFeatures(int type)
Get an array of the appropriate features for this type.

Specified by:
ll_getAppropriateFeatures in interface LowLevelTypeSystem
Parameters:
type - Input type code.
Returns:
The array of appropriate features for typeCode.

getNumberOfFeatures

public int getNumberOfFeatures()
Get the overall number of features defined in the type system.


getNumberOfTypes

public int getNumberOfTypes()
Get the overall number of types defined in the type system.


intro

public int intro(int feat)
Get the domain type for a feature.


range

public int range(int feat)
Get the range type for a feature.


unify

public int unify(int t1,
                 int t2)

addTopType

public Type addTopType(java.lang.String name)
Add a top type to the (empty) type system.


subsumes

public boolean subsumes(int superType,
                        int type)
Check if the first argument subsumes the second


ll_subsumes

public boolean ll_subsumes(int superType,
                           int type)
Description copied from interface: LowLevelTypeSystem
Check subsumption between two types.

Specified by:
ll_subsumes in interface LowLevelTypeSystem
Returns:
true iff type1 subsumes type2.

toString

public java.lang.String toString()
This writes out the type hierarchy in a human-readable form.

Overrides:
toString in class java.lang.Object

commit

public void commit()
Description copied from interface: TypeSystemMgr
Commit the type system. The type system will be locked and no longer writable. WARNING: Users should not call this, but instead call ((CASImpl) theAssociatedCAS).commitTypeSystem() in order to set up the parts of the CAS that should be set up when the type system is committed.

Specified by:
commit in interface TypeSystemMgr
See Also:
TypeSystemMgr.commit()

isCommitted

public boolean isCommitted()
Description copied from interface: TypeSystemMgr
Check if this instance has been committed.

Specified by:
isCommitted in interface TypeSystemMgr
Returns:
true iff this instance has been committed.
See Also:
TypeSystemMgr.isCommitted()

getFeature

@Deprecated
public Feature getFeature(java.lang.String featureName)
Deprecated. 


setFeatureFinal

public void setFeatureFinal(Type type)
Description copied from interface: TypeSystemMgr
Make type feature final in the sense that no new features can be added to this type. Note that making a type feature final automatically makes all ancestors of that type feature final as well.

Specified by:
setFeatureFinal in interface TypeSystemMgr
Parameters:
type - The type to be made feature final.
See Also:
TypeSystemMgr.setFeatureFinal(org.apache.uima.cas.Type)

setInheritanceFinal

public void setInheritanceFinal(Type type)
Description copied from interface: TypeSystemMgr
Block any further inheritance from this type. Does not mean that the type can have no sub-types, just that no new ones can be introduced.

Specified by:
setInheritanceFinal in interface TypeSystemMgr
See Also:
TypeSystemMgr.setInheritanceFinal(org.apache.uima.cas.Type)

addStringSubtype

public Type addStringSubtype(java.lang.String typeName,
                             java.lang.String[] stringList)
                      throws CASAdminException
Description copied from interface: TypeSystemMgr
Inherit from String. The only way you can inherit from String is by providing a restriction to a set of strings that are possible values for features of this type. This restriction will be checked when such feature values are set. Note that you can not introduce any features on such types, nor can you subtype them any further.

Specified by:
addStringSubtype in interface TypeSystemMgr
Parameters:
typeName - The name of the type to be created.
stringList - The list of legal string values for this string type.
Returns:
The resulting type, or null if the type is already defined.
Throws:
CASAdminException - If the type system is locked.
See Also:
TypeSystemMgr.addStringSubtype(java.lang.String, java.lang.String[])

getStringSet

public java.lang.String[] getStringSet(int i)

getTypeNameSpace

public TypeNameSpace getTypeNameSpace(java.lang.String name)
Description copied from interface: TypeSystem
Create a type name space object for the name parameter.

Specified by:
getTypeNameSpace in interface TypeSystem
Parameters:
name - The name of the name space.
Returns:
A TypeNameSpace object corresponding to name, or null, if name is not a legal type name space identifier.

ll_getCodeForTypeName

public int ll_getCodeForTypeName(java.lang.String typeName)
Description copied from interface: LowLevelTypeSystem
Get the type code for a given type name.

Specified by:
ll_getCodeForTypeName in interface LowLevelTypeSystem
Parameters:
typeName - The name of the type.
Returns:
The code for the type. A return value of 0 means that the a type of that name does not exist in the type system.

ll_getCodeForType

public int ll_getCodeForType(Type type)
Description copied from interface: LowLevelTypeSystem
Get the code of an existing type object.

Specified by:
ll_getCodeForType in interface LowLevelTypeSystem
Parameters:
type - A type object.
Returns:
The type code for the input type.

ll_getCodeForFeatureName

public int ll_getCodeForFeatureName(java.lang.String featureName)
Description copied from interface: LowLevelTypeSystem
Get the feature code for a given feature name.

Specified by:
ll_getCodeForFeatureName in interface LowLevelTypeSystem
Parameters:
featureName - The name of the feature.
Returns:
The code for the feature. A return value of 0 means that the name does not represent a feature in the type system.

ll_getCodeForFeature

public int ll_getCodeForFeature(Feature feature)
Description copied from interface: LowLevelTypeSystem
Get the code for a given feature object.

Specified by:
ll_getCodeForFeature in interface LowLevelTypeSystem
Parameters:
feature - A feature object.
Returns:
The code for the feature.

ll_getTypeForCode

public Type ll_getTypeForCode(int typeCode)
Description copied from interface: LowLevelTypeSystem
Get a type object for a given code.

Specified by:
ll_getTypeForCode in interface LowLevelTypeSystem
Parameters:
typeCode - The code of the type.
Returns:
A type object, or null if typeCode is not a valid type code.

ll_getFeatureForCode

public Feature ll_getFeatureForCode(int featureCode)
Description copied from interface: LowLevelTypeSystem
Get a feature object for a given code.

Specified by:
ll_getFeatureForCode in interface LowLevelTypeSystem
Parameters:
featureCode - The code of the feature.
Returns:
A feature object, or null if featureCode is not a valid feature code.

ll_getDomainType

public int ll_getDomainType(int featureCode)
Description copied from interface: LowLevelTypeSystem
Get the domain type for a given feature.

Specified by:
ll_getDomainType in interface LowLevelTypeSystem
Parameters:
featureCode - Input feature code.
Returns:
The domain type code for featureCode.

ll_getRangeType

public int ll_getRangeType(int featureCode)
Description copied from interface: LowLevelTypeSystem
Get the range type for a given feature.

Specified by:
ll_getRangeType in interface LowLevelTypeSystem
Parameters:
featureCode - Input feature code.
Returns:
The range type code for featureCode.

getLowLevelTypeSystem

public LowLevelTypeSystem getLowLevelTypeSystem()
Description copied from interface: TypeSystem
Return the low-level view of this type system.

Specified by:
getLowLevelTypeSystem in interface TypeSystem
Returns:
The LowLevelTypeSystem version of this type system.

ll_isStringSubtype

public boolean ll_isStringSubtype(int type)
Description copied from interface: LowLevelTypeSystem
Check if type is a string subtype.

Specified by:
ll_isStringSubtype in interface LowLevelTypeSystem
Parameters:
type - The type to be checked.
Returns:
true iff type is a subtype of String.

ll_isRefType

public boolean ll_isRefType(int typeCode)
Description copied from interface: LowLevelTypeSystem
Checks if the type code is that of a reference type (anything that's not a basic type, currently Integer, String, Float, Boolean, Byte, Short, Long, Double, and subtypes of String - specifying allowed-values).

Specified by:
ll_isRefType in interface LowLevelTypeSystem
Parameters:
typeCode - The type code to check.
Returns:
true iff typeCode is the type code of a reference type.

getArrayType

public Type getArrayType(Type componentType)
Description copied from interface: TypeSystem
Obtain an array type with component type componentType.

Specified by:
getArrayType in interface TypeSystem
Parameters:
componentType - The type of the elements of the resulting array type. This can be any type, even another array type.
Returns:
The array type with the corresponding component type.

ll_getTypeClass

public final int ll_getTypeClass(int typeCode)
Description copied from interface: LowLevelTypeSystem
Determine the type class of a type. This is useful for generic CAS exploiters to determine what kind of data they're looking at. The type classes currently defined are: This method is on the CAS, not the type system, since the specific properties of types are specific to the CAS. The type system does not know, for example, that the CAS treats arrays specially.

Specified by:
ll_getTypeClass in interface LowLevelTypeSystem
Parameters:
typeCode - The type code.
Returns:
A type class for the type code. TYPE_CLASS_INVALID if the type code argument does not represent a valid type code.

ll_getArrayType

public int ll_getArrayType(int componentTypeCode)
Description copied from interface: LowLevelTypeSystem
Get the type code for the array type with componentTypeCode as component type code.

Specified by:
ll_getArrayType in interface LowLevelTypeSystem
Parameters:
componentTypeCode - The type code of the component type.
Returns:
The type code for the requested array type, or UNKNOWN_TYPE_CODE if componentTypeCode is not a valid type code.

ll_isValidTypeCode

public boolean ll_isValidTypeCode(int typeCode)
Description copied from interface: LowLevelTypeSystem
Check the input type code.

Specified by:
ll_isValidTypeCode in interface LowLevelTypeSystem
Parameters:
typeCode - Type code to check.
Returns:
true iff typeCode is a valid type code.

ll_isArrayType

public boolean ll_isArrayType(int typeCode)
Description copied from interface: LowLevelTypeSystem
Check if typeCode is the type code of an array type.

Specified by:
ll_isArrayType in interface LowLevelTypeSystem
Parameters:
typeCode - The type code to check.
Returns:
true iff typeCode is an array type code.

ll_getComponentType

public int ll_getComponentType(int arrayTypeCode)
Description copied from interface: LowLevelTypeSystem
Get the component type of an array type code.

Specified by:
ll_getComponentType in interface LowLevelTypeSystem
Parameters:
arrayTypeCode - The input array type code.
Returns:
The type code for the component type, or UNKNOWN_TYPE_CODE if arrayTypeCode is not valid or not an array type.

ll_isPrimitiveType

public boolean ll_isPrimitiveType(int typeCode)
Description copied from interface: LowLevelTypeSystem
Check if typeCode is the type code of a primitive type.

Specified by:
ll_isPrimitiveType in interface LowLevelTypeSystem
Parameters:
typeCode - The type code to check.
Returns:
true iff typeCode is a primitive type code.

ll_getStringSet

public java.lang.String[] ll_getStringSet(int typeCode)
Description copied from interface: LowLevelTypeSystem
Get the string set (sorted) for a string subtype.

Specified by:
ll_getStringSet in interface LowLevelTypeSystem
Parameters:
typeCode - Input type code; should be a string subtype.
Returns:
The set of allowable string values for subtypes of uima.cas.String. If the input type code is not a proper subtype of String, returns null.


Copyright © 2010 The Apache Software Foundation. All Rights Reserved.