def load_component(self, component_name, model_dir, model_metadata, **context):
# type: (Text, Text, Metadata, **Any) -> Component
"""Tries to retrieve a component from the cache, calls `load` to create a new component."""
from rasa_nlu import registry
from rasa_nlu.model import Metadata
try:
cached_component, cache_key = self.__get_cached_component(component_name, model_metadata)
component = registry.load_component_by_name(component_name, model_dir,
model_metadata, cached_component, **context)
if not cached_component:
# If the component wasn't in the cache, let us add it if possible
self.__add_to_cache(component, cache_key)
return component
except MissingArgumentError as e: # pragma: no cover
raise Exception("Failed to load component '{}'. {}".format(component_name, e))
评论列表
文章目录