Dynamically import the python module with the ngram defined as a dictionary.
    Since bigger ngrams are large files its wasteful to always statically import them if they're not used.
976616
def _load_ngram(name):
    
    module = importlib.import_module('lantern.analysis.english_ngrams.{}'.format(name))
    return getattr(module, name)
946800
def reload_module(module):
    
    try:
        # For Python 2.x
        reload(module)
    except (ImportError, NameError):
        # For <= Python3.3:
        import imp
        imp.reload(module)
    except (ImportError, NameError):
        # For >= Python3.4
        import importlib
        importlib.reload(module)
1132792
def import_module(module):  # pylint: disable=R0201
        
        if isinstance(module, list):
            all_modules = module
        else:
            all_modules = [module]
        for mod in all_modules:
            globals()[mod] = __import__(mod.strip())
218839
def import_submodules(context, root_module, path):
    
    for _, module_name, _ in pkgutil.walk_packages(path, root_module + '.'):
        # this causes a Runtime error with model conflicts
        # module = loader.find_module(module_name).load_module(module_name)
        module = __import__(module_name, globals(), locals(), ['__name__'])
        for k, v in vars(module).items():
            if not k.startswith('_'):
                context[k] = v
        context[module_name] = module
676159
def import_modules(names, src, dst):
    """"""
    for name in names:
        module = importlib.import_module(src + '.' + name)
        setattr(sys.modules[dst], name, module)
897059
def import_(module_name, name):
    
    module = importlib.import_module(module_name, __package__)
    return getattr(module, name)
490345
def import_numpy():
    
    try:
        imp.find_module('numpy')
        numpy_exists = True
    except ImportError:
        numpy_exists = False

    if numpy_exists:
        # We do this outside of try/except block in case numpy exists
        # but is not installed correctly. We do not want to catch an
        # incorrect installation which would manifest as an
        # ImportError.
        import numpy as np
    else:
        np = None

    return np
217586
def import_submodules(module):
    """"""
    submodules = {}
    for loader, name, ispkg in pkgutil.iter_modules(module.__path__,
                                                    module.__name__ + '.'):
        try:
            submodule = import_module(name)
        except ImportError as e:
            # FIXME: Make the errors non-fatal (do we want that?).
            logging.warning("Error importing %s", name)
            logging.exception(e)
        else:
            parent, child = name.rsplit('.', 1)
            submodules[child] = submodule
    return submodules
296394
def import_object(module_name, attribute_name):
    
    # Py2 compatibility: force str (i.e bytes) when importing.
    module = __import__(str(module_name), {}, {}, [str(attribute_name)], 0)
    return getattr(module, str(attribute_name))
1343203
def register_module(module=None):
    

    global REGISTERED_MODULES

    if module is None:
        # Note: inspect.getmodule() can return the wrong module if it has been imported with different relatives paths.
        module = sys.modules.get(inspect.currentframe().f_back.f_globals["__name__"])

    REGISTERED_MODULES.add(module)
    return True
1259557
def load_module(self, name):
        """"""
        if name in sys.modules:
            return sys.modules[name]
        # load the actual import hook module
        module_name = self.mount2name(name)
        __import__(module_name)
        # alias the import hook module to the mount, so both can be used interchangeably
        module = sys.modules[name] = sys.modules[module_name]
        module.install()
        return module
496144
def import_file(filename):
    
    pathname, filename = os.path.split(filename)
    modname = re.match(
        r'(?P<modname>\w+)\.py', filename).group('modname')
    file, path, desc = imp.find_module(modname, [pathname])

    try:
        imp.load_module(modname, file, path, desc)
    finally:
        file.close()
166730
def load_module(name):
    

    spec = importlib.util.find_spec(name)
    mod = importlib.util.module_from_spec(spec)
    mod.__spec__ = spec
    mod.__loader__ = spec.loader
    spec.loader.exec_module(mod)
    return mod
123164
def _import_modules(dir_path):
    

    def _import_module(module):
        """ Imports the specified module.
            """
        # already loaded, skip
        if module in mods_loaded:
            return False

        __import__(module)
        mods_loaded.append(module)

    mods_loaded = []

    # check if provided path exists
    if not os.path.isdir(dir_path):
        return

    try:
        # update import search path
        sys.path.insert(0, dir_path)

        # check for modules in the dir path
        for entry in os.listdir(dir_path):
            path = os.path.join(dir_path, entry)

            if os.path.isdir(path):  # directory
                _import_module(entry)

            elif _RE_PY_EXT.search(entry):  # python file
                if not _RE_INIT_PY.match(entry):  # exclude init
                    name = _RE_PY_EXT.sub('', entry)
                    _import_module(name)
    finally:
        # remove inserted path
        sys.path.pop(0)
1230327
def import_module(path):
    
    mod = __import__(path, locals={}, globals={})
    for item in path.split('.')[1:]:
        try:
            mod = getattr(mod, item)
        except AttributeError:
            raise ImportError('No module named %s' % path)
    return mod
1235920
def do_import_module(self, modname=None):
        
        # handle special case where we are on a package node importing a module
        # using the same name as the package, which may end in an infinite loop
        # on relative imports
        # XXX: no more needed ?
        mymodule = self.root()
        level = getattr(self, "level", None)  # Import as no level
        if modname is None:
            modname = self.modname
        # XXX we should investigate deeper if we really want to check
        # importing itself: modname and mymodule.name be relative or absolute
        if mymodule.relative_to_absolute_name(modname, level) == mymodule.name:
            # FIXME: we used to raise InferenceError here, but why ?
            return mymodule

        return mymodule.import_module(
            modname, level=level, relative_only=level and level >= 1
        )
1183074
def import_module(name: str) -> ModuleType:
    
    logger.debug("Importing module: %s", name)
    if name == main_module_name():
        return main_module

    return importlib.import_module(name)