Class ResultSpecification_impl

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, ResultSpecification, MetaDataObject, XMLizable

    public final class ResultSpecification_impl
    extends MetaDataObject_impl
    implements ResultSpecification
    Reference implementation of ResultSpecification. Notes on the implementation Result Specifications (result specs, rs) are closely tied to capability specifications. They consist of instances of TypeOrFeatures and associated languages for which they are set. This impl supports removing previously added types and features for particular languages. There are two forms of the data kept: The data as it was provided to set the items in the result spec This form is used when removing previously added things The data after a type system has been provided, expanded to cover the various implied settings, due to either all Features flag on a type or the type/subtype hierarchy in the type system TypesOrFeatures are: typeXXX:FeatureYYY - specifying a particular feature of a type (Corner case: typeXXX:FeatureYYY doesn't imply there's a typeXXX allFeat nor a typeXXX w/o allFeat. typeXXX with allFeatures - a shorthand for specifying typeXXX and typeXXX:FeatureYYY for all features YYY defined for typeXXX (Corner case: excludes features ZZZ defined only in subtype of typeXXX) typeXXX without allFeatures (w/o allFeat) - specifies a type, but says nothing about the features This is specifiable in the XML. It means: The type is produced/needed but there's no information about the features that are to be produced or used containsType typeXXX returns true if typeXXX is in the RS, with or without the allFeats flag returns false if only features involving typeXXX are specified Intersection is done on fully expanded representations. There are two kinds of inheritance used Assuming there's a type system (which must be present when intersection is used), there's type/subtype This means that if a resultSpec is set for typeXXX, then the containsType(typeYYY) returns true if typeYYY is a subtype of typeXXX. This also needs to work for typeXXX:featZZZ; containsFeature(typeYYY:featZZZ) returns true if type YYY is a subtype of typeXXX. Languages have a 3 level hierarchy: x-unspecified - the same as no language being specified. If the resultSpec contains typeXXX for language x-unspecified, containsType(typeXXX, languageLLL) returns true, for any languageLLL a "base" language, without a '-', e.g. "en" a sub-language, with one or more '-', e.g., "en-us" The rules for matching languages only handle these three levels of inheritance. (Corner case: 3 or more level language hierarchy are treated as 3 level hierarchies eg. zh-Hant-HK (Traditional Chinese as used in Hong Kong) See http://www.w3.org/International/articles/language-tags/Overview.en.php ) Design considerations and assumptions Many instances of this class are made, sometimes via cloning. Most uses only use types, not type:features Most don't use languages A small subset of the possible types and type:features is specified explicitly Sometimes types and/or features are deleted. (language capability flow deletes types and/or features) Types and Features are kept on a per-language basis. Language can include a special value, x-unspecified, which "matches" any other language. Set operations among different result specs: Union: done in aggregates over result-specs derived from input capabilities of delegates Intersection: done for primitive components, over result-spec derived from output capability of the primitive remove: one type or feature (used by language capability flow) (Corner cases removing typeXXX doesn't remove typeXXX:featureYYY removing typeXXX allFeat doesn't remove typeXXX w/o allFeat (may have different languages) removing typeXXX w/o allFeat doesn't remove typeXXX allFeat The compiled version is used in containsType, containsFeature testing, and is used when computing intersection.
    See Also:
    Serialized Form
    • Field Detail

      • ARRAY_X_UNSPEC

        private static final java.lang.String[] ARRAY_X_UNSPEC
        main language separator e.g 'en' and 'en-US'
      • compiledXunspecified

        private static final RsLangs compiledXunspecified
        form used in hash table of compilied version to represent x-unspecified (can't use null - that means entry not in table)
      • EMPTY_TYPE_LIST

        public static final java.util.List<Type> EMPTY_TYPE_LIST
        used for empty type subsumption lists in subtype iterator
      • rsTypesMap

        private final RsTypesMap rsTypesMap
        For this Result-specification, the collection of language-sets Uncompiled format
      • mTypeSystem

        private TypeSystem mTypeSystem
        The type system used to compute the subtypes and allAnnotatorFeatures of types
      • needsCompilation

        private boolean needsCompilation
      • rsCompiled

        private final java.util.Map<java.lang.String,​RsLangs> rsCompiled
    • Constructor Detail

      • ResultSpecification_impl

        public ResultSpecification_impl()
      • ResultSpecification_impl

        public ResultSpecification_impl​(TypeSystem aTypeSystem)
        Constructor specifying the type system this should always be used in preference to the 0 argument version if the type system is available. Otherwise, the type system *must* be set via a method call prior to querying the result spec, with the one exception of the method getResultTypesAndFeaturesWithoutCompiling
        Parameters:
        aTypeSystem - -
      • ResultSpecification_impl

        private ResultSpecification_impl​(ResultSpecification_impl original)
        copies the result spec passed in so that updates to it don't affect the original
        Parameters:
        original -
    • Method Detail

      • getResultTypesAndFeatures

        public TypeOrFeature[] getResultTypesAndFeatures()
        Description copied from interface: ResultSpecification
        Retrieves the Types and Features that the AnalysisEngine or Annotator is requested to produce, for all languages.

        The set of types and features returned are just the ones that have been explicitly set or added to the ResultSpecification, and doesn't include any derived subtypes, even if this ResultSpecification has been compiled.

        Specified by:
        getResultTypesAndFeatures in interface ResultSpecification
        Returns:
        an array of TypeOrFeature objects that define the result types and features for all languages.
        See Also:
        ResultSpecification.getResultTypesAndFeatures()
      • getResultTypesAndFeatures

        private TypeOrFeature[] getResultTypesAndFeatures​(boolean skipLanguageFilter,
                                                          java.lang.String language)
      • reconstructRsTypesFromCompiled

        private void reconstructRsTypesFromCompiled()
      • addResultTof

        private void addResultTof​(TypeOrFeature tof,
                                  java.lang.String[] langs,
                                  boolean replace)
      • addResultType

        public void addResultType​(java.lang.String aTypeName,
                                  boolean aAllAnnotatorFeatures)
        Description copied from interface: ResultSpecification
        Adds an Type to this ResultSpecification for the language x-unspecified. If the current Type is already contained in the result spec, the language specification for this Type will be replaced with x-unspecified, and its allAnnotatorFeatures flag will be replaced with the parameter's.
        Specified by:
        addResultType in interface ResultSpecification
        Parameters:
        aTypeName - the name of the Type to add for the language x-unspecified
        aAllAnnotatorFeatures - whether all features of this type should also be produced
        See Also:
        ResultSpecification.addResultType(java.lang.String, boolean)
      • addResultType

        public void addResultType​(java.lang.String aTypeName,
                                  boolean aAllAnnotatorFeatures,
                                  java.lang.String[] aLanguageIDs)
        Description copied from interface: ResultSpecification
        Adds an Type to this ResultSpecification for the specified languages. If the given Type is already contained in the result spec, the languages specified will be added to those already associated with the Type in this ResultSpec. The given type's allAnnotatorFeatures is logically "or"ed with any existing value. If null is passed in for the aLanguageIDs, this is treated as if one language, x-unspecified, was given.
        Specified by:
        addResultType in interface ResultSpecification
        Parameters:
        aTypeName - the name of the Type to add for the specified languages
        aAllAnnotatorFeatures - whether all features of this type should also be produced
        aLanguageIDs - an array of ISO language identifiers.
        See Also:
        ResultSpecification.addResultType(java.lang.String, boolean, java.lang.String[])
      • addResultFeature

        public void addResultFeature​(java.lang.String aFullFeatureName)
        Description copied from interface: ResultSpecification
        Adds a Feature to this ResultSpecification for the language x-unspecified. If the given Type is already contained in the result spec, the languages associated with that type will be replaced by x-unspecified.
        Specified by:
        addResultFeature in interface ResultSpecification
        Parameters:
        aFullFeatureName - the fully-qualified name of the Feature to add for the language x-unspecified
        See Also:
        ResultSpecification.addResultFeature(java.lang.String)
      • addResultFeature

        public void addResultFeature​(java.lang.String aFullFeatureName,
                                     java.lang.String[] aLanguageIDs)
        Description copied from interface: ResultSpecification
        Adds a Feature to this ResultSpecification for the specified languages. If the current Feature is already contained in the result spec, the language specification for this Feature will be augmented (added to) with the specified languages. If null is passed in for the aLanguageIDs, this is treated as if one language, x-unspecified, was given.
        Specified by:
        addResultFeature in interface ResultSpecification
        Parameters:
        aFullFeatureName - the fully-qualified name of the Feature to add for the specified languages
        aLanguageIDs - an array of ISO language identifiers.
        See Also:
        ResultSpecification.addResultFeature(java.lang.String, java.lang.String[])
      • createTypeOrFeature

        private TypeOrFeature createTypeOrFeature​(java.lang.String name,
                                                  boolean isType,
                                                  boolean aAllAnnotatorFeatures)
      • createTypeOrFeature

        private TypeOrFeature createTypeOrFeature​(java.lang.String typeName,
                                                  java.lang.String featureName)
      • containsType

        public boolean containsType​(java.lang.String aTypeName)
        Description copied from interface: ResultSpecification
        Determines whether this ResultSpecification contains the specified Type for the language x-unspecified. If a type system is available to the result specification, a type will be considered to be contained in the result spec, also, if it is a subtype of the types originally specified to be in the result specification.
        Specified by:
        containsType in interface ResultSpecification
        Parameters:
        aTypeName - the name of the type
        Returns:
        true if and only if this ResultSpecification contains the type with name aTypeName.
        See Also:
        ResultSpecification.containsType(java.lang.String)
      • containsFeature

        public boolean containsFeature​(java.lang.String aFullFeatureName)
        Description copied from interface: ResultSpecification
        Determines whether this ResultSpecification contains the specified Feature for the language x-unspecified. Feature names are fully qualified, consisting of the type name plus the feature-of-that-type name. A feature ttt:fff is contained in the result spec if that fff is specified for type ttt or any supertype of ttt in the result spec. A feature can be specified in the result spec explicitly or by specifying a type or supertype of the feature's type having the allAnnotatorFeatures flag set.
        Specified by:
        containsFeature in interface ResultSpecification
        Parameters:
        aFullFeatureName - the fully-qualified name of the feature, in the form MyTypeName:MyFeatureName.
        Returns:
        true if and only if this ResultSpecification contains the feature with name aFullFeatureName.
        See Also:
        ResultSpecification.containsFeature(java.lang.String)
      • containsFeature

        public boolean containsFeature​(java.lang.String aFullFeatureName,
                                       java.lang.String aLanguage)
        Description copied from interface: ResultSpecification
        Determines whether this ResultSpecification contains the specified Feature for the specified language. Feature names are fully qualified, consisting of the type name plus the feature-of-that-type name. A feature ttt:fff is contained in the result spec if that fff is specified for type ttt or any supertype of ttt in the result spec. A feature can be specified in the result spec explicitly or by specifying a type or supertype of the feature's type having the allAnnotatorFeatures flag set.
        Specified by:
        containsFeature in interface ResultSpecification
        Parameters:
        aFullFeatureName - the fully-qualified name of the feature, in the form MyTypeName:MyFeatureName.
        aLanguage - the language to search for. A null value or the value x-unspecified for this argument only matches ResultSpecifications having x-unspecified as their type. A language value that is contained within a language in the ResultSpecification is considered to match. In particular: Language ResultSpecification Result x-unspecified x-unspecified match x-unspecified en no match en x-unspecified match en en-us no match en-us en match
        Returns:
        true if and only if this ResultSpecification contains the feature with name aFullFeatureName for a matching language.
        See Also:
        ResultSpecification.containsFeature(java.lang.String,java.lang.String)
      • hasLanguage

        private static boolean hasLanguage​(RsLangs rsLangs,
                                           java.lang.String language)
        Parameters:
        rsLangs -
        language -
        Returns:
        true if the rsLangs subsumes the language
      • addCapabilities

        public void addCapabilities​(Capability[] capabilities)
        Description copied from interface: ResultSpecification
        Adds the output types and features from the specified capabilities to this ResultSpecification.

        If a Type being added is already contained in the ResultSpecification, the languages from the Capabilities entry for this type will be added to those already associated with the Type in this ResultSpec. The given capability instance's allAnnotatorFeatures is logically "or"ed with any existing value.

        Specified by:
        addCapabilities in interface ResultSpecification
        Parameters:
        capabilities - capabilities to add
        See Also:
        ResultSpecification.addCapabilities(org.apache.uima.resource.metadata.Capability[])
      • addCapabilities

        public void addCapabilities​(Capability[] capabilities,
                                    boolean outputs)
        Description copied from interface: ResultSpecification
        Adds either outputs or inputs from the specified capabilities to this ResultSpecification.

        If a Type being added is already contained in the ResultSpecification, the languages from the Capabilities entry for this type will be added to those already associated with the Type in this ResultSpec. The given capability instance's allAnnotatorFeatures is logically "or"ed with any existing value.

        Specified by:
        addCapabilities in interface ResultSpecification
        Parameters:
        capabilities - capabilities to add
        outputs - true to add the output types/features to this ResultSpecification, false to add the input types/features to this ResultSpecification.
        See Also:
        ResultSpecification.addCapabilities(org.apache.uima.resource.metadata.Capability[], boolean)
      • setTypeSystem

        public void setTypeSystem​(TypeSystem ts)
        Description copied from interface: ResultSpecification
        set the type system associated with this result specification. It is used to augment any types with their subtypes
        Specified by:
        setTypeSystem in interface ResultSpecification
        Parameters:
        ts - the CAS Type System
      • toString

        public java.lang.String toString()
        Description copied from class: MetaDataObject_impl
        Dump this metadata object's attributes and values to a String. This is useful for debugging.
        Overrides:
        toString in class MetaDataObject_impl
      • compileIfNeeded

        private void compileIfNeeded()
      • setCompileNeeded

        private void setCompileNeeded()
      • compile

        private void compile()
        create a fully expanded version of this result spec
      • addCompiledFormForTypeAndItsSubtypes

        private void addCompiledFormForTypeAndItsSubtypes​(RsType rst,
                                                          RsLangs langs)
      • addCompiledFormForFeatureAndItsSubtypes

        private void addCompiledFormForFeatureAndItsSubtypes​(RsType rst,
                                                             java.lang.String shortFeatName,
                                                             RsLangs langs)
        Note: the string typeXXX:featYYY may not be in the type system. For instance, if featYYY is introduced in type Foo, we could have a spec of FooSubtype:featYYY; this string could be unique to the result spec
        Parameters:
        rst -
        shortFeatName -
        langs -
      • addCompiledFormEntry

        private void addCompiledFormEntry​(java.lang.String tofName,
                                          RsLangs languagesToAdd)
        Adds languages to a type or feature
        Parameters:
        tofName -
        languagesToAdd -
      • subtypeNames

        private java.lang.Iterable<java.lang.String> subtypeNames​(java.lang.String typeName)
      • intersect

        ResultSpecification_impl intersect​(ResultSpecification_impl rsOther)
        Compute the feature/type + language intersection of two result specs Result-spec 2 is the more-or-less constant spec from the primitive's capability outputs it can change if the type system changes... causing new 'inheritance" Language intersection is done on a per-type-or-feature basis: Each is a set of languages, interpreted as a "Union". If the set contains x-unspecified - it is taken to mean all languages if the set contains XX - it is taken to mean the union of all sublanguages XX-yy
      • equals

        public boolean equals​(java.lang.Object aObj)
        Description copied from class: MetaDataObject_impl
        Determines if this object is equal to another. Two MetaDataObjects are equivalent if they share the same attributes and the same values for those attributes.
        Specified by:
        equals in interface MetaDataObject
        Overrides:
        equals in class MetaDataObject_impl
        Parameters:
        aObj - object with which to compare this object
        Returns:
        true if and only if this object is equal to aObj
      • equalsOrBothNull

        static boolean equalsOrBothNull​(java.lang.Object x,
                                        java.lang.Object y)
      • hashCode

        public int hashCode()
        Description copied from class: MetaDataObject_impl
        Gets the hash code for this object. The hash codes of two NameClassPairs x and y must be equal if x.equals(y) returns true;
        Overrides:
        hashCode in class MetaDataObject_impl
        Returns:
        the hash code for this object