Package org.apache.uima.cas.impl
Class FeatureValuePathImpl
java.lang.Object
org.apache.uima.cas.impl.FeatureValuePathImpl
- All Implemented Interfaces:
FeatureValuePath
Contains CAS Type and Feature objects to represent a feature path of the form
feature1/.../featureN. Each part that is enclosed within / is referred to as "path snippet"
below. Also contains the necessary evaluation logic to yield the value of the feature path. For
leaf snippets, the following "special features" are defined:
Usage
coveredText()can be accessed usingevaluateAsStringtypeName()can be accessed usingevaluateAsStringfsId()can be accessed usingevaluateAsInt. Its result can be used to retrieve an FS from the current LowLevel-CAS.uniqueId()can be accessed usingevaluateAsInt. Its result can be used to uniquely identify an FS for a document (even if the document is split over several CAS chunks)
- A feature path may contain 0 or more features of type
FSArray, but not as the last path snippet. The next path snippet must contain the fully qualified type name, example:family/members[0]/somepackage.Person:name - A feature path may also contain 0 or 1 feature of type
IntArray, StringArray, FloatArray, but only as the last path snippet.
[index]returns the array entry atindex[last]returns the last entry of the array[]returns an array of values.[]is only allowed 0 or 1 time in a feature path. If it is used,getValueTypewill return one of the following:CAS.TYPE_NAME_STRING_ARRAY ,CAS.TYPE_NAME_INTEGER_ARRAY,CAS.TYPE_NAME_FLOAT_ARRAY.
FSArray, an actual feature name can
be omitted, and only the array access operator can be used. Examples:
[]/somepackage.Person:coveredText()
[last]/somepackage.Person:fsId()
Usage
- To create the feature path, use
FeaturePath.getFeaturePath. Note that the client code needs to keep track of the "start type" of the feature path, that is, the type that contains the attribute used in the first snippet of the path. - At
typeSystemInitof your component (CAS consumer or TAE), calltypeSystemInitof the feature path. - Call
getValueTypeto find out whether the feature path evaluates to a String, and int, a float, or their array counterparts. - Depending on the leaf type, call the appropriate
evaluateAsmethods
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate static final booleanprivate final FeatureValuePathImplprivate static final Stringprivate static final String[]private Type[]private intprivate Stringprivate intprivate static final Stringprivate intprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate static final intprivate static final Stringprivate static final String[]private intprivate static final String[]private intprivate static final intprivate static final intprivate static final intprivate static final intprivate static final Stringprivate intprivate final Stringprivate static final Stringprivate static final intprivate String -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateFeatureValuePathImpl(String pathSnippet, FeatureValuePathImpl child) -
Method Summary
Modifier and TypeMethodDescriptionprivate final voidChecks whether the feature snippet denotes array access (i.e., has [..] attached to it).evaluate(int currentFS, LowLevelCAS cas) evaluateAsFloat(int currentFS, LowLevelCAS cas) Float[]evaluateAsFloatArray(int currentFS, LowLevelCAS cas) evaluateAsInt(int currentFS, LowLevelCAS cas) Integer[]evaluateAsIntArray(int currentFS, LowLevelCAS cas) evaluateAsString(int currentFS, LowLevelCAS cas) Evaluates each snippet of the feature path.String[]evaluateAsStringArray(int currentFS, LowLevelCAS cas) private intgetArrayIndex(int arraySize) private final StringgetFeatureInSnippet(String pathSnippet) static FeatureValuePathImplgetFeaturePath(String featurePath) private intgetFsAtIndex(int currentFS, LowLevelCAS cas, int arraySize) private intgetFsAtListIndex(LowLevelCAS cas, int listFS) Assumes thatarrayIndex!=USE_ALL_ENTRIES, and that thelistTypeisTYPE_CLASS_FSLISTintReturns the type for which the last feature in the feature path is defined.private ObjectgetHeadValue(LowLevelCAS cas, int listFS) private final StringgetTypeInSnippet(String pathSnippet) private ObjectgetValueAtIndexRec(LowLevelCAS cas, int listFS, ArrayList list, int count) private ObjectgetValueAtListIndex(LowLevelCAS cas, int listFS) Returns the type that this feature path will evaluate to.private booleanprivate booleanprivate booleanisEmptyList(LowLevelCAS cas, int type) toString()voidtypeSystemInit(int fsType, LowLevelTypeSystem ts)
-
Field Details
-
CAS_TYPE_CHECKS
private static final boolean CAS_TYPE_CHECKS- See Also:
-
CONTAINER_TO_ELEMENTYPE_MAP
-
LIST_TO_ARRAYTYPE_MAP
-
COVERED_TEXT
- See Also:
-
EMPTY_LIST_TYPE_NAMES
-
FS_ID
- See Also:
-
LAST_ARRAY_ENTRY
private static final int LAST_ARRAY_ENTRY- See Also:
-
LAST_ARRAY_ENTRY_MARKER
- See Also:
-
LIST_TYPE_NAMES
-
SIMPLE_VAL_TYPES
-
TYPE_CLASS_FLOATLIST
private static final int TYPE_CLASS_FLOATLIST- See Also:
-
TYPE_CLASS_FSLIST
private static final int TYPE_CLASS_FSLIST- See Also:
-
TYPE_CLASS_INTEGERLIST
private static final int TYPE_CLASS_INTEGERLIST- See Also:
-
TYPE_CLASS_STRINGLIST
private static final int TYPE_CLASS_STRINGLIST- See Also:
-
TYPE_NAME
- See Also:
-
UNIQUE_ID
- See Also:
-
USE_ALL_ENTRIES
private static final int USE_ALL_ENTRIES- See Also:
-
arrayIndex
private int arrayIndex -
childPath
-
emptyListTypes
-
featureCode
private int featureCode -
featureName
-
featureRangeType
private int featureRangeType -
headFeature
private int headFeature -
isArrayOrList
private boolean isArrayOrList -
isArrayType
private boolean isArrayType -
isBracketsOnly
private boolean isBracketsOnly -
isCoveredTextFeature
private boolean isCoveredTextFeature -
isFsIdFeature
private boolean isFsIdFeature -
isListType
private boolean isListType -
isSimpleRangeType
private boolean isSimpleRangeType -
isTypeNameFeature
private boolean isTypeNameFeature -
isUniqueIdFeature
private boolean isUniqueIdFeature -
listType
private int listType -
tailFeature
private int tailFeature -
typeCode
private int typeCode -
typeNameInSnippet
-
valueTypeName
-
-
Constructor Details
-
FeatureValuePathImpl
private FeatureValuePathImpl(String pathSnippet, FeatureValuePathImpl child) throws CASRuntimeException - Parameters:
pathSnippet- feature path partchild- a feature value path object- Throws:
CASRuntimeException- if the feature path is invalid
-
-
Method Details
-
getFeaturePath
- Throws:
CASRuntimeException
-
evaluate
- Specified by:
evaluatein interfaceFeatureValuePath
-
evaluateAsFloat
- Specified by:
evaluateAsFloatin interfaceFeatureValuePath
-
evaluateAsFloatArray
- Specified by:
evaluateAsFloatArrayin interfaceFeatureValuePath
-
evaluateAsInt
- Specified by:
evaluateAsIntin interfaceFeatureValuePath
-
evaluateAsIntArray
- Specified by:
evaluateAsIntArrayin interfaceFeatureValuePath
-
evaluateAsString
Evaluates each snippet of the feature path. Returns a String representation of the leaf value of the path. Returnsnullif some feature within the path is not set. If the leaf snippet isCOVERED_TEXT, returns the covered text ofcurrentFS.- Specified by:
evaluateAsStringin interfaceFeatureValuePath- Parameters:
currentFS- the current Feature Structurecas- CAS- Returns:
- A string representation of the leaf value.
-
evaluateAsStringArray
- Specified by:
evaluateAsStringArrayin interfaceFeatureValuePath
-
getFSType
public int getFSType()Returns the type for which the last feature in the feature path is defined. Assumes thattypeSystemInithas been called prior to this method.- For a feature path
feature1/.../featureN-1/featureN, returns the type of featureN. - For a feature path
feature1/.../featureN-1/typeN:featureN, returns the type code for typeN. (For example, if the range type of featureN-1 is FSList or FSArray) - For a feature path
feature1, where feature1 is simple-valued, returns the type that was used intypeSystemInit
- Specified by:
getFSTypein interfaceFeatureValuePath- Returns:
- the type for which the last feature in the feature path is defined.
- For a feature path
-
getValueType
Returns the type that this feature path will evaluate to. Can be used to select the correct "evaluateAs" method.- Specified by:
getValueTypein interfaceFeatureValuePath- Returns:
- String the type that this feature path will evaluate to. Will be one of the following:
- CAS.TYPE_NAME_STRING
- CAS.TYPE_NAME_STRING_ARRAY
- CAS.TYPE_NAME_INTEGER
- CAS.TYPE_NAME_INTEGER_ARRAY
- CAS.TYPE_NAME_FLOAT
- CAS.TYPE_NAME_FLOAT_ARRAY
-
toString
-
typeSystemInit
- Specified by:
typeSystemInitin interfaceFeatureValuePath- Throws:
CASRuntimeException
-
isBuiltInFeature
private boolean isBuiltInFeature() -
determineArray
Checks whether the feature snippet denotes array access (i.e., has [..] attached to it). If so, determines the arrayIndex to use within evaluation, which can be a number, the special element "last" or simple [], which means "all elements"- Throws:
CASRuntimeException- If the closing ] is missing, or the number is not an integer
-
getArrayIndex
private int getArrayIndex(int arraySize) -
getFeatureInSnippet
-
getFsAtIndex
-
getFsAtListIndex
Assumes thatarrayIndex!=USE_ALL_ENTRIES, and that thelistTypeisTYPE_CLASS_FSLIST- Parameters:
cas- the low level CASthe- list feature structure- Returns:
- int A reference to the fs given in
arrayIndex, or 0 if the list does not contain an entry for that index.
-
getHeadValue
-
getTypeInSnippet
-
getValueAtIndexRec
-
getValueAtListIndex
- Parameters:
cas- CASlistFS- the list Feature Structure- Returns:
- Object If arrayIndex = USE_ALL_ENTRIES, returns an
ArrayListcontaining all entries. Otherwise, returns a String, Integer, or Float. Returnsnullif the list does not contain an entry for arrayIndex, or is empty.
-
isBracketsOnly
private boolean isBracketsOnly() -
isEmptyList
-