Package org.apache.uima.cas.impl
Class FeatureValuePathImpl
- java.lang.Object
-
- org.apache.uima.cas.impl.FeatureValuePathImpl
-
- All Implemented Interfaces:
FeatureValuePath
public class FeatureValuePathImpl extends java.lang.Object implements 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:coveredText()
can be accessed usingevaluateAsString
typeName()
can be accessed usingevaluateAsString
fsId()
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,getValueType
will 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
typeSystemInit
of your component (CAS consumer or TAE), calltypeSystemInit
of the feature path. - Call
getValueType
to 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
evaluateAs
methods
-
-
Field Summary
Fields Modifier and Type Field Description private int
arrayIndex
private static boolean
CAS_TYPE_CHECKS
private FeatureValuePathImpl
childPath
private static java.util.Map<java.lang.String,java.lang.String>
CONTAINER_TO_ELEMENTYPE_MAP
private static java.lang.String
COVERED_TEXT
private static java.lang.String[]
EMPTY_LIST_TYPE_NAMES
private Type[]
emptyListTypes
private int
featureCode
private java.lang.String
featureName
private int
featureRangeType
private static java.lang.String
FS_ID
private int
headFeature
private boolean
isArrayOrList
private boolean
isArrayType
private boolean
isBracketsOnly
private boolean
isCoveredTextFeature
private boolean
isFsIdFeature
private boolean
isListType
private boolean
isSimpleRangeType
private boolean
isTypeNameFeature
private boolean
isUniqueIdFeature
private static int
LAST_ARRAY_ENTRY
private static java.lang.String
LAST_ARRAY_ENTRY_MARKER
private static java.util.Map<java.lang.String,java.lang.String>
LIST_TO_ARRAYTYPE_MAP
private static java.lang.String[]
LIST_TYPE_NAMES
private int
listType
private static java.lang.String[]
SIMPLE_VAL_TYPES
private int
tailFeature
private static int
TYPE_CLASS_FLOATLIST
private static int
TYPE_CLASS_FSLIST
private static int
TYPE_CLASS_INTEGERLIST
private static int
TYPE_CLASS_STRINGLIST
private static java.lang.String
TYPE_NAME
private int
typeCode
private java.lang.String
typeNameInSnippet
private static java.lang.String
UNIQUE_ID
private static int
USE_ALL_ENTRIES
private java.lang.String
valueTypeName
-
Constructor Summary
Constructors Modifier Constructor Description private
FeatureValuePathImpl(java.lang.String pathSnippet, FeatureValuePathImpl child)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
determineArray()
Checks whether the feature snippet denotes array access (i.e., has [..] attached to it).java.lang.Object
evaluate(int currentFS, LowLevelCAS cas)
java.lang.Float
evaluateAsFloat(int currentFS, LowLevelCAS cas)
java.lang.Float[]
evaluateAsFloatArray(int currentFS, LowLevelCAS cas)
java.lang.Integer
evaluateAsInt(int currentFS, LowLevelCAS cas)
java.lang.Integer[]
evaluateAsIntArray(int currentFS, LowLevelCAS cas)
java.lang.String
evaluateAsString(int currentFS, LowLevelCAS cas)
Evaluates each snippet of the feature path.java.lang.String[]
evaluateAsStringArray(int currentFS, LowLevelCAS cas)
private int
getArrayIndex(int arraySize)
private java.lang.String
getFeatureInSnippet(java.lang.String pathSnippet)
static FeatureValuePathImpl
getFeaturePath(java.lang.String featurePath)
private int
getFsAtIndex(int currentFS, LowLevelCAS cas, int arraySize)
private int
getFsAtListIndex(LowLevelCAS cas, int listFS)
Assumes thatarrayIndex
!=USE_ALL_ENTRIES
, and that thelistType
isTYPE_CLASS_FSLIST
int
getFSType()
Returns the type for which the last feature in the feature path is defined.private java.lang.Object
getHeadValue(LowLevelCAS cas, int listFS)
private java.lang.String
getTypeInSnippet(java.lang.String pathSnippet)
private java.lang.Object
getValueAtIndexRec(LowLevelCAS cas, int listFS, java.util.ArrayList list, int count)
private java.lang.Object
getValueAtListIndex(LowLevelCAS cas, int listFS)
java.lang.String
getValueType()
Returns the type that this feature path will evaluate to.private boolean
isBracketsOnly()
private boolean
isBuiltInFeature()
private boolean
isEmptyList(LowLevelCAS cas, int type)
java.lang.String
toString()
void
typeSystemInit(int fsType, LowLevelTypeSystem ts)
-
-
-
Field Detail
-
CAS_TYPE_CHECKS
private static final boolean CAS_TYPE_CHECKS
- See Also:
- Constant Field Values
-
CONTAINER_TO_ELEMENTYPE_MAP
private static final java.util.Map<java.lang.String,java.lang.String> CONTAINER_TO_ELEMENTYPE_MAP
-
LIST_TO_ARRAYTYPE_MAP
private static final java.util.Map<java.lang.String,java.lang.String> LIST_TO_ARRAYTYPE_MAP
-
COVERED_TEXT
private static final java.lang.String COVERED_TEXT
- See Also:
- Constant Field Values
-
EMPTY_LIST_TYPE_NAMES
private static final java.lang.String[] EMPTY_LIST_TYPE_NAMES
-
FS_ID
private static final java.lang.String FS_ID
- See Also:
- Constant Field Values
-
LAST_ARRAY_ENTRY
private static final int LAST_ARRAY_ENTRY
- See Also:
- Constant Field Values
-
LAST_ARRAY_ENTRY_MARKER
private static final java.lang.String LAST_ARRAY_ENTRY_MARKER
- See Also:
- Constant Field Values
-
LIST_TYPE_NAMES
private static final java.lang.String[] LIST_TYPE_NAMES
-
SIMPLE_VAL_TYPES
private static final java.lang.String[] SIMPLE_VAL_TYPES
-
TYPE_CLASS_FLOATLIST
private static final int TYPE_CLASS_FLOATLIST
- See Also:
- Constant Field Values
-
TYPE_CLASS_FSLIST
private static final int TYPE_CLASS_FSLIST
- See Also:
- Constant Field Values
-
TYPE_CLASS_INTEGERLIST
private static final int TYPE_CLASS_INTEGERLIST
- See Also:
- Constant Field Values
-
TYPE_CLASS_STRINGLIST
private static final int TYPE_CLASS_STRINGLIST
- See Also:
- Constant Field Values
-
TYPE_NAME
private static final java.lang.String TYPE_NAME
- See Also:
- Constant Field Values
-
UNIQUE_ID
private static final java.lang.String UNIQUE_ID
- See Also:
- Constant Field Values
-
USE_ALL_ENTRIES
private static final int USE_ALL_ENTRIES
- See Also:
- Constant Field Values
-
arrayIndex
private int arrayIndex
-
childPath
private final FeatureValuePathImpl childPath
-
emptyListTypes
private Type[] emptyListTypes
-
featureCode
private int featureCode
-
featureName
private java.lang.String 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
private final java.lang.String typeNameInSnippet
-
valueTypeName
private java.lang.String valueTypeName
-
-
Constructor Detail
-
FeatureValuePathImpl
private FeatureValuePathImpl(java.lang.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 Detail
-
getFeaturePath
public static FeatureValuePathImpl getFeaturePath(java.lang.String featurePath) throws CASRuntimeException
- Throws:
CASRuntimeException
-
evaluate
public java.lang.Object evaluate(int currentFS, LowLevelCAS cas)
- Specified by:
evaluate
in interfaceFeatureValuePath
-
evaluateAsFloat
public java.lang.Float evaluateAsFloat(int currentFS, LowLevelCAS cas)
- Specified by:
evaluateAsFloat
in interfaceFeatureValuePath
-
evaluateAsFloatArray
public java.lang.Float[] evaluateAsFloatArray(int currentFS, LowLevelCAS cas)
- Specified by:
evaluateAsFloatArray
in interfaceFeatureValuePath
-
evaluateAsInt
public java.lang.Integer evaluateAsInt(int currentFS, LowLevelCAS cas)
- Specified by:
evaluateAsInt
in interfaceFeatureValuePath
-
evaluateAsIntArray
public java.lang.Integer[] evaluateAsIntArray(int currentFS, LowLevelCAS cas)
- Specified by:
evaluateAsIntArray
in interfaceFeatureValuePath
-
evaluateAsString
public java.lang.String evaluateAsString(int currentFS, LowLevelCAS cas)
Evaluates each snippet of the feature path. Returns a String representation of the leaf value of the path. Returnsnull
if some feature within the path is not set. If the leaf snippet isCOVERED_TEXT
, returns the covered text ofcurrentFS
.- Specified by:
evaluateAsString
in interfaceFeatureValuePath
- Parameters:
currentFS
- the current Feature Structurecas
- CAS- Returns:
- A string representation of the leaf value.
-
evaluateAsStringArray
public java.lang.String[] evaluateAsStringArray(int currentFS, LowLevelCAS cas)
- Specified by:
evaluateAsStringArray
in interfaceFeatureValuePath
-
getFSType
public int getFSType()
Returns the type for which the last feature in the feature path is defined. Assumes thattypeSystemInit
has 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:
getFSType
in interfaceFeatureValuePath
- Returns:
- the type for which the last feature in the feature path is defined.
- For a feature path
-
getValueType
public java.lang.String getValueType()
Returns the type that this feature path will evaluate to. Can be used to select the correct "evaluateAs" method.- Specified by:
getValueType
in 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
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
typeSystemInit
public void typeSystemInit(int fsType, LowLevelTypeSystem ts) throws CASRuntimeException
- Specified by:
typeSystemInit
in interfaceFeatureValuePath
- Throws:
CASRuntimeException
-
isBuiltInFeature
private boolean isBuiltInFeature()
-
determineArray
private final void determineArray() throws CASRuntimeException
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
private final java.lang.String getFeatureInSnippet(java.lang.String pathSnippet)
-
getFsAtIndex
private int getFsAtIndex(int currentFS, LowLevelCAS cas, int arraySize)
-
getFsAtListIndex
private int getFsAtListIndex(LowLevelCAS cas, int listFS)
Assumes thatarrayIndex
!=USE_ALL_ENTRIES
, and that thelistType
isTYPE_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
private java.lang.Object getHeadValue(LowLevelCAS cas, int listFS)
-
getTypeInSnippet
private final java.lang.String getTypeInSnippet(java.lang.String pathSnippet)
-
getValueAtIndexRec
private java.lang.Object getValueAtIndexRec(LowLevelCAS cas, int listFS, java.util.ArrayList list, int count)
-
getValueAtListIndex
private java.lang.Object getValueAtListIndex(LowLevelCAS cas, int listFS)
- Parameters:
cas
- CASlistFS
- the list Feature Structure- Returns:
- Object If arrayIndex = USE_ALL_ENTRIES, returns an
ArrayList
containing all entries. Otherwise, returns a String, Integer, or Float. Returnsnull
if the list does not contain an entry for arrayIndex, or is empty.
-
isBracketsOnly
private boolean isBracketsOnly()
-
isEmptyList
private boolean isEmptyList(LowLevelCAS cas, int type)
-
-