Class UimaContext_ImplBase

    • Field Detail

      • mQualifiedContextName

        protected final String mQualifiedContextName
        Fully-qualified name of this context.
      • mSofaMappings

        protected final Map<String,​String> mSofaMappings
        Mapping between sofa names assigned by an aggregate engine to sofa names assigned by the component engines. The key is the component sofa name and the value is the absolute sofa name assigned by a top level aggregate in this process. Multi-threading: This map is constructed at Constructor time, and never updated, only referenced, subsequently.
      • mCasPoolSize

        protected volatile int mCasPoolSize
        Size of the CAS pool used to support the getEmptyCas(Class) method. Note: CASes obtained by a CAS Multiplier, which then leave (exit) the CAS Multiplier, are not counted toward this limit. Rather, this limit limits the number of CASes that can be obtained while inside an annotator. The (maybe unobvious) use-case: Consider an annotator that receives hundreds of CASes, and sorts them into 3 kinds of aggregations, each of which accumulates information in a separate CAS for a while, and then releases these CASes for further processing. The limit would need to be set to 3 for this annotator instance, for this to work. The value of this max is set by calling the annotator's method getCasInstancesRequired method, a user-supplied method that is used to configure this. The default is 1.
      • mOutstandingCASes

        protected final Set<CAS> mOutstandingCASes
        CASes that have been requested via getEmptyCas(Class) minus the number calls the framework has made to returnedCAS(AbstractCas) (which indicate that the AnalysisComponent has returned a CAS from its next() method or released the CAS. If this Set size is at the maximum for this annotator, and the Analysis Component requests any additional CASes, then the AnalysisComponent has requested more CASes than it is allowed to and we throw an exception. This was changed from a simple int count to a set, in https://issues.apache.org/jira/browse/UIMA-437 revision 546169 (see history). CAS Multiplier use counts the CAS as returned after it is produced by the next() method when that method returns. Note that the CAS is not at that point "released" back into the CasPool - it is typically following a flow path and will eventually be released at some later point. The reason it is counted as released in this context's count is that this count limit is for limiting the number of CASes that can be requested within one process(), next(), or hasNext() methods, simultaneously, before that CAS is set onwards. Normally this is just 1 (at a time). The set is managed as a ConcurrentMap, to allow "remove" operations to not interlock with add or size operations. The size check followed by an add is in one sync block within getEmptyCas(), locked on the set object itself (not shared with any other locks).
    • Constructor Detail

      • UimaContext_ImplBase

        public UimaContext_ImplBase()
        Default constructor. Only Called for creating a "Root" instance.
      • UimaContext_ImplBase

        public UimaContext_ImplBase​(String contextName,
                                    Map<String,​String> sofaMappings)
        Constructor for non Root instances
        Parameters:
        contextName - -
        sofaMappings - -
    • Method Detail

      • createChild

        public UimaContextAdmin createChild​(String aContextName,
                                            Map<String,​String> aSofaMappings)
        Description copied from interface: UimaContextAdmin
        Creates a UimaContext that is a child of this UimaContext.
        Specified by:
        createChild in interface UimaContextAdmin
        Parameters:
        aContextName - a name for the new context, which must be unique with respect to all children of the parent context.
        aSofaMappings - mappings from child's sofa name to parent's sofa name. May be null.
        Returns:
        the Administrative interface to the UIMA Context
      • combineSofaMappings

        public Map<String,​String> combineSofaMappings​(Map<String,​String> aSofaMappings)
        Create the child sofa map by combining existing mapping from the current context with any mappings specific for this child, passed in as aSofaMappings
        Parameters:
        aSofaMappings - -
        Returns:
        the combined absolute sofamappings
      • getConfigParameterValue

        public Object getConfigParameterValue​(String aName)
        Description copied from interface: UimaContext
        Retrieves the value for a configuration parameter that is not defined in any group or is defined in the default group.

        This method returns null if the parameter is optional and has not been assigned a value. (For mandatory parameters, an exception is thrown during initialization if no value has been assigned.) This method also returns null if there is no declared configuration parameter with the specified name.

        Specified by:
        getConfigParameterValue in interface UimaContext
        Parameters:
        aName - the name of the parameter to look up
        Returns:
        the value of the parameter with the given name. The caller is expected to know the data type of the parameter. Returns null if the parameter does not exist or has not been assigned a value.
        See Also:
        AnnotatorContext.getConfigParameterValue(java.lang.String)
      • getConfigParameterValue

        public Object getConfigParameterValue​(String aGroupName,
                                              String aParamName)
        Description copied from interface: UimaContext
        Retrieves the value for a configuration parameter in a particular group. If that group contains no value for the specified parameter, the fallback strategy specified by the Analysis Engine's ConfigurationParameterDeclarations.getSearchStrategy() property will be used. The search strategy can be specified in the descriptor.

        This method returns null if the parameter is optional and has not been assigned a value. (For mandatory parameters, an exception is thrown during initialization if no value has been assigned.) This method also returns null if there is no declared configuration parameter with the specified name.

        Specified by:
        getConfigParameterValue in interface UimaContext
        Parameters:
        aGroupName - the name of the group containing the parameter
        aParamName - the name of the parameter to look up
        Returns:
        the value of the parameter with the given name. The caller is expected to know the data type of the parameter. Returns null if the parameter does not exist or has not been assigned a value.
        See Also:
        AnnotatorContext.getConfigParameterValue(java.lang.String, java.lang.String)
      • getSharedSettingArray

        public String[] getSharedSettingArray​(String name)
                                       throws ResourceConfigurationException
        Description copied from interface: UimaContext
        Get the array of values for a shared configuration parameter from the external override settings.
        Specified by:
        getSharedSettingArray in interface UimaContext
        Parameters:
        name - - the name of the parameter
        Returns:
        - an array of values found in the shared settings file(s), or null if missing.
        Throws:
        ResourceConfigurationException - if the value references an undefined parameter, or the value is not an array
      • getSharedSettingNames

        public String[] getSharedSettingNames()
        Description copied from interface: UimaContext
        Get the names of all the external override settings available.
        Specified by:
        getSharedSettingNames in interface UimaContext
        Returns:
        - an array containing the names of all the external override settings.
      • getResourceURI

        public URI getResourceURI​(String aKey)
                           throws ResourceAccessException
        Description copied from interface: UimaContext
        Retrieves the URI to the named resource. This can be used, for example, to locate configuration or authority files. The resource should be declared in the <externalResourceDependencies> section of the descriptor.

        This method is safer than UimaContext.getResourceURL(String) in its treatment of file paths containing spaces. This is because the URI.getPath() does perform URL decoding of that path (decoding %20 sequences to spaces) whereas URL.getPath() does not.

        For backwards compatibility, if the key is not declared as a resource dependency, it is looked up directly in the data path and the class path. However, this usage is deprecated and support may be dropped in future versions. ALL external resource dependencies should be declared in the descriptor.

        Specified by:
        getResourceURI in interface UimaContext
        Parameters:
        aKey - the key by which the resource is identified. This key should be declared in the <externalResourceDependencies> section of the descriptor.
        Returns:
        the URI at which the named resource is located, null if the named resource could not be found.
        Throws:
        ResourceAccessException - if a failure occurs in accessing the resource
      • getResourceFilePath

        public String getResourceFilePath​(String aKey)
                                   throws ResourceAccessException
        Description copied from interface: UimaContext
        Retrieves the absolute file path to the named resource. This can be used, for example, to locate configuration or authority files. The resource should be declared in the <externalResourceDependencies> section of the descriptor.

        This only works if the resource is a local file. If the resource is not a local file (for example, it could be an http URL, then an exception will be thrown.

        URL decoding will be done on the file path, so it is safe to use this method for file paths that contain spaces. For backwards compatibility, if the key is not declared as a resource dependency, it is looked up directly in the data path and the class path. However, this usage is deprecated and support may be dropped in future versions. ALL external resource dependencies should be declared in the descriptor.

        Specified by:
        getResourceFilePath in interface UimaContext
        Parameters:
        aKey - the key by which the resource is identified. This key should be declared in the <externalResourceDependencies> section of the descriptor.
        Returns:
        the absolute file path at which the named resource is located, null if the named resource could not be found.
        Throws:
        ResourceAccessException - if the resource is not a local file, or if a failure occurs in accessing the resource
      • getResourceAsStream

        public InputStream getResourceAsStream​(String aKey,
                                               String[] aParams)
                                        throws ResourceAccessException
        Description copied from interface: UimaContext
        Retrieves an InputStream for reading from the named resource. This can be used, for example, to locate configuration or authority files. The resource should be declared in the <externalResourceDependencies> section of the descriptor.

        For backwards compatibility, if the key is not declared as a resource dependency, it is looked up directly in the data path and the class path. However, this usage is deprecated and support may be dropped in future versions. ALL external resource dependencies should be declared in the descriptor.

        This version of this method takes an array of parameters used to further identify the resource. This can be used, for example, with resources that vary depending on the language of the document being analyzed, such as when the <fileLanguageResourceSpecifier> element is used in the component descriptor.

        Specified by:
        getResourceAsStream in interface UimaContext
        Parameters:
        aKey - the key by which the resource is identified. This key should bd declared in the <externalResourceDependencies> section of the descriptor.
        aParams - parameters used to further identify the resource. When used to identify the language for a <fileLanguageResourceSpecifier>, this array should contain a single element, the ISO language code for the language of the document (e.g. "en", "de").
        Returns:
        an InputStream for reading from the named resource, null if the named resource could not be found. It is the caller's responsibility to close this stream once it is no longer needed.
        Throws:
        ResourceAccessException - if a failure occurs in accessing the resource
        See Also:
        AnnotatorContext.getResourceAsStream(java.lang.String, java.lang.String[])
      • getResourceObject

        public Object getResourceObject​(String aKey,
                                        String[] aParams)
                                 throws ResourceAccessException
        Description copied from interface: UimaContext
        Retrieves the named resource object. This can be used to acquire references to external resources. The resource should be declared in the <externalResourceDependencies> section of the descriptor.

        This version of this method takes an array of parameters used to further identify the resource. This can be used, for example, with resources that vary depending on the language of the document being analyzed, such as when the <fileLanguageResourceSpecifier> element is used in the component descriptor.

        Specified by:
        getResourceObject in interface UimaContext
        Parameters:
        aKey - the key by which the resource is identified. This key should be declared in the <externalResourceDependencies> section of the descriptor.
        aParams - parameters used to further identify the resource. When used to identify the language for a <fileLanguageResourceSpecifier>, this array should contain a single element, the ISO language code for the language of the document (e.g. "en", "de").
        Returns:
        the object bound to aName, null if none.
        Throws:
        ResourceAccessException - if a failure occurs in accessing the resource
        See Also:
        AnnotatorContext.getResourceObject(java.lang.String, java.lang.String[])
      • getResourceURL

        public URL getResourceURL​(String aKey,
                                  String[] aParams)
                           throws ResourceAccessException
        Description copied from interface: UimaContext
        Retrieves the URL to the named resource. This can be used, for example, to locate configuration or authority files. The resource should be declared in the <externalResourceDependencies> section of the descriptor.

        Note that if the URL contains spaces they may be encoded as %20. The URL.getPath() method does NOT decode these sequences, therefore it is not safe to call getResourceURL().getPath() and attempt to use the result as a file path. Instead, you may use UimaContext.getResourceURI(String) or UimaContext.getResourceFilePath(String).

        For backwards compatibility, if the key is not declared as a resource dependency, it is looked up directly in the data path and the class path. However, this usage is deprecated and support may be dropped in future versions. ALL external resource dependencies should be declared in the descriptor.

        This version of this method takes an array of parameters used to further identify the resource. This can be used, for example, with resources that vary depending on the language of the document being analyzed, such as when the <fileLanguageResourceSpecifier> element is used in the component descriptor.

        Specified by:
        getResourceURL in interface UimaContext
        Parameters:
        aKey - the key by which the resource is identified. This key should be declared in the <externalResourceDependencies> section of the descriptor.
        aParams - parameters used to further identify the resource. When used to identify the language for a <fileLanguageResourceSpecifier>, this array should contain a single element, the ISO language code for the language of the document (e.g. "en", "de").
        Returns:
        the URL at which the named resource is located, null if the named resource could not be found.
        Throws:
        ResourceAccessException - if a failure occurs in accessing the resource
        See Also:
        AnnotatorContext.getResourceURL(java.lang.String, java.lang.String[])
      • getResourceURI

        public URI getResourceURI​(String aKey,
                                  String[] aParams)
                           throws ResourceAccessException
        Description copied from interface: UimaContext
        Retrieves the URI to the named resource. This can be used, for example, to locate configuration or authority files. The resource should be declared in the <externalResourceDependencies> section of the descriptor.

        This method is safer than UimaContext.getResourceURL(String) in its treatment of file paths containing spaces. This is because the URI.getPath() does perform URL decoding of that path (decoding %20 sequences to spaces) whereas URL.getPath() does not.

        For backwards compatibility, if the key is not declared as a resource dependency, it is looked up directly in the data path and the class path. However, this usage is deprecated and support may be dropped in future versions. ALL external resource dependencies should be declared in the descriptor.

        This version of this method takes an array of parameters used to further identify the resource. This can be used, for example, with resources that vary depending on the language of the document being analyzed, such as when the <fileLanguageResourceSpecifier> element is used in the component descriptor.

        Specified by:
        getResourceURI in interface UimaContext
        Parameters:
        aKey - the key by which the resource is identified. This key should be declared in the <externalResourceDependencies> section of the descriptor.
        aParams - parameters used to further identify the resource. When used to identify the language for a <fileLanguageResourceSpecifier>, this array should contain a single element, the ISO language code for the language of the document (e.g. "en", "de").
        Returns:
        the URI at which the named resource is located, null if the named resource could not be found.
        Throws:
        ResourceAccessException - if a failure occurs in accessing the resource
      • getResourceFilePath

        public String getResourceFilePath​(String aKey,
                                          String[] aParams)
                                   throws ResourceAccessException
        Description copied from interface: UimaContext
        Retrieves the absolute file path to the named resource. This can be used, for example, to locate configuration or authority files. The resource should be declared in the <externalResourceDependencies> section of the descriptor.

        This only works if the resource is a local file. If the resource is not a local file (for example, it could be an http URL, then an exception will be thrown.

        URL decoding will be done on the file path, so it is safe to use this method for file paths that contain spaces.

        For backwards compatibility, if the key is not declared as a resource dependency, it is looked up directly in the data path and the class path. However, this usage is deprecated and support may be dropped in future versions. ALL external resource dependencies should be declared in the descriptor.

        This version of this method takes an array of parameters used to further identify the resource. This can be used, for example, with resources that vary depending on the language of the document being analyzed, such as when the <fileLanguageResourceSpecifier> element is used in the component descriptor.

        Specified by:
        getResourceFilePath in interface UimaContext
        Parameters:
        aKey - the key by which the resource is identified. This key should be declared in the <externalResourceDependencies> section of the descriptor.
        aParams - parameters used to further identify the resource. When used to identify the language for a <fileLanguageResourceSpecifier>, this array should contain a single element, the ISO language code for the language of the document (e.g. "en", "de").
        Returns:
        the absolute file path at which the named resource is located, null if the named resource could not be found.
        Throws:
        ResourceAccessException - if the resource is not a local file, or if a failure occurs in accessing the resource
      • getDataPath

        public String getDataPath()
        Description copied from interface: UimaContext
        Gets the data path used to locate resources. This path may contain more than one directory, separated by the System path.separator character (; on windows, : on UNIX).

        This method is intended to be used only for integration of legacy or third-party components that have their own resource management facility. If possible, it is recommended that you use the getResoureXXX methods instead.

        Specified by:
        getDataPath in interface UimaContext
        Returns:
        the data path
        See Also:
        AnnotatorContext.getDataPath()
      • makeQualifiedName

        protected String makeQualifiedName​(String name)
      • getQualifiedContextName

        public String getQualifiedContextName()
        Description copied from interface: UimaContextAdmin
        Gets the fully-qualified name of this context. This is a slash-separated name consisting of each containing context name back to the root. It always begins and ends with a slash. For example, the context name for an annotator nested within two AnalysisEngines might look like: /MyTopLevelAnalysisEngine/MyComponentAnalysisEngine/MyAnnotator/.
        Specified by:
        getQualifiedContextName in interface UimaContextAdmin
        Returns:
        the qualified context name
      • getConfigurationGroupNames

        public String[] getConfigurationGroupNames()
        Description copied from interface: UimaContext
        Gets the names of all configuration parameter groups.
        Specified by:
        getConfigurationGroupNames in interface UimaContext
        Returns:
        an array containing the names of all configuration groups that exist for this component. Returns an empty array if no groups are declared.
      • getConfigParameterNames

        public String[] getConfigParameterNames()
        Description copied from interface: UimaContext
        Gets the names of all configuration parameters that are not declared in a group.
        Specified by:
        getConfigParameterNames in interface UimaContext
        Returns:
        an array containing the names of all configuration parameters not declared in any group. Returns an empty array if there are none.
      • getConfigParameterNames

        public String[] getConfigParameterNames​(String aGroup)
        Description copied from interface: UimaContext
        Gets the names of all configuration parameters in the specified group.
        Specified by:
        getConfigParameterNames in interface UimaContext
        Parameters:
        aGroup - the group name
        Returns:
        an array containing the names of all configuration parameters declared in aGroup. Note that this does include parameters with null values. Returns an empty array if there are none (including if the group does not exist).
      • getSofaMap

        public Map<String,​String> getSofaMap()
        Description copied from interface: UimaContextAdmin
        Gets an unmodifiable Map containing the mapping of component sofa name to absolute sofa ID.
        Specified by:
        getSofaMap in interface UimaContextAdmin
        Returns:
        the Sofa map for this component
      • defineCasPool

        public void defineCasPool​(int aSize,
                                  Properties aPerformanceTuningSettings,
                                  boolean aSofaAware)
                           throws ResourceInitializationException
        Description copied from interface: UimaContextAdmin
        Defines the CAS pool that this UimaContext must support. This method must be called before UimaContext.getEmptyCas(Class) may be called.
        Specified by:
        defineCasPool in interface UimaContextAdmin
        Parameters:
        aSize - the minimum CAS pool size required
        aPerformanceTuningSettings - settings, including initial CAS heap size, for the AE
        aSofaAware - whether the component that will receive these CASes is sofa aware. This is needed to determine which view to get. Sofa-aware components get the base view; sofa-unaware components get the default text sofa view (or whatever is mapped to it).
        Throws:
        ResourceInitializationException - if a CAS could not be created.
      • returnedCAS

        public void returnedCAS​(AbstractCas aCAS)
        Description copied from interface: UimaContextAdmin
        Called internally by the framework whenever the AnalysisComponent returns a CAS from its next() method or calls cas.release(). Used to monitor the number of CASes that the AnalysisComponent is using at any one time.
        Specified by:
        returnedCAS in interface UimaContextAdmin
        Parameters:
        aCAS - the CAS that was returned or released
        See Also:
        UimaContextAdmin.returnedCAS(AbstractCas)
      • getEmptyCas

        public <T extends AbstractCas> T getEmptyCas​(Class<T> aCasInterface)
        Description copied from interface: UimaContext
        Get an empty CAS. This method can only be called from CAS Multipliers, and typically a CAS Multiplier would call this indirectly through its CasMultiplier_ImplBase.getEmptyCAS() or JCasMultiplier_ImplBase.getEmptyJCas() method.

        This method may maintain a pool of CASes and may block if none are currently available.

        Specified by:
        getEmptyCas in interface UimaContext
        Type Parameters:
        T - the type of the CAS interface (CAS or JCas)
        Parameters:
        aCasInterface - the specific CAS interface that the component wants to use (e.g. CAS or JCas). Must specify a subtype of AbstractCas.
        Returns:
        an empty CAS. This will be an implementation of aCasInterface.