Package org.apache.uima.cas.impl
Class CasTypeSystemMapper
- java.lang.Object
-
- org.apache.uima.cas.impl.CasTypeSystemMapper
-
public class CasTypeSystemMapper extends java.lang.Object
This class gets initialized with two type systems, and then provides resources to map type and feature codes between them. It is used by some Binary serialization/ deserialization code to allow non-exact matched type systems to send and receive CASes in a binary-like format. Use cases: Serializing: Source ts -%gt; generate serialized form in Target ts Deserializing: Target ts -%gt; generate deserialized form in Source ts - either from remote or - from disk-stored-form Mapping details: Types are mapped by name. Same-named types do not need to have the same number of features. Same-named features must have same Range - otherwise, not mapped. Types with 0 features mapped allowed. LifeCycle: Instance of this are created for a CAS when needed, and then kept in the (source) TypeSystemImpl, in a map indexed by the target type system (identity map)
-
-
Field Summary
Fields Modifier and Type Field Description private FeatureImpl[][]
fSrc2Tgt
Feature mapping from source to target first key is the src type code, 2nd is the src feature offset (origin 0)private FeatureImpl[][]
fTgt2Src
Feature mapping from target to source first key is the tgt type code, 2nd is the tgt feature offset Only used for type codes that are not arrays.private java.util.List<TypeImpl>
tSrc2Tgt
Map from source types to target types.TypeSystemImpl
tsSrc
java.lang.ref.WeakReference<TypeSystemImpl>
tsTgt
private java.util.List<TypeImpl>
tTgt2Src
Map from target types to source types.private boolean
typeSystemsSame
-
Constructor Summary
Constructors Constructor Description CasTypeSystemMapper(TypeSystemImpl tsSrc, TypeSystemImpl tsTgt)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
addFeatures(FeatureImpl[][] map, TypeSystemImpl tsFrom, TypeSystemImpl tsTo)
Create the map from tsFrom to tsTo for all the features, by type -- map created using type and feature name equality -- note: the features may have different definitions; map is by name only --- e.g., one may have String range, the other float range.private boolean
addTypes(java.util.List<TypeImpl> map, TypeSystemImpl tsSrc, TypeSystemImpl tsTgt)
return true if no types are filteredFeatureImpl
getSrcFeature(TypeImpl tgtType, FeatureImpl tgtFeat)
FeatureImpl[]
getSrcFeatures(TypeImpl tgtType)
Given a tgt type, return an array of source features in the order they would appear in the target.FeatureImpl
getTgtFeature(TypeImpl srcType, FeatureImpl srcFeat)
Get target feature, given src type and featureFeatureImpl
getToFeature(FeatureImpl[][] mapByTypeCode, TypeImpl fromType, FeatureImpl fromFeat)
boolean
isEqual()
TypeImpl
mapTypeCode2Other(TypeImpl type, boolean src2tgt)
TypeImpl
mapTypeCodeTgt2Src(int tgtTypeCode)
TypeImpl
mapTypeSrc2Tgt(TypeImpl srcType)
TypeImpl
mapTypeTgt2Src(TypeImpl tgtType)
-
-
-
Field Detail
-
tsSrc
public final TypeSystemImpl tsSrc
-
tsTgt
public final java.lang.ref.WeakReference<TypeSystemImpl> tsTgt
-
tSrc2Tgt
private final java.util.List<TypeImpl> tSrc2Tgt
Map from source types to target types. Source type code used as index, value is target type or null if the type doesn't exist in the target
-
tTgt2Src
private final java.util.List<TypeImpl> tTgt2Src
Map from target types to source types. Source type code used as index, value is target type or null if the type doesn't exist in the target
-
fSrc2Tgt
private final FeatureImpl[][] fSrc2Tgt
Feature mapping from source to target first key is the src type code, 2nd is the src feature offset (origin 0)
-
fTgt2Src
private final FeatureImpl[][] fTgt2Src
Feature mapping from target to source first key is the tgt type code, 2nd is the tgt feature offset Only used for type codes that are not arrays. Use: When serializing a source type that exists in the target, have to output the slots in the target feature order Also, when comparing the slots in the target with a given source
-
typeSystemsSame
private final boolean typeSystemsSame
-
-
Constructor Detail
-
CasTypeSystemMapper
public CasTypeSystemMapper(TypeSystemImpl tsSrc, TypeSystemImpl tsTgt)
-
-
Method Detail
-
isEqual
public boolean isEqual()
-
mapTypeSrc2Tgt
public TypeImpl mapTypeSrc2Tgt(TypeImpl srcType)
- Parameters:
srcType
- -- Returns:
- Type in other type system, or this one if map is empty
-
mapTypeTgt2Src
public TypeImpl mapTypeTgt2Src(TypeImpl tgtType)
- Parameters:
tgtType
- -- Returns:
- 0 if type doesn't have corresponding code in other type system
-
mapTypeCodeTgt2Src
public TypeImpl mapTypeCodeTgt2Src(int tgtTypeCode)
-
mapTypeCode2Other
public TypeImpl mapTypeCode2Other(TypeImpl type, boolean src2tgt)
- Parameters:
type
- -src2tgt
- -- Returns:
- 0 if type doesn't have corresponding code in other type system
-
getTgtFeature
public FeatureImpl getTgtFeature(TypeImpl srcType, FeatureImpl srcFeat)
Get target feature, given src type and feature- Parameters:
srcType
- the source typesrcFeat
- the source feature- Returns:
- the target feature or null
-
getSrcFeature
public FeatureImpl getSrcFeature(TypeImpl tgtType, FeatureImpl tgtFeat)
-
getSrcFeatures
public FeatureImpl[] getSrcFeatures(TypeImpl tgtType)
Given a tgt type, return an array of source features in the order they would appear in the target.- Parameters:
tgtType
- -- Returns:
- array of corresponding source features, in target type order
-
getToFeature
public FeatureImpl getToFeature(FeatureImpl[][] mapByTypeCode, TypeImpl fromType, FeatureImpl fromFeat)
-
addTypes
private boolean addTypes(java.util.List<TypeImpl> map, TypeSystemImpl tsSrc, TypeSystemImpl tsTgt)
return true if no types are filtered- Parameters:
map
-tsSrc
-tsTgt
-- Returns:
-
addFeatures
private boolean addFeatures(FeatureImpl[][] map, TypeSystemImpl tsFrom, TypeSystemImpl tsTo)
Create the map from tsFrom to tsTo for all the features, by type -- map created using type and feature name equality -- note: the features may have different definitions; map is by name only --- e.g., one may have String range, the other float range. --- in this case, the return is set to false.- Parameters:
map
- the map to updatetsFrom
- the From type systemtsTo
- the to type system- Returns:
- true if all the tsFrom features are found in tsTo and following fields are the same: rangeType.name, featureOffset, isMultipleRefsAllowed
-
-