Package de.julielab.jcore.utility
Class JCoReFeaturePath
- java.lang.Object
-
- de.julielab.jcore.utility.JCoReFeaturePath
-
- All Implemented Interfaces:
org.apache.uima.cas.FeaturePath
public class JCoReFeaturePath extends java.lang.Object implements org.apache.uima.cas.FeaturePathThis class is an implementation of the UIMAFeaturePathinterface and adds some capabilities to it. Note that it also is currently missing some capabilities, most importantly it only does not implement a range of interface methods. However, it is able to query arbitrary feature values through itsgetValue(FeatureStructure, int)method, even if the methods to retrieve specific types of feature values (integers, floats, bytes etc) are currently not implemented. The JCoReFeaturePath uses the the same syntax as traditional UIMA feature paths but is also able to address specific indices in multi-valued features. Suppose you have a Gene annotation and want to create feature paths to access various information of the annotation. Then you could specify the following feature paths in the constructor of a new JCoReFeaturePath:/specificType: Returns the string value of the specificType feature/resourceEntryList: Returns the FSArray holding the ResourceEntry instances of the gene (a resource entry is a pointer into a database which is the 'resource')/resourceEntryList/entryId: Returns the entryId feature values of all ResourceEntry instances as an array/resourceEntryList[0]/entryId: Returns the entryId feature value of the first ResourceEntry instance/resourceEntryList[-1]/entryId: Returns the entryId feature value of the last ResourceEntry instance
coveredText(): Calls Annotation.getCoveredText on the annotation pointed to with the feature pathtypeName(): Calls Object.getClass().getName() on the annotation pointed to by the feature path.
/arguments[0]/:coveredText(): Returns the document text covered by the first Argument of the EventMention.
- /arguments[0]/:typeName(): Returns the name of type - or class - of the first argument
- /:coveredText(): Returns the covered text of the input annotation and thus is equivalent to
annotation.getCoveredText()Feature Value Replacement
-
-
Constructor Summary
Constructors Constructor Description JCoReFeaturePath()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFeature(org.apache.uima.cas.Feature feat)voidclearReplacementCache()Important only if using value replacements.protected java.lang.ObjectgetArrayElement(org.apache.uima.cas.CommonArrayFS sa, java.util.Map<?,?> replacements, java.lang.reflect.Method getter, java.lang.reflect.Method setter, int index)java.lang.BooleangetBooleanValue(org.apache.uima.cas.FeatureStructure fs)java.lang.BytegetByteValue(org.apache.uima.cas.FeatureStructure fs)java.lang.ObjectgetDefaultReplacementValue()java.lang.DoublegetDoubleValue(org.apache.uima.cas.FeatureStructure fs)org.apache.uima.cas.FeaturegetFeature(int i)java.lang.StringgetFeaturePath()protected java.lang.ObjectgetFeatureValueFromFeatureStructure(org.apache.uima.cas.FeatureStructure fs, org.apache.uima.cas.Feature feature, java.util.Map<?,?> replacements)Returns the value of the feature feature of the feature structure fs.java.lang.FloatgetFloatValue(org.apache.uima.cas.FeatureStructure fs)org.apache.uima.cas.FeatureStructuregetFSValue(org.apache.uima.cas.FeatureStructure fs)java.lang.IntegergetIntValue(org.apache.uima.cas.FeatureStructure fs)java.lang.LonggetLongValue(org.apache.uima.cas.FeatureStructure fs)protected java.lang.StringgetObjectValueAsString(java.lang.Object objectValue)Get a String representation for a single primitive value.booleangetReplaceUnmappedValues()Returns true if feature values not contained in the replacement map are to be replaced by a default value.java.lang.ShortgetShortValue(org.apache.uima.cas.FeatureStructure fs)java.lang.StringgetStringValue(org.apache.uima.cas.FeatureStructure fs)org.apache.uima.cas.TypeClassgetTypClass(org.apache.uima.cas.FeatureStructure fs)org.apache.uima.cas.TypegetType(org.apache.uima.cas.FeatureStructure fs)java.lang.ObjectgetValue(org.apache.uima.cas.FeatureStructure fs, int startFeatureIndex)Begins to traverse the feature path from position startFeatureIndex and returns whatever values lie at the end of the feature path.java.lang.StringgetValueAsString(org.apache.uima.cas.FeatureStructure fs)java.lang.StringgetValueAsString(org.apache.uima.cas.FeatureStructure fs, boolean doReplacements)If using replacements, please note the comment atclearReplacementCache().java.lang.String[]getValueAsStringArray(org.apache.uima.cas.FeatureStructure fs)Returns the feature path values without performing value replacements.java.lang.String[]getValueAsStringArray(org.apache.uima.cas.FeatureStructure fs, boolean doReplacements)java.util.List<java.lang.String>getValueAsStringList(org.apache.uima.cas.FeatureStructure fs)Returns the feature path values without performing value replacements.java.util.List<java.lang.String>getValueAsStringList(org.apache.uima.cas.FeatureStructure fs, boolean doReplacements)voidinitialize(java.lang.String featurePath)voidinitialize(java.lang.String featurePath, java.util.Map<?,?> replacements)java.lang.Stringll_getValueAsString(int fsRef, org.apache.uima.cas.impl.LowLevelCAS llCas)voidloadReplacementsFromFile(java.lang.String replacementsFile)Reads a replacement file with lines of the formoriginalValue=replacementValueand immediately populates the internal replacement table with those entries.static java.util.Map<java.lang.String,java.lang.String>readReplacementsFromFile(java.lang.String replacementsFile)Reads a replacement file with lines of the formoriginalValue=replacementValueand returns the respective map.static java.util.Map<java.lang.String,java.lang.String>readReplacementsFromInputStream(java.io.InputStream is)Reads a replacement file with lines of the formoriginalValue=replacementValueand returns the respective map.java.lang.ObjectreplaceValue(org.apache.uima.cas.FeatureStructure fs)When using this method, please note the comment atclearReplacementCache().voidsetDefaultReplacementValue(java.lang.Object defaultReplacementValue)Sets a default replacement value to be used when there is no replacement for a feature value andreplaceUnmappedValuesis set to true.voidsetReplaceUnmappedValues(boolean replaceWithNullValues)For the work with replacements, please note the comment ofclearReplacementCache().intsize()voidtypeInit(org.apache.uima.cas.Type featurePathType)
-
-
-
Method Detail
-
size
public int size()
- Specified by:
sizein interfaceorg.apache.uima.cas.FeaturePath
-
getFeature
public org.apache.uima.cas.Feature getFeature(int i)
- Specified by:
getFeaturein interfaceorg.apache.uima.cas.FeaturePath
-
addFeature
public void addFeature(org.apache.uima.cas.Feature feat)
- Specified by:
addFeaturein interfaceorg.apache.uima.cas.FeaturePath
-
initialize
public void initialize(java.lang.String featurePath) throws org.apache.uima.cas.CASException- Specified by:
initializein interfaceorg.apache.uima.cas.FeaturePath- Throws:
org.apache.uima.cas.CASException
-
initialize
public void initialize(java.lang.String featurePath, java.util.Map<?,?> replacements) throws org.apache.uima.cas.CASException- Throws:
org.apache.uima.cas.CASException
-
typeInit
public void typeInit(org.apache.uima.cas.Type featurePathType) throws org.apache.uima.cas.CASException- Specified by:
typeInitin interfaceorg.apache.uima.cas.FeaturePath- Throws:
org.apache.uima.cas.CASException
-
replaceValue
public java.lang.Object replaceValue(org.apache.uima.cas.FeatureStructure fs)
When using this method, please note the comment atclearReplacementCache().- Parameters:
fs-- Returns:
-
getValue
public java.lang.Object getValue(org.apache.uima.cas.FeatureStructure fs, int startFeatureIndex)Begins to traverse the feature path from position startFeatureIndex and returns whatever values lie at the end of the feature path. This includes FeatureStructures, primitive values or even array-typed values.- Parameters:
fs-startFeatureIndex-- Returns:
-
getArrayElement
protected java.lang.Object getArrayElement(org.apache.uima.cas.CommonArrayFS sa, java.util.Map<?,?> replacements, java.lang.reflect.Method getter, java.lang.reflect.Method setter, int index) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException- Throws:
java.lang.IllegalAccessExceptionjava.lang.reflect.InvocationTargetException
-
getFeatureValueFromFeatureStructure
protected java.lang.Object getFeatureValueFromFeatureStructure(org.apache.uima.cas.FeatureStructure fs, org.apache.uima.cas.Feature feature, java.util.Map<?,?> replacements)Returns the value of the feature feature of the feature structure fs.- Parameters:
fs-feature-replacements-- Returns:
-
getValueAsStringArray
public java.lang.String[] getValueAsStringArray(org.apache.uima.cas.FeatureStructure fs, boolean doReplacements)
-
getValueAsStringArray
public java.lang.String[] getValueAsStringArray(org.apache.uima.cas.FeatureStructure fs)
Returns the feature path values without performing value replacements.- Parameters:
fs-- Returns:
-
getValueAsStringList
public java.util.List<java.lang.String> getValueAsStringList(org.apache.uima.cas.FeatureStructure fs, boolean doReplacements)
-
getValueAsStringList
public java.util.List<java.lang.String> getValueAsStringList(org.apache.uima.cas.FeatureStructure fs)
Returns the feature path values without performing value replacements. The returned list is not held by this object and can be modified in the application without side effects.- Parameters:
fs-- Returns:
-
getObjectValueAsString
protected java.lang.String getObjectValueAsString(java.lang.Object objectValue)
Get a String representation for a single primitive value.- Parameters:
objectValue-- Returns:
-
getValueAsString
public java.lang.String getValueAsString(org.apache.uima.cas.FeatureStructure fs)
- Specified by:
getValueAsStringin interfaceorg.apache.uima.cas.FeaturePath
-
getValueAsString
public java.lang.String getValueAsString(org.apache.uima.cas.FeatureStructure fs, boolean doReplacements)If using replacements, please note the comment atclearReplacementCache().- Parameters:
fs-doReplacements-- Returns:
-
setReplaceUnmappedValues
public void setReplaceUnmappedValues(boolean replaceWithNullValues)
For the work with replacements, please note the comment ofclearReplacementCache().- Parameters:
replaceWithNullValues-
-
getReplaceUnmappedValues
public boolean getReplaceUnmappedValues()
Returns true if feature values not contained in the replacement map are to be replaced by a default value.- Returns:
-
ll_getValueAsString
public java.lang.String ll_getValueAsString(int fsRef, org.apache.uima.cas.impl.LowLevelCAS llCas)- Specified by:
ll_getValueAsStringin interfaceorg.apache.uima.cas.FeaturePath
-
getType
public org.apache.uima.cas.Type getType(org.apache.uima.cas.FeatureStructure fs)
- Specified by:
getTypein interfaceorg.apache.uima.cas.FeaturePath
-
getTypClass
public org.apache.uima.cas.TypeClass getTypClass(org.apache.uima.cas.FeatureStructure fs)
- Specified by:
getTypClassin interfaceorg.apache.uima.cas.FeaturePath
-
getFeaturePath
public java.lang.String getFeaturePath()
- Specified by:
getFeaturePathin interfaceorg.apache.uima.cas.FeaturePath
-
getStringValue
public java.lang.String getStringValue(org.apache.uima.cas.FeatureStructure fs)
- Specified by:
getStringValuein interfaceorg.apache.uima.cas.FeaturePath
-
getIntValue
public java.lang.Integer getIntValue(org.apache.uima.cas.FeatureStructure fs)
- Specified by:
getIntValuein interfaceorg.apache.uima.cas.FeaturePath
-
getBooleanValue
public java.lang.Boolean getBooleanValue(org.apache.uima.cas.FeatureStructure fs)
- Specified by:
getBooleanValuein interfaceorg.apache.uima.cas.FeaturePath
-
getByteValue
public java.lang.Byte getByteValue(org.apache.uima.cas.FeatureStructure fs)
- Specified by:
getByteValuein interfaceorg.apache.uima.cas.FeaturePath
-
getDoubleValue
public java.lang.Double getDoubleValue(org.apache.uima.cas.FeatureStructure fs)
- Specified by:
getDoubleValuein interfaceorg.apache.uima.cas.FeaturePath
-
getFloatValue
public java.lang.Float getFloatValue(org.apache.uima.cas.FeatureStructure fs)
- Specified by:
getFloatValuein interfaceorg.apache.uima.cas.FeaturePath
-
getLongValue
public java.lang.Long getLongValue(org.apache.uima.cas.FeatureStructure fs)
- Specified by:
getLongValuein interfaceorg.apache.uima.cas.FeaturePath
-
getShortValue
public java.lang.Short getShortValue(org.apache.uima.cas.FeatureStructure fs)
- Specified by:
getShortValuein interfaceorg.apache.uima.cas.FeaturePath
-
getFSValue
public org.apache.uima.cas.FeatureStructure getFSValue(org.apache.uima.cas.FeatureStructure fs)
- Specified by:
getFSValuein interfaceorg.apache.uima.cas.FeaturePath
-
loadReplacementsFromFile
public void loadReplacementsFromFile(java.lang.String replacementsFile) throws java.io.FileNotFoundException, java.io.IOExceptionReads a replacement file with lines of the formoriginalValue=replacementValueand immediately populates the internal replacement table with those entries.- Parameters:
replacementsFile-- Throws:
java.io.FileNotFoundExceptionjava.io.IOException
-
readReplacementsFromFile
public static java.util.Map<java.lang.String,java.lang.String> readReplacementsFromFile(java.lang.String replacementsFile) throws java.io.FileNotFoundException, java.io.IOExceptionReads a replacement file with lines of the formoriginalValue=replacementValueand returns the respective map.- Parameters:
replacementsFile-- Returns:
- Throws:
java.io.FileNotFoundExceptionjava.io.IOException
-
readReplacementsFromInputStream
public static java.util.Map<java.lang.String,java.lang.String> readReplacementsFromInputStream(java.io.InputStream is) throws java.io.FileNotFoundException, java.io.IOExceptionReads a replacement file with lines of the formoriginalValue=replacementValueand returns the respective map.- Parameters:
is-- Returns:
- Throws:
java.io.FileNotFoundExceptionjava.io.IOException
-
getDefaultReplacementValue
public java.lang.Object getDefaultReplacementValue()
-
setDefaultReplacementValue
public void setDefaultReplacementValue(java.lang.Object defaultReplacementValue)
Sets a default replacement value to be used when there is no replacement for a feature value andreplaceUnmappedValuesis set to true. Defaults to null.- Parameters:
defaultReplacementValue-
-
clearReplacementCache
public void clearReplacementCache()
Important only if using value replacements. Clears the cache of already replaced feature structures. This has to be reset after each CAS in order to avoid collisions between different annotations from different CASes, which may happen due to the fact that the hash codes may collide and that the internal annotation addresses within a case are only unique within a CAS. Thus, the next CAS could have an annotation that doesn't get its value replaced because this annotation allegedly was already replaced due to an identity collision.
-
-