Skip to content

Commit

Permalink
python/bllipparser/RerankingParser.py: add fetch_and_load()
Browse files Browse the repository at this point in the history
This makes downloading, installing, and loading models a nice 2-liner.
  • Loading branch information
dmcc committed Aug 16, 2015
1 parent be59f53 commit be05870
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions python/bllipparser/RerankingParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,27 @@ def from_unified_model_dir(this_class, model_dir, parsing_options=None,
rrp.unified_model_dir = model_dir
return rrp

@classmethod
def fetch_and_load(this_class, model_name, models_directory=None,
verbose=False, extra_loading_options=None):
"""Downloads, installs, and creates a RerankingParser object for
a specified model using ModelFetcher.download_and_install_model.
model_name must be one of the defined models in ModelFetcher
and models_directory is a directory where the model will
be installed. By default, models will be installed to
"~/.local/share/bllipparser". Setting verbose=True will
cause ModelFetcher to be print additional details. Finally,
extra_loading_options is a dictionary of keyword arguments
passed to RerankingParser.from_unified_model_dir to customize
the parsing models."""
from .ModelFetcher import download_and_install_model
model_dir = download_and_install_model(model_name,
models_directory,
verbose)

kwargs = extra_loading_options or {}
return this_class.from_unified_model_dir(model_dir, **kwargs)

def tokenize(text):
"""Helper method to tokenize a string. Note that most methods accept
untokenized text so you shouldn't need to run this if you intend
Expand Down

0 comments on commit be05870

Please sign in to comment.