Package com.gengoai.hermes
Enum ResourceType
- java.lang.Object
-
- java.lang.Enum<ResourceType>
-
- com.gengoai.hermes.ResourceType
-
- All Implemented Interfaces:
Serializable
,Comparable<ResourceType>
public enum ResourceType extends Enum<ResourceType>
Defines common resource used by Hermes and methods for finding configuration values and resources for them.
-
-
Enum Constant Summary
Enum Constants Enum Constant Description CADUCEUS
Caduceus programsLEXICON
Lexicon Resources (supports in-memory via json files and on-disk)MODEL
Machine Learning Model resourcesMORPHOLOGY_RULES
WORD_LIST
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <M> Cache<Language,M>
createCache(int size, @NonNull String configKey, @NonNull String resourceName)
Creates a Language-keyed cache for this resource type that loads the resource based on the given configKey and resourceName<M> Cache<Language,M>
createCache(@NonNull String configKey, @NonNull String resourceName)
Creates a Language-keyed cache for this resource type that loads the resource based on the given configKey and resourceNameOptional<String>
getConfigValue(@NonNull String resourceName, @NonNull Language language)
Gets the config value, if any, for the this resource type with the given name and language.<T> T
load(@NonNull String resourceName, @NonNull Language language)
Loads a resource of this type by finding the resource with the given resource name and language.abstract <T> T
load(@NonNull String configKey, @NonNull String resourceName, @NonNull Language language)
Loads a resource of this type by finding the resource with the given configuration key, resource name, and language.Optional<Resource>
locate(@NonNull String resourceName, @NonNull Language language)
Common method for finding a resource of a given type.Optional<Resource>
locate(@NonNull String configKey, @NonNull String resourceName, @NonNull Language language)
Common method for finding a resource of a given typestatic ResourceType
valueOf(String name)
Returns the enum constant of this type with the specified name.static ResourceType[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
LEXICON
public static final ResourceType LEXICON
Lexicon Resources (supports in-memory via json files and on-disk)
-
WORD_LIST
public static final ResourceType WORD_LIST
-
MODEL
public static final ResourceType MODEL
Machine Learning Model resources
-
CADUCEUS
public static final ResourceType CADUCEUS
Caduceus programs
-
MORPHOLOGY_RULES
public static final ResourceType MORPHOLOGY_RULES
-
-
Method Detail
-
values
public static ResourceType[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (ResourceType c : ResourceType.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static ResourceType valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
createCache
public <M> Cache<Language,M> createCache(int size, @NonNull @NonNull String configKey, @NonNull @NonNull String resourceName)
Creates a Language-keyed cache for this resource type that loads the resource based on the given configKey and resourceName- Type Parameters:
M
- the resource type parameter- Parameters:
size
- the maximum size of the cacheconfigKey
- the configuration key to use when looking for the location in ConfigresourceName
- the resource name- Returns:
- the cache
-
createCache
public <M> Cache<Language,M> createCache(@NonNull @NonNull String configKey, @NonNull @NonNull String resourceName)
Creates a Language-keyed cache for this resource type that loads the resource based on the given configKey and resourceName- Type Parameters:
M
- the resource type parameter- Parameters:
configKey
- the configuration key to use when looking for the location in ConfigresourceName
- the resource name- Returns:
- the cache
-
getConfigValue
public Optional<String> getConfigValue(@NonNull @NonNull String resourceName, @NonNull @NonNull Language language)
Gets the config value, if any, for the this resource type with the given name and language.
The method will look for the following configuration keys:
- [resourceName].[language].[type]
- [resourceName].[language]
- [resourceName].[type]
- [resourceName]
- Parameters:
resourceName
- the resource namelanguage
- the language- Returns:
- the config value
-
load
public <T> T load(@NonNull @NonNull String resourceName, @NonNull @NonNull Language language)
Loads a resource of this type by finding the resource with the given resource name and language. Will throw a runtime exception if the resources is not located or there is a problem loading it.- Type Parameters:
T
- the type of resource returned- Parameters:
resourceName
- the resource namelanguage
- the language version of the resource to load- Returns:
- the loaded resource
-
load
public abstract <T> T load(@NonNull @NonNull String configKey, @NonNull @NonNull String resourceName, @NonNull @NonNull Language language)
Loads a resource of this type by finding the resource with the given configuration key, resource name, and language. Will throw a runtime exception if the resources is not located or there is a problem loading it.- Type Parameters:
T
- the type of resource returned- Parameters:
configKey
- the configuration key to use when looking for the location in ConfigresourceName
- the resource namelanguage
- the language version of the resource to load- Returns:
- the loaded resource
-
locate
public Optional<Resource> locate(@NonNull @NonNull String resourceName, @NonNull @NonNull Language language)
Common method for finding a resource of a given type. {@see ResourceType.findResource(String, String, Language)}** for details. This method uses the name also as the config property
- Parameters:
resourceName
- the resource namelanguage
- the language of the model- Returns:
- the resource location or null
-
locate
public Optional<Resource> locate(@NonNull @NonNull String configKey, @NonNull @NonNull String resourceName, @NonNull @NonNull Language language)
Common method for finding a resource of a given type
The method will look in the following locations:
- [configKey].[language].[type]
- [hermes.resources.dir]/[language]/[type]/[resourceName]
- classpath:com/gengoai/hermes/[language]/[type]/[resourceName]
- configKey.[language]
- configKey
- configKey.[type]
- [hermes.resources.dir]/default/[type]/[resourceName]
- classpath:com/gengoai/hermes/default/[type]/[resourceName]
language
is the two-letter (lowercased) language code.- Parameters:
configKey
- the config key to use for locating the modelresourceName
- the resource resourceNamelanguage
- the language of the model- Returns:
- the resource location or null
-
-