Exemplo n.º 1
0
def test_download_models():
    """Test downloading of models from S3"""
    # Remove test models folder if it exists
    test_model_folder = os.path.join(ADEFT_MODELS_PATH, '__TEST')
    if os.path.isdir(test_model_folder):
        shutil.rmtree(test_model_folder)
    assert '__TEST' not in get_available_models()

    # Download models
    download_models(models=['__TEST'])
    assert '__TEST' in get_available_models()
Exemplo n.º 2
0
def load_disambiguator(shortform, path=ADEFT_MODELS_PATH):
    """Returns adeft disambiguator loaded from models directory

    Searches folder specified by path for a disambiguation model
    that can disambiguate the given shortform and returns this
    model

    Parameters
    ----------
    shortform : str
        Shortform to disambiguate.
    path : Optional[str]
        Path to models directory. Defaults to adeft's pretrained models.
        Users have the option to specify a path to another directory to use
        custom models.

    Returns
    -------
    py:class:`adeft.disambiguate.AdeftDisambiguator`
        A disambiguator that was loaded from a file. Returns None if there
        are no disambiguation models in the supplied folder that can
        disambiguate the given shortform
    """
    available = get_available_models(path=path)
    try:
        model_name = available[shortform]
    except KeyError:
        logger.error('No model available for shortform %s' % shortform)
        return None

    output = load_disambiguator_directly(os.path.join(path, model_name))
    return output
Exemplo n.º 3
0
__version__ = '0.5.5'

from adeft.download import get_available_models

available_shortforms = {
    shortform: model
    for shortform, model in get_available_models().items()
    if shortform != '__TEST'
}